Skip to content
heliaAOT
HELIA HUB

AotOperator

Machine-readable model

  • AotOperatorclassBase class for the AOT lowering of a single AIR operator.
class

Base class for the AOT lowering of a single AIR operator.

helia_aot/aot/operators/operator.py:119

AotOperator(
op: AirOperator,
model: AirModel,
platform: SocPlatform,
prefix: str = 'aot',
attributes: dict[str, Any] | None = None,
)

Base class for the AOT lowering of a single AIR operator.

One instance wraps one AirOperator and drives it through the per-operator half of the conversion: resolve() validates the operator against the target platform and materializes any scratch or constant tensors, plan() reports what the memory planner must reserve, and emit() renders the operator’s C source. Subclasses implement those steps for one TYPE and are registered into RegistryContext.aot_operator_classes (see register_default_aot_operators for the built-ins).

The upper-case class attributes below are the declarative contract the rest of the pipeline reads. AotMeta rejects reassignment of an upper-case name that a class declares in its own body, so a subclass that inherits SUPPORTED_DTYPES without redeclaring it can still have it assigned at runtime.

Parameters of AotOperator
NameTypeDefaultDescription
opAirOperatorRequiredThe AIR operator to wrap.
modelAirModelRequiredThe AIR model.
platformSocPlatformRequiredThe target platform for code generation.
prefixstr'aot'Prefix for generated code files. Defaults to "aot".
attributesdict[str, Any] | NoneNoneAttributes for template values.
attribute

Whether this operator's run code is placed in ITCM.

helia_aot/aot/operators/operator.py:355

code_in_itcm: bool

Whether this operator’s run code is placed in ITCM.

True only when code_placement is ITCM and the target has ITCM; the operator handler warns about requests that cannot be honored.

attribute

has_init

Python

Whether this operator emits a per-instance init function.

helia_aot/aot/operators/operator.py:946

has_init: bool

Whether this operator emits a per-instance _init function.

Operators whose initialization is a no-op may opt out by returning False. When an operator opts out, it must not emit an _init function/declaration in its templates, and the dispatch table records a NULL init slot (the model init loop skips the call while preserving the init callback contract). Defaults to True so existing operators keep emitting their own init unchanged.

attribute

Return the operator's effective optimization capabilities.

helia_aot/aot/operators/operator.py:963

capabilities: OpCapability

Return the operator’s effective optimization capabilities.

The effective set is the declared :attr:CAPABILITIES widened by the capabilities implied by the operator’s runtime behavior, so the legacy seams remain the source of truth during migration and no operator has to declare a capability twice:

  • not self.has_init implies :attr:OpCapability.STATELESS.
  • A non-empty :meth:shared_kernel_helpers or :meth:shared_activation_helpers implies :attr:OpCapability.DESCRIPTOR_DRIVEN and :attr:OpCapability.SHARED_KERNEL.

Because some seams are dtype-dependent (e.g. fully-connected only routes through a shared kernel for int8 per-channel quantization), this is an instance property rather than a class constant: it reflects the concrete resolved operator. It performs no model mutation and does not change emitted code.

attribute

Return the direct shared-kernel call target for static scheduling.

helia_aot/aot/operators/operator.py:995

direct_dispatch: tuple[str, str] | None

Return the direct shared-kernel call target for static scheduling.

Under static scheduling the model schedule can call a descriptor driven operator’s shared kernel helper directly, eliding the thin per-node _run thunk (the main .text reclaim described in RFC 0003 Stage 4). This is only valid for operators whose _run body is exactly return helper(ctx, &desc); – i.e. operators that route through a single shared kernel helper with the uniform helper(ctx, const desc_t *) signature (ADD/MUL/per-channel int8 FULLY_CONNECTED). Shared activation helpers marshal flattened arguments and keep mutable file-scope state, so they are intentionally excluded and keep their _run thunk.

method

set_knobs

Python

Set the resolved optimization knob values before resolve().

helia_aot/aot/operators/operator.py:302

set_knobs(values: dict[str, str]) -> None

Set the resolved optimization knob values before resolve().

Parameters of set_knobs
NameTypeDefaultDescription
valuesdict[str, str]RequiredKnob name to resolved value, for every knob.
Errors raised by set_knobs
TypeDescription
ValueErrorWhen a knob is missing or unknown, or a value is ``auto`` or not one of the knob's values.
method

Whether a knob's alternatives would change this operator's code.

helia_aot/aot/operators/operator.py:319

knob_applicability(name: str) -> tuple[bool, str | None] | None

Whether a knob’s alternatives would change this operator’s code.

Operators that implement a knob override this; the base operator has no knobs.

Parameters of knob_applicability
NameTypeDefaultDescription
namestrRequiredThe knob's name.
Returns of knob_applicability
TypeDescription
tuple[bool, str | None] | Nonetuple[bool, str | None] | None: ``(applicable, reason when not)``,
tuple[bool, str | None] | Noneor None when the knob does not exist for this operator.
method

