runtime_value#

RuntimeValue represents named TypeProto.struct_type fields and EncodedValueProto payloads. Tensor leaves reuse Tensor. Ordinary tensor edges remain exclusively in RuntimeContext::tensors(); values() is for structured/encoded edges, not a parallel tensor store.

The header declares the representation and API; runtime_value.cc implements copying, retention and validation.

The representation is independent of persistence. Encoded messages have one immutable shared owner from construction, not mutable inline storage plus a second promoted representation. BorrowView() copies numeric metadata and existing owner handles, without changing the source. Ordinary string fields are materialized instead, as required by normal string execution. DeepCopy() copies all payloads explicitly. std::move(value).Retain() consumes a selected whole result, recursively moving owned tensor buffers or exporting existing I/O allocations as IOLease handles. An ownerless borrow or unleased execution-arena allocation cannot be retained, except an explicit immutable initializer view whose proto lifetime is guaranteed by the C++ caller. String tensors cannot be retained, including nested fields and constants in an encoded layout. Retain(catalogue) resolves encoded layout references through the model catalogue; unresolved references and recursive types are rejected.

Structured Identity forwarding uses normal RuntimeValue copy semantics: owned tensor storage is copied, while existing tensor owners and immutable encoded messages are shared. Unlike BorrowView(), this keeps inline-owned intermediate fields valid when their source is released, including when there are multiple consumers. It does not mutate or promote the source.

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 runtime

Typedefs

using RuntimeValueMap = std::unordered_map<std::string, RuntimeValue>#
class RuntimeSequence#
#include <runtime_value.h>

Shares immutable sequence elements through a balanced tree.

Copies share metadata; append and replacement copy only a logarithmic path. Elements are read-only: replaces a changed element with Set(), never through a mutable reference. Retained payloads follow the usual read-only contract.

Public Functions

RuntimeSequence() = default#
explicit RuntimeSequence(std::vector<RuntimeValue> values)#
inline size_t size() const noexcept#
inline bool empty() const noexcept#
inline void clear() noexcept#
inline size_t depth() const noexcept#
inline bool retained() const noexcept#
const RuntimeValue &at(size_t index) const#
inline const RuntimeValue &operator[](size_t index) const#
inline const RuntimeValue &front() const#
inline const RuntimeValue &back() const#
void push_back(RuntimeValue value)#
void Set(size_t index, RuntimeValue value)#

Replaces an element without changing any existing snapshot.

RuntimeSequence Transform(const std::function<RuntimeValue(const RuntimeValue&)> &transform) const#

Returns a sequence with independently transformed elements.

void TransformInPlace(const std::function<void(RuntimeValue&)> &transform)#

Updates unpublished elements, consuming unique storage and copying shared snapshots.

inline const_iterator begin() const#
inline const_iterator end() const#
template<typename Result, typename Leaf, typename Join>
inline Result Fold(Memo<Result> &memo, const Leaf &leaf, const Join &join) const#

Reduces only changed tree paths; each memo belongs to one analysis policy.

Private Types

using Root = std::shared_ptr<const Node>#

Private Functions

void Retain(const StructTypeCatalogue &catalogue, size_t depth)#

Private Members

Root root_#

Private Static Functions

static Root Append(Root root, Root leaf)#
static Root Replace(const Root &root, size_t index, Root leaf)#
static Root RetainNode(const Root &root, const StructTypeCatalogue &catalogue, size_t depth)#
static Root TransformNode(const Root &root, const std::function<RuntimeValue(const RuntimeValue&)> &transform)#
static Root TransformOwnedNode(const Root &root, bool shared, const std::function<void(RuntimeValue&)> &transform)#
static const RuntimeValue &At(const Root &root, size_t index)#

Friends

friend struct RuntimeValue
class const_iterator#
#include <runtime_value.h>

Public Types

using iterator_category = std::forward_iterator_tag#
using value_type = RuntimeValue#
using difference_type = std::ptrdiff_t#
using reference = const RuntimeValue&#
using pointer = const RuntimeValue*#

Public Functions

