shape_inference.h#
Top-level shape-inference helpers that dispatch to the per-operator ComputeShape* functions of onnx_optim.
The per-operator functions (for example :cpp:func:onnx_optim::shapes::math::ComputeShapeAbs) each take their inputs by name. The methods of :cpp:class:ShapesContext (declared in shapes_context.h and defined in shape_inference.cc) walk a single NodeProto or a topologically-sorted sequence of NodeProto (typically GraphProto::node()), look up the op type and forward the call to the matching ComputeShape* implementation.
The shape-inference entry points (:cpp:func:ShapesContext::ComputeShapeNode, :cpp:func:ShapesContext::ComputeShapes, :cpp:func:ShapesContext::ComputeShapeGraph, :cpp:func:ShapesContext::ComputeShapeModel, :cpp:func:ShapesContext::ApplyInferredShapesToGraph, :cpp:func:ShapesContext::ApplyInferredShapesToModel, :cpp:func:ShapesContext::CheckInputsAvailable and :cpp:func:ShapesContext::CheckOutputsNotAvailable) are defined as methods of :cpp:class:ShapesContext. The only free function left in this header is :cpp:func:InferShapesModel, a convenience helper that does not need a caller-supplied context.
-
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.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.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 onnx_optim
-
namespace shapes
Functions
-
void InferShapesModel(ModelProto &model, bool prefill_with_value_info_output = false)#
Convenience helper: constructs a fresh :cpp:class:
ShapesContext, runs :cpp:func:ShapesContext::ComputeShapeModelonmodeland then :cpp:func:ShapesContext::ApplyInferredShapesToModel, mutatingmodelin place so that itsgraph.output()andgraph.value_info()carry the inferred shapes.- Parameters:
model – In/out model on which shape inference is run and whose proto is updated with the inferred results.
prefill_with_value_info_output – When
true, enables the same prefill/anchor behavior as :cpp:func:ShapesContext::ComputeShapeModel.
- Throws:
std::invalid_argument – when
modelhas no graph or when shape inference of the graph rejects a node.
-
void InferShapesModel(ModelProto &model, bool prefill_with_value_info_output = false)#
-
namespace shapes
-
namespace onnx_optim