Operations Reference#
This page documents all operations supported by NKIPy, organized by category.
Overview#
NKIPy operations are traced and lowered to HLO for compilation by the Neuron Compiler.
Categories#
Unary Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
Linear Algebra Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
|
Binary Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
Collective Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu, hlo |
— |
|
cpu, hlo |
— |
|
cpu, hlo |
— |
|
cpu, hlo |
— |
Convolution Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu, hlo |
— |
|
cpu, hlo |
— |
Neural Network Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
— |
|
— |
— |
|
cpu, hlo |
— |
Creation Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu, hlo |
|
|
cpu, hlo |
— |
|
cpu, hlo |
|
|
cpu, hlo |
— |
|
cpu, hlo |
— |
|
cpu, hlo |
|
Reduction Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
Transform Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
— |
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
— |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
|
hlo |
|
Indexing Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
hlo |
— |
|
hlo |
|
|
hlo |
— |
|
hlo |
— |
|
hlo |
|
|
hlo |
|
|
hlo |
|
API Reference#
NKIPy Operations Module
This module provides a unified interface for tensor operations that dispatch to the appropriate backend (IR or HLO) based on the current tracing context.
- class nkipy.core.ops.Op(name: str)[source]#
Bases:
objectSimple operation dispatcher.
Usage:
zeros = Op('zeros') @zeros.impl('hlo') def _zeros_hlo(shape, dtype): # HLO implementation ... @zeros.impl('cpu') def _zeros_cpu(shape, dtype): # CPU implementation ... # Later, during tracing: result = zeros(shape, dtype) # Dispatches based on current backend
- nkipy.core.ops.set_backend(backend: str | None, context: TraceContext | None = None) None[source]#
Set the current backend and optional trace context.
Called by tracing infrastructure when a kernel is being traced.
- Parameters:
backend – Backend name (‘hlo’, ‘cpu’, or future backends), or None to clear.
context – Trace context for tracing backends (required for ‘hlo’).
- nkipy.core.ops.get_backend() str[source]#
Get the current backend name.
- Returns:
Current backend name.
- Raises:
RuntimeError – If no backend is set.
- nkipy.core.ops.set_context(context: TraceContext | None) None[source]#
Set the current trace context.
This is typically called together with set_backend, but can be used separately if needed.
- Parameters:
context – Trace context or None to clear.
- nkipy.core.ops.get_context() TraceContext | None[source]#
Get the current trace context.
- Returns:
Current trace context, or None for eager backends (like ‘cpu’).
- nkipy.core.ops.set_source_location(location: Tuple[str, int] | None) None[source]#
Set the current source location in the trace context.
This is a convenience function that sets the source location in the current context if available.
- Parameters:
location – Tuple of (filename, line_number) or None to clear.
- nkipy.core.ops.get_source_location() Tuple[str, int] | None[source]#
Get the current source location from the trace context.
This is a convenience function that retrieves the source location from the current context if available.
- Returns:
Tuple of (filename, line_number) or None if no context or location set.