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_NAMESPACE so 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 with ONNX_API compile without modification.

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 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::ComputeShapeModel on model and then :cpp:func:ShapesContext::ApplyInferredShapesToModel, mutating model in place so that its graph.output() and graph.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 model has no graph or when shape inference of the graph rejects a node.