Skip to content
class

IKernel

IKernel

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

1
dtor

~IKernel

void ~IKernel()

Virtual destructor — ensures derived UnaryKernel / BinaryKernel / ReduceKernel destructors run when held by a base-class pointer. Defaulted; nothing to clean up at this layer.

Methods

3
fn

apply

→std::vector<Storage>
int apply(int grad_out)

Backward entry point — invoked by the autograd engine.

Parameters

grad_outStorage
The gradient of the loss with respect to this op's output.

Returns

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.

fn

compute

→Storage
int compute(const int &)

Polymorphic forward entry point.

Parameters

inputsconst std::vector<Storage>&
Flat ordered list of input storages. The interpretation (arity, shapes, dtype) is determined by the concrete kernel.

Returns

Storage

The single output storage.

Raises

:logic_error
The default implementation always throws — concrete kernels are normally invoked via their typed static forward() (which performs full dtype/shape/device handling). Override this method only when a kernel must participate in a fully generic dispatch loop.
fnconst

name

→std::string_view
int name()

Return the canonical short name of this op (e.g. "add", "relu").

Returns

std::string_view

A 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.