Abstract base interface every Lucid op kernel implements.
IKernel exposes a minimal polymorphic surface so the
autograd engine, profiler, and testing harnesses can manipulate
kernels without knowing the concrete CRTP type. Concrete kernels
inherit IKernel indirectly via one of the CRTP helpers
(UnaryKernel, BinaryKernel, NaryKernel,
VariadicKernel); the CRTP layer supplies correct overrides
of every virtual below.
See Also
UnaryKernel, BinaryKernel, NaryKernel,
VariadicKernel — CRTP helpers that provide the typed
implementations of apply and (when applicable) compute.
KernelPolicy — documentation of the compile-time flags
concrete kernels expose to the CRTP layer.
Notes
The interface is intentionally split: compute is the generic
polymorphic forward entry point, while apply is the backward
entry point called by the autograd engine during reverse-mode
differentiation. In practice nearly every op routes its forward
through its CRTP base's typed static forward() (which handles
dtype promotion, contiguity, dispatch and graph wiring) and uses
compute only when invoked through a fully generic harness.
Thread safety: instances are not thread-safe. The framework constructs a fresh kernel per forward invocation and never shares it across threads.
Destructor
1Methods
3Backward entry point — invoked by the autograd engine.
Parameters
grad_outStorageReturns
std::vector<Storage>One gradient Storage per forward input, in the same order as the inputs were consumed by forward().
Notes
CRTP bases override this method to delegate to
Derived::grad_formula(grad_out) and apply broadcast-reduction
back to the original input shapes; concrete ops only implement
the math.
Polymorphic forward entry point.
Parameters
inputsconst std::vector<Storage>&Returns
StorageThe single output storage.
Raises
:logic_errorforward() (which performs full dtype/shape/device handling). Override this method only when a kernel must participate in a fully generic dispatch loop.Return the canonical short name of this op (e.g. "add", "relu").
Returns
std::string_viewA stable, lifetime-bound view of the op's schema name. Used by error messages, profiler scopes and schema lookups.
Notes
The returned view aliases Derived::schema_v1.name in CRTP
kernels, so it is valid for the lifetime of the program.