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#
Reduction Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
Unary Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
Binary Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
Collective Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu |
— |
|
cpu |
— |
|
cpu |
— |
|
cpu |
— |
Transform Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
— |
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
|
— |
|
Indexing Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
— |
|
— |
— |
|
— |
— |
|
— |
— |
|
— |
— |
|
— |
|
|
— |
|
|
— |
|
Linear Algebra Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
|
|
— |
|
|
— |
— |
|
— |
|
|
— |
|
Neural Network Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
— |
— |
|
— |
— |
|
cpu |
— |
Convolution Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu |
— |
|
cpu |
— |
Creation Operations#
Operation |
Backend(s) |
NumPy Equivalent |
|---|---|---|
|
cpu |
— |
|
— |
|
|
cpu |
|
|
cpu |
— |
|
cpu |
|
|
cpu |
|
|
— |
|
|
— |
|
|
cpu |
— |
|
cpu |
|
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
Composed ops (built from other dispatched ops) use
composed_impl:floor_divide = Op('floor_divide') @floor_divide.composed_impl def _floor_divide(x, y): return floor(divide(x, y))
The composed fallback is used when no backend-specific implementation is registered. Since it calls other ops via dispatch, it works on any backend that has the underlying primitives registered.
- impl(backend: str) Callable[source]#
Decorator to register a backend implementation.
- Parameters:
backend – Backend name (‘hlo’, ‘cpu’, or other supported).
- Returns:
Decorator function.
- property composed_impl#
Decorator to register a composed (backend-agnostic) fallback.
A composed implementation is built entirely from calls to other dispatched ops, so it works on any backend that has those primitives. It is used as a fallback when no backend-specific impl is registered.