graph_manipulations.h#

Lightweight GraphProto / NodeProto manipulation helpers (formerly onnx_proto/common_functions.h), including onnx_light::CollectExternalInputs(), onnx_light::CollectRemainingInputs() and onnx_light::CollectNodeInputs().

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.

Functions

std::vector<std::string> CollectExternalInputs(const utils::RepeatedProtoField<NodeProto> &nodes)#

Returns the list of input names referenced by nodes that are not produced as outputs by any node in the same list.

Recursively inspects subgraph attributes (GRAPH / GRAPHS) and appends names read by subgraph nodes when neither the subgraph nor the outer nodes produce those names.

The returned list preserves first-seen order and contains no duplicates. Empty input names are skipped.

std::vector<std::string> CollectExternalInputs(const std::vector<NodeProto> &nodes)#

std::vector overload of :cpp:func:CollectExternalInputs.

std::vector<std::vector<std::string>> CollectRemainingInputs(const utils::RepeatedProtoField<NodeProto> &nodes, const std::vector<std::string> &outputs)#

Returns, for every node in nodes, the list of input names that must already be available before that node runs in order to eventually produce the requested outputs.

The algorithm performs a backward reachability analysis: starting from the requested outputs, it determines the ancestors (the nodes and tensors the outputs transitively depend on). For each index i it considers the suffix nodes[i..], keeps only the nodes of that suffix that are ancestors of outputs (branches that do not contribute to outputs are pruned), and reports the names those relevant nodes read — including names captured by subgraph attributes GRAPH / GRAPHS — that are not produced within the suffix. Those are the tensors that need to be kept alive before running node i.

nodes is expected to be in topological order. The returned vector has exactly nodes.size() entries. Each inner list preserves first-seen order and contains no duplicates; empty input names are skipped.

std::vector<std::vector<std::string>> CollectRemainingInputs(const std::vector<NodeProto> &nodes, const std::vector<std::string> &outputs)#

std::vector overload of :cpp:func:CollectRemainingInputs.

std::vector<std::string> CollectNodeInputs(const NodeProto &node)#

Returns the full list of tensor / sequence names a single node depends on at runtime.

Includes names referenced by node.input() and external inputs captured by subgraph attributes (GRAPH / GRAPHS), preserves first-seen order without duplicates, and skips empty input names.