dispatch_table.h#
Per-(domain, op_type) dispatch table used by :cpp:func:core::shapes::ShapesContext::ComputeShapeNode to forward each NodeProto to the matching ComputeShape* implementation.
The generic dispatch mechanism (this file, :cpp:class:ShapesContext, :cpp:func:InferShapesModel, …) lives in onnx_core so it has no dependency on any particular set of operator implementations. The concrete ComputeShape* functions (“shape functions”) for every standard ONNX operator remain in onnx_shapes and register themselves here via :cpp:func:RegisterComputeShapeFn instead of being hard-coded in this table, which keeps the onnx_core -> onnx_shapes dependency direction from ever being introduced.
-
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 shapes
Typedefs
-
using ComputeShapeFn = std::function<void(ShapesContext&, const NodeProto&)>#
Signature of every per-operator
ComputeShape*trampoline registered in :cpp:func:DispatchTable: it reads the node’s inputs fromctxand inserts the resulting output descriptors back intoctx.
-
using ComputePeakMemoryFn = std::function<int64_t(Device, const std::vector<SymShape>&)>#
Signature of every per-operator peak-memory function registered in :cpp:func:
PeakMemoryDispatchTable. Mirroring :cpp:type:ComputeShapeFn, but for memory rather than shapes, it estimates the peak amount of scratch/working memory (in bytes) an operator’s computation needs, in addition to its declared inputs and outputs.The function takes the :cpp:enum:
Deviceon which the operator executes followed by the :cpp:class:SymShapeof each of its inputs, and returns the estimated peak memory as anint64_t. The returned value is the extra scratch/working memory the computation allocates; it excludes the memory already accounted for by the operator’s inputs and outputs. When no function is registered for an operator the default is to return0(see :cpp:func:ComputePeakMemory).
Functions
-
const std::unordered_map<std::string, ComputeShapeFn> &DispatchTable()#
Returns the
(normalised_domain, op_type) -> ComputeShape*dispatch table. Empty until shape-function libraries (e.g.onnx_shapes) populate it via :cpp:func:RegisterComputeShapeFn.
-
void RegisterComputeShapeFn(const std::string &domain, const std::string &op_type, ComputeShapeFn fn)#
Registers (or replaces) the
ComputeShape*function for (domain,op_type) in the shared :cpp:func:DispatchTable.Use an empty string for
domainto denote the default ONNX domain (normalised to :cpp:var:kOnnxDomain). Intended to be called once per operator during static initialization by shape-function libraries that must not be linked intoonnx_core(e.g.onnx_shapes); seeonnx_shapes::RegisterShapeFunctions.- Parameters:
domain – The operator domain (
""or"ai.onnx"for standard ONNX).op_type – The ONNX operator type name (e.g.
"Abs").fn – The shape function implementing the
ComputeShape*rule.
-
const std::unordered_map<std::string, ComputePeakMemoryFn> &PeakMemoryDispatchTable()#
Returns the
(normalised_domain, op_type) -> ComputePeakMemoryFndispatch table. Empty until libraries populate it via :cpp:func:RegisterComputePeakMemoryFn; operators without an entry report a peak memory of0through :cpp:func:ComputePeakMemory.
-
void RegisterComputePeakMemoryFn(const std::string &domain, const std::string &op_type, Device device, ComputePeakMemoryFn fn)#
Registers (or replaces) the peak-memory function for the identifier (
domain,op_type,device) in the shared :cpp:func:PeakMemoryDispatchTable.Use an empty string for
domainto denote the default ONNX domain (normalised to :cpp:var:kOnnxDomain).deviceis part of the identifier so that a distinct estimator can be registered per device; :cpp:enumerator:Device::kCPU(and :cpp:enumerator:Device::kUndefined) denote the default host entry. Mirrors :cpp:func:RegisterComputeShapeFnso that libraries that must not be linked intoonnx_corecan contribute their per-operator memory estimators.- Parameters:
domain – The operator domain (
""or"ai.onnx"for standard ONNX).op_type – The ONNX operator type name (e.g.
"Abs").device – The device the estimator applies to (e.g. :cpp:enumerator:
Device::kCPU).fn – The peak-memory function implementing the estimation rule.
-
int64_t ComputePeakMemory(const std::string &domain, const std::string &op_type, Device device, const std::vector<SymShape> &input_shapes)#
Returns the estimated peak memory (in bytes) for (
domain,op_type) executed ondevicewith inputs of shapeinput_shapes.Looks the operator up in the shared :cpp:func:
PeakMemoryDispatchTableand forwards to its registered :cpp:type:ComputePeakMemoryFn. When no function is registered for the operator the default is to return0.- Parameters:
domain – The operator domain (
""or"ai.onnx"for standard ONNX).op_type – The ONNX operator type name (e.g.
"Abs").device – The device on which the operator executes.
input_shapes – The shapes of the operator’s inputs, in order.
- Returns:
The estimated peak memory in bytes, or
0when the operator has no registered peak-memory function.
-
using ComputeShapeFn = std::function<void(ShapesContext&, const NodeProto&)>#
-
namespace shapes
-
namespace core