Choices that change numerics or speed but are not knobs yet.

helia_aot/aot/operators/operator.py:334

fixed_choices() -> dict[str, tuple[str, FixedSetBy]]

Choices that change numerics or speed but are not knobs yet.

Returns of fixed_choices
TypeDescription
dict[str, tuple[str, FixedSetBy]]dict[str, tuple[str, FixedSetBy]]: Choice name to ``(value, set_by)``,
dict[str, tuple[str, FixedSetBy]]where ``set_by`` is ``attribute``, ``default``, ``heuristic`` or
dict[str, tuple[str, FixedSetBy]]``knob``.
method

Return self.op.options checked against the operator's options class.

helia_aot/aot/operators/operator.py:368

typed_options(options_type: type[_OptionsT]) -> _OptionsT

Return self.op.options checked against the operator’s options class.

AirOperator.options is typed as the AirOperatorOptions marker base; each AOT operator knows its concrete class and reads through this so field access is type-checked and a mismatch (a mis-registered parser, a hand-built graph) fails with a clear error.

Parameters of typed_options
NameTypeDefaultDescription
options_typetype[_OptionsT]RequiredThe ``AirXxxOptions`` class this operator expects.
Returns of typed_options
TypeDescription
_OptionsTThe options object, typed as ``options_type``.
Errors raised by typed_options
TypeDescription
TypeErrorIf the operator carries options of a different class.
method

Numpy float scalar types present on this operator's IO tensors.

helia_aot/aot/operators/operator.py:408

float_io_dtypes() -> set[type]

Numpy float scalar types present on this operator’s IO tensors.

Returns of float_io_dtypes
TypeDescription
set[type]set[type]: The subset of ``{np.float16, np.float32}`` referenced by
set[type]the operator's input or output tensors.
method

Float dtypes for which this operator needs the ns-cmsis-nn float API.

helia_aot/aot/operators/operator.py:422

cmsis_float_dependencies() -> set[type]

Float dtypes for which this operator needs the ns-cmsis-nn float API.

A returned dtype means the emitted C references the float-only arm_nnfunctions_flt.h API (a gated arm_*_f32 / arm_*_f16 kernel or the float16_t / float32_t types it introduces) for that precision, so the ns-cmsis-nn build must enable ARM_NN_ENABLE_F32 / ARM_NN_ENABLE_F16.

The base implementation derives the set from :attr:USES_CMSIS_FLOAT_KERNEL: operators that dispatch to a gated float kernel advertise every float dtype on their IO; everything else (integer kernels, byte movers, portable conversions) advertises none. Operators with a per-instance dependency override this method.

Returns of cmsis_float_dependencies
TypeDescription
set[type]set[type]: Subset of ``{np.float16, np.float32}`` requiring the
set[type]ns-cmsis-nn float API.
method

Minimum ns-cmsis-nn version this operator instance requires.

helia_aot/aot/operators/operator.py:445

cmsis_nn_version_requirement() -> tuple[int, int, int] | None

Minimum ns-cmsis-nn version this operator instance requires.

The base implementation applies :attr:MIN_CMSIS_NN_VERSION_FLOAT only when the operator actually takes its float path, reusing the same :meth:cmsis_float_dependencies contract that drives the float header include and the ARM_NN_ENABLE_F32 / ARM_NN_ENABLE_F16 build defines. An int8 ABS therefore imposes no floor of its own while an fp32 ABS does; a declaration only raises a module’s requirement when it is above the repository-wide CMSIS_NN_VERSION.

Operators with an unconditional floor, or one that varies by something other than float dispatch, override this.

Returns of cmsis_nn_version_requirement
TypeDescription
tuple[int, int, int] | Nonetuple[int, int, int] | None: ``(major, minor, patch)``, or
tuple[int, int, int] | None``None`` when the module-wide floor already suffices.
method

The ns-cmsis-nn function this operator calls, when it selects one kernel.

helia_aot/aot/operators/operator.py:473

kernel_entry() -> str | None

The ns-cmsis-nn function this operator calls, when it selects one kernel.

Returns of kernel_entry
TypeDescription
str | Nonestr | None: The C function name, or None for an operator without a
str | Nonesingle selected kernel.
method

Return a tensor's quantization zero point, defaulting to 0.

helia_aot/aot/operators/operator.py:580

tensor_zero_point(tensor: AirTensor, index: int = 0) -> int

staticmethod

Return a tensor’s quantization zero point, defaulting to 0.

Parameters of tensor_zero_point
NameTypeDefaultDescription
tensorAirTensorRequiredThe tensor to inspect.
indexint0The zero-point index to read (per-tensor quant uses 0).
Returns of tensor_zero_point
TypeDescription
intThe integer zero point, or 0 when the tensor is unquantized.
method