const_iterator() = default#
inline const_iterator(Root root, size_t index)#
inline reference operator*() const#
inline pointer operator->() const#
inline const_iterator &operator++()#
inline const_iterator operator++(int)#
bool operator==(const const_iterator &other) const = default#

Private Members

Root root_#
size_t index_ = 0#
template<typename Result>
class Memo#
#include <runtime_value.h>

Memoizes one immutable analysis policy without retaining sequence storage.

Private Functions

template<typename Leaf, typename Join>
inline Result Fold(const Root &node, const Leaf &leaf, const Join &join)#

Private Members

std::mutex mutex_#
std::unordered_map<const Node*, Entry> entries_#

Friends

friend class RuntimeSequence
struct Entry#

Public Members

std::weak_ptr<const Node> node#
Result result#
struct Node#

Public Functions

Node(RuntimeValue value, bool retained)#
Node(std::shared_ptr<const Node> left, std::shared_ptr<const Node> right)#

Public Members

std::shared_ptr<const Node> left#
std::shared_ptr<const Node> right#
std::shared_ptr<const RuntimeValue> value#
size_t size = 1#
size_t height = 1#
size_t depth = 0#
bool retained = false#
bool catalogue_independent = false#
struct RuntimeValue#
#include <runtime_value.h>

Represents tensors, typed sequences, named structures and immutable encoded proto values.

RuntimeContext stores ordinary tensor edges in its existing tensor map, not here. This recursive representation supplies the structured/encoded edges required by TypeProto, independently of whether an edge is persistent.

Public Types

enum class Kind#

Values:

enumerator kTensor#
enumerator kStruct#
enumerator kEncoded#
enumerator kSequence#

Public Functions

RuntimeValue() = default#
inline explicit RuntimeValue(Tensor value)#
inline explicit RuntimeValue(std::unordered_map<std::string, RuntimeValue> value)#
inline explicit RuntimeValue(std::vector<RuntimeValue> value)#
explicit RuntimeValue(EncodedValueProto value)#
bool HasPagedCacheStructure() const#

Recognizes the cache’s named structure; payloads and ranges require separate validation.

PagedCacheProto ToPagedCache(const std::string &name = "", const StructTypeCatalogue &catalogue = {}) const#

Exports a cache without decoding pages, sharing retained storage and copying ownerless payloads. Referenced types remain model-scoped.

const EncodedValueProto &Encoded() const#

Returns the immutable encoded message.

RuntimeValue BorrowView() const#

Borrows numeric storage and materializes ordinary string fields without changing this value.

RuntimeValue DeepCopy() const#

Returns independent owned payloads.

RuntimeValue Retain(const StructTypeCatalogue &catalogue = {}) &&#

Consumes a selected whole value and explicitly retains its backing storage.

Public Members

Kind kind = Kind::kStruct#
Tensor tensor#
std::unordered_map<std::string, RuntimeValue> fields#
RuntimeSequence elements#
std::shared_ptr<const EncodedValueProto> encoded#
std::shared_ptr<const QuantizationParameterCatalogue> quantization_parameters#

Public Static Functions

static RuntimeValue FromEncodedView(const EncodedValueProto &value, std::shared_ptr<void> owner)#

Returns an immutable message view with an explicit lifetime owner.

static RuntimeValue FromEncodedView(const EncodedValueProto &value)#

Borrows immutable proto storage; the proto must outlive all returned views.

static RuntimeValue FromPagedCache(PagedCacheProto value, const StructTypeCatalogue &catalogue = {}, std::shared_ptr<const QuantizationParameterCatalogue> parameters = {})#

Restores a validated cache, retaining proto storage and any shared parameter catalogue.

Public Static Attributes

static constexpr size_t kMaxDepth = 64#

Private Functions

size_t Depth(size_t depth = 0) const#
bool CatalogueIndependent(size_t depth = 0) const#
void RetainAtDepth(size_t depth, const StructTypeCatalogue &catalogue)#
RuntimeValue CopyAtDepth(size_t depth, bool owned) const#

Friends

friend class RuntimeSequence