value_store.h#
ValueStore owns immutable values prepared synchronously while
a RuntimeSession hierarchy initializes its kernels. RuntimeContext
always exposes a store, and child contexts inherit the same shared instance.
Each session owns a non-null store from construction and installs it into
the context before initializing kernels. Nested graph/function sessions
explicitly receive their parent’s owner. Independent sessions do not adopt
the store of a reused context; cross-session sharing requires
RuntimeSessionOptions::value_store.
Kernels bind a ValueStore::Slot during initialization. This opaque handle
associates a stable uint32_t index with the originating store. IsReady,
Publish, and Get reject handles from any other store, even when both
stores use the same numeric index. Raw integers cannot be used as handles;
Slot::index() exposes the index only for diagnostics.
Find(key) const looks up an existing slot without binding or allocating one.
It returns std::nullopt for an unknown key (including an empty key), and a
store-bound slot for a known key, even if its value has not been published.
Call IsReady(*slot) to check publication before Get or BindForRead;
both reads reject unpublished slots. Estimators can use this lookup through
const RuntimeContext::value_store() with the same execution cache key used
by preparation. An already published artifact needs no additional prepared
allocation: its storage is already included in prepared_bytes().
Lookups neither change that total nor create slots, and only search this store,
not independent stores with the same keys.
After publication, BindForRead(slot) checks ownership, bounds, and readiness
once and returns a ValueStore::BoundSlot. It contains only the store pointer
and a uint32_t index. Its parameterless Get() reads the immutable value
directly: no identity comparison, ownership copy, bounds/readiness validation,
map lookup, mutex, readiness wait, or scheduler dispatch occurs on the hot path.
There is no public unchecked Get(uint32_t) that could combine an arbitrary
index with another store. Gemm retains this validated binding, not the
identity-carrying setup handle. All sessions sharing a store must
serialize their runs. Its allocations remain alive until the last shared
owner, including any context, is released.
A slot retains only a small identity token, not the store or its prepared allocations. The token remains distinct if the original store is destroyed and another is constructed at the same address. Default-constructed and moved-from setup slots are rejected. Checked store operations take setup handles by const reference, while replay bindings contain no shared pointer. Bindings can only be constructed after successful validation and cannot be default-constructed. They borrow the original store, which must remain alive through every read; neither kind of handle extends its allocation lifetime.
The location under runtime/kernels/ reflects its kernel-preparation role:
it is not the invocation value directory. “Static” means publication once per
slot followed by immutable replay, not a global C++ object or mutation-free
initialization. value_store() returns a reference;
value_store_owner() returns shared ownership. Both session and context
accessors expose only read-only views through const objects.
This store does not schedule asynchronous loading, track generations, evict values, or persist prepared payloads.
prepared_bytes() returns an incrementally maintained live-byte total in
constant time, including allocated but unpublished values. Each allocation
and release updates the total, including reuse through a tensor’s allocator.
accounting_allocator_visits() exposes allocator live-byte query visits for
deterministic scaling diagnostics; reading the total adds no visits.
The total excludes retained free-buffer
capacity and execution/I/O arenas. There is no static-store admission budget or
eviction policy.
-
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 runtime
-
-
class ValueStore#
- #include <value_store.h>
Stores statically prepared, immutable kernel values, not invocation values.
A root session fixes its owner at construction and explicitly shares it with nested graph and model-local function sessions. Other sessions share it only when their construction options supply the same owner. The store and its allocations live until the last shared owner (including contexts) is released. “Static” means publication once per slot followed by immutable replay, not a global C++ object or mutation-free initialization.
All sessions sharing the store are serialized by contract. Indexed reads neither copy identity ownership nor require mutexes or atomic updates. Initialization uses the store-bound slot returned by :cpp:func:
Bind. Once published, :cpp:func:BindForReadvalidates it and returns a binding that performs direct indexed reads without repeating ownership checks. This store does not schedule asynchronous tasks, track generations, persist payloads, or evict prepared values.Public Functions
-
ValueStore() = default#
-
ValueStore(const ValueStore&) = delete#
-
ValueStore &operator=(const ValueStore&) = delete#
-
ValueStore(ValueStore&&) = delete#
-
ValueStore &operator=(ValueStore&&) = delete#
-
std::optional<Slot> Find(const std::string &key) const#
Returns an existing slot without creating one, or nullopt for an unknown key.
An empty key is unknown. A returned slot belongs to this store but may be unpublished; IsReady checks publication before Get or BindForRead.
-
void Publish(const Slot &slot, RuntimeValue value)#
-
const RuntimeValue &Get(const Slot &slot) const#
-
BoundSlot BindForRead(const Slot &slot) const#
Validates a published slot once and binds it for direct immutable replay.
-
size_t prepared_bytes() const noexcept#
Returns the incrementally maintained live-byte total in O(1). Includes allocated but unpublished values, not retained free capacity or other runtime storage. No admission budget or eviction applies.
-
inline size_t accounting_allocator_visits() const noexcept#
Returns allocator live-byte query visits for accounting scaling diagnostics.
-
inline size_t slot_count() const noexcept#
Private Functions
-
std::optional<RuntimeValue> &ValueAt(const Slot &slot)#
-
const std::optional<RuntimeValue> &ValueAt(const Slot &slot) const#
Private Members
-
size_t prepared_bytes_ = 0#
-
size_t accounting_allocator_visits_ = 0#
-
std::vector<std::unique_ptr<ExecutionArena>> allocators_#
-
std::deque<std::optional<RuntimeValue>> slots_#
-
class BoundSlot#
- #include <value_store.h>
Borrows a published value through a validated store pointer and integer index.
Only BindForRead constructs bindings, after checking ownership and readiness. Publication is immutable, so reads need no further validation. The original store must outlive the binding’s use; this binding retains no shared owner.
Public Functions
-
inline const RuntimeValue &Get() const noexcept#
Returns the immutable value directly, without ownership or readiness checks.
Private Functions
-
inline BoundSlot(const ValueStore &store, uint32_t index)#
Friends
- friend class ValueStore
-
inline const RuntimeValue &Get() const noexcept#
-
struct Identity#
-
class Slot#
- #include <value_store.h>
Identifies a stable index in one store, without retaining its allocations.
A default-constructed or moved-from slot is unbound and rejected by store operations. The identity token prevents a slot from matching another store, even if the original store’s address is reused after destruction.
Public Functions
-
Slot() = default#
-
inline uint32_t index() const noexcept#
Returns the numeric index for diagnostics, not an interchangeable handle.
Private Functions
Friends
- friend class ValueStore
-
Slot() = default#
-
ValueStore() = default#
-
class ValueStore#
-
namespace runtime
-
namespace core