Promote an operator-local constant array into a model tensor.

helia_aot/aot/operators/operator.py:596

intern_constant_array(
name: str,
data: np.ndarray,
*,
role: AirTensorKind = AirTensorKind.CONSTANT,
alignment: int | None = None,
) -> TensorId

Promote an operator-local constant array into a model tensor.

This routes operator metadata (e.g. per-channel quantization tables) through the same machinery as ordinary constants: memory planning, duplicate-constant interning (storage dedup), cold/staged residency, and uniform tensor-pointer resolution. The tensor is registered under op.named_tensors[name] so templates can reference it via ctx->tensor_ptrs[...] like any other tensor.

The operation is idempotent: a previously interned tensor with the same deterministic id is replaced.

Parameters of intern_constant_array
NameTypeDefaultDescription
namestrRequiredLocal tensor name; also used to build the deterministic id.
datanp.ndarrayRequiredArray payload, stored as a contiguous copy.
roleAirTensorKindAirTensorKind.CONSTANTTensor kind/bucket. Defaults to ``CONSTANT``.
alignmentint | NoneNoneOptional alignment hint in bytes.
Returns of intern_constant_array
ValueTypeDescription
TensorIdTensorIdThe id of the registered tensor.
method

resolve

Python

Public entry point—only runs once, even if called repeatedly.

helia_aot/aot/operators/operator.py:776

resolve()

Public entry point—only runs once, even if called repeatedly.

This method validates the AIR operator and performs any model mutations needed.

Errors raised by resolve
TypeDescription
ValueErrorIf the operator declares that a kernel reads through a ``cmsis_nn_context`` buffer but allocated no backing for it (see :meth:`_assert_ctx_buf_backed`).
method

Whether this concrete operator's lowering dereferences ctx->buf.

helia_aot/aot/operators/operator.py:794

ctx_buf_required() -> bool

Whether this concrete operator’s lowering dereferences ctx->buf.

Only meaningful for operators declaring :attr:CtxBufUsage.CONDITIONAL, which MUST override this. Evaluate it against the same inputs the operator’s scratch sizing uses (dtype, options, platform capability) so the two can never disagree: the guard exists precisely to catch the case where sizing says “0 bytes” and the dispatched kernel says “I read that buffer”.

Returns of ctx_buf_required
TypeDescription
bool``True`` if at least one kernel this operator can dispatch reads or
boolwrites through ``ctx->buf``.
Errors raised by ctx_buf_required
TypeDescription
NotImplementedErrorIf called on an operator that did not declare :attr:`CtxBufUsage.CONDITIONAL` and override this method.
method

Return the shared operator-kernel helpers this operator requires.

helia_aot/aot/operators/operator.py:1022

shared_kernel_helpers() -> list[KernelHelper]

Return the shared operator-kernel helpers this operator requires.

This mirrors :meth:shared_activation_helpers but for general operator kernels (e.g. elementwise ADD/MUL or FULLY_CONNECTED). An operator that routes its _run body through a shared runtime helper (instead of an inlined per-node call site) declares the helper descriptors here so the code generator emits each distinct helper exactly once. Helpers are keyed by signature, so distinct operator variants map to distinct helpers and never collide. The base implementation requires no shared kernels.

Returns of shared_kernel_helpers
TypeDescription
list[KernelHelper]A list of :class:`KernelHelper` descriptors (see
list[KernelHelper]mod:`helia_aot.aot.operators.kernel_runtime`). Empty for operators
list[KernelHelper]that do not use a shared kernel helper.
method

Return the shared LUT-activation helpers this operator requires.

helia_aot/aot/operators/operator.py:1042

shared_activation_helpers() -> list[dict[str, object]]

Return the shared LUT-activation helpers this operator requires.

Operators that emit their hot loop via a shared runtime helper (rather than an inlined per-node body) declare the helper descriptors here so the code generator can emit each distinct helper exactly once. The base implementation requires no shared helpers.

Returns of shared_activation_helpers
TypeDescription
list[dict[str, object]]A list of helper descriptor dicts (see
list[dict[str, object]]func:`helia_aot.aot.operators.activation_runtime.activation_lut_helper`).
list[dict[str, object]]Empty for operators that do not use a shared activation helper.
method

Compute the values for the operator source code template.

helia_aot/aot/operators/operator.py:1058

compute_values() -> dict[str, Any]

Compute the values for the operator source code template.

Args:

Returns of compute_values
TypeDescription
dict[str, Any]dict[str, Any]: Dictionary of values for the operator template.
method

emit

Python

Generate the source code for the operator.

helia_aot/aot/operators/operator.py:1108

emit(save_path: Path)

Generate the source code for the operator.

This method should be overridden by subclasses.

Parameters of emit
NameTypeDefaultDescription
save_pathPathRequiredPath to save the generated source code.