constant_info.h#
Constant-value / constant-node analysis.
A constant value is one whose content is known before any inference starts: graph initializers, the output of a Constant node, and — more generally — the output of any deterministic node all of whose inputs are themselves constant. A constant node is a node whose outputs are all constant. Graph inputs are never constant.
The analysis mirrors the value / node tag machinery (:file:value_tags.h): the result is recorded per value on the metadata_props of every ValueInfoProto (graph inputs, outputs and shape-inference value_info) and initializer TensorProto, and per node on the NodeProto metadata_props, under :cpp:var:kConstantMetadataKey. Nested subgraphs are supported: the analysis recurses into GRAPH / GRAPHS attributes, seeding each subgraph with the constant values captured from the enclosing scope.
-
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 compute
Enums
Functions
-
bool IsNonDeterministicOp(const std::string &domain, const std::string &op_type)#
Returns whether
op_type(in the default ONNX domain) is non-deterministic and therefore never produces a constant output, even when all of its inputs are constant (e.g. the random generators).
-
bool IsNodeConstant(const NodeProto &node, const std::unordered_set<std::string> &constants)#
Returns whether
nodeproduces constant outputs given the set of already knownconstantsvalue names. A node is constant when it is deterministic, every value it references (direct inputs and subgraph captures) is constant, and none of its subgraphs contain a non-deterministic op. Nodes with no reachable inputs (e.g.Constant) are constant unless the op is non-deterministic.
-
std::pair<std::unordered_set<std::string>, std::vector<ConstantInfo>> InferConstants(const GraphProto &graph, const std::unordered_set<std::string> &outer_constants = {})#
Infers the set of constant value names and the per-node constant flags for
graph.outer_constantsseeds the analysis with values captured from an enclosing scope (used when recursing into subgraphs). The returnedstd::vector<ConstantInfo>has one entry per node, aligned withgraph.node().
-
std::pair<std::unordered_set<std::string>, std::vector<ConstantInfo>> InferConstants(const FunctionProto &function, const std::unordered_set<std::string> &outer_constants = {})#
Same as :cpp:func:
InferConstants(const GraphProto&, ...)but for aFunctionProto(which carries no initializers; its formal inputs are never constant).
-
void WriteConstantInfoToMetadata(GraphProto &graph)#
Runs :cpp:func:
InferConstantsongraphand records the result in themetadata_propsof every constant node and every constant value (graph inputs, outputs,value_infoand initializers) under :cpp:var:kConstantMetadataKey. Recurses into subgraphs, seeding each with the constant values captured from the enclosing scope.
-
void WriteConstantInfoToMetadata(FunctionProto &function)#
Same as :cpp:func:
WriteConstantInfoToMetadata(GraphProto&)but for aFunctionProto.
-
void WriteConstantInfoToMetadata(ModelProto &model)#
Same as :cpp:func:
WriteConstantInfoToMetadata(GraphProto&)but for aModelProto(operates on its main graph).
Variables
-
constexpr const char *kConstantMetadataKey = "onnx_light.constant"#
Metadata key under which the constant analysis records that a value or node is constant (known before inference). The associated value is
"1".
-
bool IsNonDeterministicOp(const std::string &domain, const std::string &op_type)#
-
namespace compute
-
namespace core