result_lifetime.h#

Standalone value-lifetime analysis shared by :cpp:func:ComputeContext::ComputeInPlaceReuseGraph.

This header isolates the purely name-based bookkeeping that decides, for every node of a graph, which values reach their last use at that node (:cpp:var:ResultLifetimeNodeInfo::release_after / :cpp:var:ResultLifetimeNodeInfo::not_used_after). It does not depend on shape inference or byte sizes: those live in compute_context.cc and combine this lifetime information with the shape-driven in-place reuse matching.

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

Functions

ResultLifetimeInfo ComputeResultLifetimeInfo(const GraphProto &graph, bool allow_input_overwrite)#

Computes the per-node value-lifetime information for graph: which values are read for the last time at each node, and which of those are releasable top-level intermediates versus caller-owned inputs / initializers.

Parameters:
  • graph – Graph whose nodes are analysed, in topological order.

  • allow_input_overwrite – When true, declared graph inputs are treated as available before the first node (producer index -1) so they can be reused once they reach their last use; when false they are always kept alive.

ResultLifetimeInfo ComputeResultLifetimeInfo(const FunctionProto &function, bool allow_input_overwrite)#

Computes value lifetimes directly from a function’s nodes and declarations.

class ResultLifetimeInfo#
#include <result_lifetime.h>

Result of :cpp:func:ComputeResultLifetimeInfo: a per-node list of :cpp:struct:ResultLifetimeNodeInfo plus the producer / lifetime maps and name sets it was derived from, so callers can reuse them without recomputing.

Public Types

using value_type = ResultLifetimeNodeInfo#
using storage_type = std::vector<value_type>#
using iterator = storage_type::iterator#
using const_iterator = storage_type::const_iterator#

Public Functions

inline std::size_t size() const#
inline bool empty() const#
inline void resize(std::size_t count)#
inline value_type &operator[](std::size_t index)#
inline const value_type &operator[](std::size_t index) const#
inline iterator begin()#
inline iterator end()#
inline const_iterator begin() const#
inline const_iterator end() const#
inline const_iterator cbegin() const#
inline const_iterator cend() const#
inline std::vector<std::vector<std::string>> MoveReleaseAfter()#
inline std::vector<std::vector<std::string>> MoveNotUsedAfter()#

Public Members

std::unordered_map<std::string, int> producer#

Producer node index for every top-level intermediate (-1 marks a declared graph input made available before the first node when allow_input_overwrite is set).

std::unordered_map<std::string, int> last_use#

Index of the last node that references each name, directly or through a subgraph capture, or the producer for an unused output.

std::unordered_set<std::string> keep#

Names whose buffers must never be reused in place: initializers and declared graph outputs are always kept; declared graph inputs are kept unless allow_input_overwrite was requested.

std::unordered_set<std::string> graph_inputs#
std::unordered_set<std::string> graph_initializers#
std::unordered_set<std::string> graph_outputs#

Private Members

storage_type nodes_#
struct ResultLifetimeNodeInfo#
#include <result_lifetime.h>

Holds per-node value-lifetime bookkeeping from :cpp:func:ComputeResultLifetimeInfo.

Public Members

std::vector<std::string> release_after#

Per-node list of top-level intermediates that reach their last use at that node and are therefore releasable after it runs (excludes declared graph inputs, initializers and outputs). Unused outputs are released at their producing node.

std::vector<std::string> not_used_after#

Per-node list of declared graph inputs / initializers that reach their last use at that node. Not released by the runtime (their lifetime is owned by the caller / model) but still exposed as “last read” info.