kernel_runtime
Shared operator-kernel runtime helpers.
This module is the general-purpose sibling of
:mod:helia_aot.aot.operators.activation_runtime. Where the activation runtime
collapses repeated activation bodies, this one collapses repeated operator
call sites (e.g. elementwise ADD / MUL or FULLY_CONNECTED) into a
single shared runtime function per distinct kernel signature.
An operator opts in by returning descriptors from
:meth:helia_aot.aot.operators.operator.AotOperator.shared_kernel_helpers. The
operator then emits a compact per-node descriptor (rodata) plus a thin
_run wrapper that forwards to the shared helper, instead of an inlined
per-node call with a dozen marshalled arguments. The dominant per-op code (the
CMSIS call site) is compiled exactly once.
Helpers are keyed by signature (key), so distinct operator variants map to
distinct shared helpers and never collide. Adding a future variant (e.g. a
second fully-connected kernel) simply introduces a new key and a new helper;
existing kernels are untouched.
Classes
KernelHelper
dataclass
Descriptor for one distinct shared operator-kernel signature.
A descriptor is the single source of truth tying together the Python
operator, the shared runtime declaration/definition
({prefix}_kernels.h/.c) and the per-node _run wrapper. Because
it is a frozen dataclass rather than a bare dict, field typos surface at
construction time (and via the type checker) instead of as a Jinja render
error or a C compile error in generated code. Instances are hashable, so
distinct signatures de-duplicate cleanly by value.
Attributes:
-
key(str) –Signature identity used to de-duplicate helpers across operators.
-
struct_kind(str) –Selects the descriptor struct layout / dispatch branch in the kernel templates.
-
helper_name(str) –Bare name of the shared runtime function (prefixed at render time).
-
ctype(str) –C element type the kernel operates on (e.g.
int8_t). -
cmsis(str) –CMSIS-NN entry point the shared runtime forwards to.
Functions
elementwise_kernel_helper
Return the shared kernel descriptor for an elementwise family.
Parameters:
-
(familystr) –The elementwise family (
"add"or"mul"). -
(dtypedtype) –The numpy dtype of the operator's output elements.
Returns:
-
A(KernelHelper | None) –class:
KernelHelper, orNoneiffamily/dtypehas no -
KernelHelper | None–shared kernel.
fully_connected_kernel_helper
Return the shared descriptor for the per-channel int8 fully-connected kernel.
Returns:
-
The(KernelHelper) –class:
KernelHelperforarm_fully_connected_per_channel_s8.
collect_kernel_helpers
Collect the distinct shared kernel helpers required by operators.
Parameters:
-
(operatorslist) –The resolved :class:
AotOperatorinstances for the model.
Returns:
-
list[KernelHelper]–class:
KernelHelperdescriptors (one per distinct key) sorted by key, -
list[KernelHelper]–suitable for rendering the shared kernels runtime file. Empty when no
-
list[KernelHelper]–operator uses a shared kernel helper.
Raises:
-
ValueError–If two operators declare the same
keywith differing descriptors (a signature collision that would otherwise resolve silently to whichever operator was visited last).