persistent_value#
PersistentTensor owns a retained tensor value and its optional append capacity
by composition. Its move-only AppendLease reserves writable tails, grants at
most one in-place extension per invocation, and owns the contiguous growth policy.
AppendReservation exposes only the new region: the kernel initializes it
directly, then seals the candidate with Commit. Sealing does not publish
feedback state. Ordinary Tensor copies and borrowed views carry no such permission.
PersistentValue preserves whole structured and encoded feedback values, using
PersistentTensor for tensor leaves.
Reservations record allocations, copied bytes and reuse directly through the
optional RuntimeContext supplied to Reserve when its existing
events_enabled option is true. Reports appear in the shared
RuntimeContext::events() log as kPersistentStorage events.
Their storage_* fields describe the work for that event, independently of
the consuming operator. There is no separate statistics object or cumulative
counter state; consumers sum fields from the event list when totals are needed.
-
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 PersistentTensor : private AppendLease, private AppendReservation#
- #include <persistent_value.h>
Retains a tensor value and, for internally allocated append buffers, spare capacity.
Ordinary Tensor views carry lifetime ownership, never capacity or write permissions. Importing such a view retains its payload without certifying it for append. The owner serializes access, as PersistentValueState does; each prepared AppendLease may be consumed only once, even when an append requires a copy or is declined.
Reserves append destinations using the contiguous tensor’s storage policy.
Captures the retained prefix for one append attempt. Further reservations are rejected. Allocation, geometric growth and prefix relocation belong here; producing the new elements belongs to the kernel.
Exposes only the writable tail of an unpublished contiguous result.
The kernel initializes the entire region directly, then seals the candidate. Destruction without Commit abandons it without changing the retained prefix or logical extent. Written tail bytes need not be restored on abandonment.
Public Functions
-
PersistentTensor(PersistentTensor&&) noexcept = default#
-
PersistentTensor &operator=(PersistentTensor&&) noexcept = default#
-
PersistentTensor(const PersistentTensor&) = delete#
-
PersistentTensor &operator=(const PersistentTensor&) = delete#
-
inline const Tensor &value() const noexcept#
Returns the committed logical value, excluding spare capacity.
-
inline size_t capacity_bytes() const noexcept#
Returns certified capacity in bytes, or zero for imported storage.
-
bool Matches(const Tensor &view) const noexcept#
Returns whether a view has this exact owner, extent, type and shape.
-
AppendLease PrepareAppend() const#
Prepares append reservations before invocation-local views are created.
Captures the prefix and its capacity for one append attempt. Only exclusive certified storage grants in-place permission; otherwise the append allocates.
-
AppendLease(AppendLease &&other) noexcept#
-
AppendLease &operator=(AppendLease &&other) noexcept#
-
AppendLease(const AppendLease&) = delete#
-
AppendLease &operator=(const AppendLease&) = delete#
-
inline bool Matches(const Tensor &view) const noexcept
Returns whether the invocation input still matches the captured prefix.
-
std::optional<AppendReservation> Reserve(const Shape &shape, size_t axis, size_t initial_capacity, RawBufferAllocator *allocator, RuntimeContext *context = nullptr)#
Reserves an uninitialized tail, declining layouts that cannot append contiguously.
Only the append axis may grow, and the product of preceding dimensions must be one. Initial capacity is measured along that axis, not in bytes. Zero capacity declines the reservation but still consumes this lease. Records allocation, prefix copies and reuse in the supplied runtime context when events are enabled, including work before a failure. The caller supplies the output allocator; no alternate allocator is used.
-
AppendReservation(AppendReservation&&) noexcept = default#
-
AppendReservation &operator=(AppendReservation&&) noexcept = default#
-
AppendReservation(const AppendReservation&) = delete#
-
AppendReservation &operator=(const AppendReservation&) = delete#
-
std::span<uint8_t> writable_bytes()#
Returns the reserved tail, valid until this reservation is committed or destroyed.
-
PersistentTensor Commit(size_t initialized_bytes)#
Seals a fully initialized candidate without publishing the feedback state.
Requires initialized_bytes to match the whole tail; the caller guarantees that these bytes were written. No writable span may be used after this call.
Private Types
Private Functions
-
AppendLease(const PersistentTensor &tensor, bool available)#
-
inline AppendReservation(PersistentTensor candidate, size_t prefix_bytes)#
Private Members
-
size_t capacity_bytes_ = 0#
-
PersistentTensor prefix_#
-
PersistentTensor candidate_#
-
size_t prefix_bytes_#
Friends
- friend class PersistentTensor
- friend class AppendLease
-
PersistentTensor(PersistentTensor&&) noexcept = default#
-
class PersistentValue#
- #include <persistent_value.h>
Retains a whole feedback value with PersistentTensor at its numeric tensor leaves.
Public Functions
-
explicit PersistentValue(RuntimeValue value, const StructTypeCatalogue &catalogue = {})#
-
explicit PersistentValue(PersistentTensor tensor)#
-
PersistentValue(PersistentValue&&) noexcept = default#
-
PersistentValue &operator=(PersistentValue&&) noexcept = default#
-
PersistentValue(const PersistentValue&) = delete#
-
PersistentValue &operator=(const PersistentValue&) = delete#
-
inline const PersistentTensor *tensor() const noexcept#
Returns a root tensor, or null for structured, sequence and encoded values.
-
RuntimeValue BorrowView() const#
Returns ordinary views without exposing capacity or append permissions.
Private Members
-
RuntimeValue::Kind kind_ = RuntimeValue::Kind::kStruct#
-
std::optional<PersistentTensor> tensor_#
-
std::unordered_map<std::string, PersistentValue> fields_#
-
RuntimeSequence elements_#
-
std::shared_ptr<const EncodedValueProto> encoded_#
-
std::shared_ptr<const QuantizationParameterCatalogue> quantization_parameters_#
Private Static Functions
-
static PersistentValue FromRetained(RuntimeValue value, size_t depth = 0)#
-
explicit PersistentValue(RuntimeValue value, const StructTypeCatalogue &catalogue = {})#
-
class PersistentTensor : private AppendLease, private AppendReservation#
-
namespace runtime
-
namespace core