kernel_context.h#

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace core
namespace runtime

Functions

inline OpsetId DefaultOpset(int64_t version)#

Builds an :ref:OpsetId for the default ai.onnx domain (empty string).

class KernelBase#
#include <kernel_context.h>

Base class for every kernel.

Each concrete kernel class derives from KernelBase so it inherits ownership of the construction-time KernelContext. Derived kernels access the context through the protected ctx_ member and typically inherit KernelBase’s constructor via using KernelBase::KernelBase;, which preserves the explicit qualifier on the single-argument constructor.

ctx_ is stored by value so that kernels are safely copy-constructible: lazy test-case lambdas capture kernels by value and may outlive the KernelContext local variable used at registration time.

KernelBase is also the runtime dispatch interface: it exposes a virtual :cpp:func:Run that the runtime (:cpp:func:RunNode / :cpp:class:RuntimeSession) calls once per node. Each dispatch-registered kernel overrides :cpp:func:Run to read the node’s current inputs from rt.tensors(), invoke its own operator() and store the produced outputs back. The node the kernel runs for is attached once (during kernel resolution) via :cpp:func:set_node; the owning graph / execution plan outlives the kernel, so the stored pointer stays valid for the kernel’s life. The default :cpp:func:Run throws — only kernels registered in the dispatch table (and the control-flow / custom kernels) override it.

Centralizing the context member here keeps every kernel class consistent, makes it trivial to extend the construction-time interface (e.g. by adding new fields to KernelContext), and avoids a repeated boilerplate KernelContext ctx_; member in each kernel.

Subclassed by onnx_light::core::runtime::If, onnx_light::core::runtime::Loop, onnx_light::core::runtime::Scan, onnx_light::onnx_kernels::tuning::ParallelTunableKernel

Public Functions

inline explicit KernelBase(const KernelContext &ctx)#
KernelBase(const KernelBase&) = default#
KernelBase &operator=(const KernelBase&) = default#
virtual ~KernelBase() = default#
inline void set_node(const NodeProto &node)#

Attaches the node this kernel runs for. Called once at kernel-resolution time; the node outlives the kernel.

virtual void Run(RuntimeContext &rt)#

Runs the kernel for its node (see :cpp:func:set_node) against the current state of rt: reads the node’s current inputs, computes and writes the outputs back. Safe to call repeatedly. The default throws; every dispatch-registered kernel overrides it.

virtual KernelTuningKey TuningKey(int32_t element_type) const#

Returns the tuning key for this implementation and element_type.

The default returns an undefined key, indicating that the kernel has no tuning schema. Tunable kernels override this together with :cpp:func:Configure.

virtual void Configure(const KernelTuningParameters &parameters)#

Validates and copies resolved parameters into this kernel’s typed, immutable configuration.

Called at most once, while a :cpp:class:RuntimeSession initializes the kernel and before its first :cpp:func:Run.

Protected Attributes

KernelContext ctx_#
const NodeProto *node_ = nullptr#

The node this kernel was built for, or nullptr when the kernel is used directly (e.g. in tests) without being resolved through the dispatch path.

struct KernelContext#
#include <kernel_context.h>

Construction-time context passed to backend test kernel classes.

Kernels are implemented as classes whose constructor takes a single KernelContext argument. The context bundles the opset against which the kernel must behave so the same kernel class can specialize its computation (or perform opset-specific validation) without changing its call sites.

Only the opset field is exposed today; new construction-time inputs (for example a device descriptor or an allocator) can be added later as additional fields without breaking existing kernel classes.

Public Functions

KernelContext() = default#
inline explicit KernelContext(OpsetId opset_, RawBufferAllocator *allocator_ = nullptr)#

Public Members

OpsetId opset#

Opset against which the kernel must behave (domain + version).

RawBufferAllocator *allocator = nullptr#

Allocator kernels must use to acquire the raw byte storage of the tensors they return, so no result buffer is allocated outside the runtime context. nullptr when the owning :cpp:class:RuntimeContext has no allocator attached (the default), in which case results fall back to inline std::vector storage. Initialized from the allocator supplied to :cpp:class:RuntimeContext.

struct OpsetId#
#include <kernel_context.h>

Lightweight opset identifier used by the backend test library.

Mirrors the (domain, version) pair carried by OperatorSetIdProto but keeps the public API of this library independent from the proto type so test cases can be declared without touching the proto wire format.

Public Functions

OpsetId() = default#
inline OpsetId(std::string domain_, int64_t version_)#

Public Members

std::string domain#
int64_t version = 0#