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_NAMESPACEso 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_protouses hidden visibility by default.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_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 fromonnx.-
namespace core
-
namespace runtime
Functions
-
class KernelBase#
- #include <kernel_context.h>
Base class for every kernel.
Each concrete kernel class derives from
KernelBaseso it inherits ownership of the construction-timeKernelContext. Derived kernels access the context through the protectedctx_member and typically inheritKernelBase’s constructor viausing KernelBase::KernelBase;, which preserves theexplicitqualifier 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 theKernelContextlocal variable used at registration time.KernelBaseis also the runtime dispatch interface: it exposes a virtual :cpp:func:Runthat the runtime (:cpp:func:RunNode/ :cpp:class:RuntimeSession) calls once per node. Each dispatch-registered kernel overrides :cpp:func:Runto read the node’s current inputs fromrt.tensors(), invoke its ownoperator()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:Runthrows — 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 boilerplateKernelContext 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 ofrt: 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 ¶meters)#
Validates and copies resolved parameters into this kernel’s typed, immutable configuration.
Called at most once, while a :cpp:class:
RuntimeSessioninitializes the kernel and before its first :cpp:func:Run.
Protected Attributes
-
KernelContext ctx_#
-
inline explicit KernelBase(const KernelContext &ctx)#
-
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
KernelContextargument. 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
opsetfield 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
-
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.
nullptrwhen the owning :cpp:class:RuntimeContexthas no allocator attached (the default), in which case results fall back to inlinestd::vectorstorage. Initialized from the allocator supplied to :cpp:class:RuntimeContext.
-
KernelContext() = default#
-
struct OpsetId#
- #include <kernel_context.h>
Lightweight opset identifier used by the backend test library.
Mirrors the (domain, version) pair carried by
OperatorSetIdProtobut keeps the public API of this library independent from the proto type so test cases can be declared without touching the proto wire format.
-
class KernelBase#
-
namespace runtime
-
namespace core