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_NAMESPACE so 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_proto uses hidden visibility by default.

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 core
namespace compute

Enums

enum class ConstantInfo : uint8_t#

Classifies whether a node produces constant outputs.

Values:

enumerator kNotConstant#
enumerator kConstant#

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 node produces constant outputs given the set of already known constants value 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_constants seeds the analysis with values captured from an enclosing scope (used when recursing into subgraphs). The returned std::vector<ConstantInfo> has one entry per node, aligned with graph.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 a FunctionProto (which carries no initializers; its formal inputs are never constant).

void WriteConstantInfoToMetadata(GraphProto &graph)#

Runs :cpp:func:InferConstants on graph and records the result in the metadata_props of every constant node and every constant value (graph inputs, outputs, value_info and 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 a FunctionProto.

void WriteConstantInfoToMetadata(ModelProto &model)#

Same as :cpp:func:WriteConstantInfoToMetadata(GraphProto&) but for a ModelProto (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".