prepared_execution.h#
-
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
Typedefs
-
using PreparedTaskExecutor = std::function<void(const TaskDescriptor&, PreparedExecutionState&)>#
Enums
Functions
- ONNX_LIGHT_CORE_API MaterializationTaskDescriptors ExpandMaterializationRecipe (const PreparedRequirementDescriptor &requirement, const MaterializationRecipe &selected, TaskId first_task_id)
Expands one selected recipe into its session-scoped preparation task chain.
-
class ExecutionHandle#
- #include <prepared_execution.h>
Owns the completion state of one
PrepareAsync/RunAsyncsubmission.The handle is movable but not copyable. It keeps the submission’s borrowed
PreparedExecutionStateand task executor referenced by the caller alive for as long as the submission still runs: destroying (or move-assigning over) a live handle blocks until every task the submission still owns reaches a terminal state, so no detached task can outlive the context or input state its submission borrowed.Cancel()only affects tasks this submission produces; shared session-scoped work still required elsewhere is left untouched.Public Functions
-
ExecutionHandle()#
-
ExecutionHandle(ExecutionHandle&&) noexcept#
-
ExecutionHandle &operator=(ExecutionHandle&&) noexcept#
-
ExecutionHandle(const ExecutionHandle&) = delete#
-
ExecutionHandle &operator=(const ExecutionHandle&) = delete#
-
~ExecutionHandle()#
-
const PreparedExecutionResult &Wait()#
Blocks until every required task finishes and rethrows the first error.
-
bool IsReady() const#
Returns whether the submission has already reached a terminal state.
-
void Cancel()#
Cooperatively cancels tasks this submission has not yet dispatched.
Already-running tasks finish normally; downstream tasks are suppressed. Session-scoped work owned by another submission is left untouched.
Private Functions
-
void WaitQuiet() noexcept#
Blocks until done without rethrowing; safe to call while unwinding.
Private Members
Private Static Functions
-
static ExecutionHandle Submit(std::function<PreparedExecutionResult(std::atomic<bool>&)> work)#
Friends
- friend class PreparedExecutionPlan
-
ExecutionHandle()#
-
struct MaterializationRecipe#
- #include <prepared_execution.h>
Public Members
-
struct MaterializationTaskDescriptors#
- #include <prepared_execution.h>
Public Members
-
TaskDescriptor load#
-
TaskDescriptor prepack#
-
TaskDescriptor publish#
-
TaskDescriptor dormant_fallback#
-
TaskDescriptor load#
-
class PreparationArena : public onnx_light::core::runtime::ExecutionArena#
- #include <prepared_execution.h>
Public Functions
-
virtual RawBuffer *Allocate(size_t n_bytes) override#
Allocates
n_bytesfrom the smallest sufficient retained buffer.An unused slot is preferred when no retained buffer is large enough. Once all slots have acquired storage, the largest undersized free buffer grows to satisfy the request.
- Throws:
std::bad_alloc – if all slots are currently live.
-
virtual void Free(RawBuffer *buffer) override#
Returns a live buffer to its capacity bucket without releasing its storage.
- Throws:
std::invalid_argument – if
bufis not live in this arena.
-
virtual size_t TotalAllocatedSize() const override#
Returns the logical bytes held by live buffers.
-
virtual size_t PeakAllocatedSize() const override#
Returns the peak logical live-byte count.
-
virtual void ResetPeak() override#
Resets the live-byte peak to the current live-byte count.
-
explicit ExecutionArena(size_t capacity, size_t retention_cap = std::numeric_limits<size_t>::max())#
Constructs an arena with at most
capacitysimultaneously live buffers.- Parameters:
capacity – Number of stable :cpp:struct:
RawBufferslots.retention_cap – Maximum total capacity kept on the retained free lists. Defaults to unbounded, disabling eviction.
-
virtual RawBuffer *Allocate(size_t n_bytes) override#
-
class PreparedArena : public onnx_light::core::runtime::ExecutionArena#
- #include <prepared_execution.h>
Public Functions
-
virtual RawBuffer *Allocate(size_t n_bytes) override#
Allocates
n_bytesfrom the smallest sufficient retained buffer.An unused slot is preferred when no retained buffer is large enough. Once all slots have acquired storage, the largest undersized free buffer grows to satisfy the request.
- Throws:
std::bad_alloc – if all slots are currently live.
-
virtual void Free(RawBuffer *buffer) override#
Returns a live buffer to its capacity bucket without releasing its storage.
- Throws:
std::invalid_argument – if
bufis not live in this arena.
-
virtual size_t TotalAllocatedSize() const override#
Returns the logical bytes held by live buffers.
-
virtual size_t PeakAllocatedSize() const override#
Returns the peak logical live-byte count.
-
virtual void ResetPeak() override#
Resets the live-byte peak to the current live-byte count.
-
explicit ExecutionArena(size_t capacity, size_t retention_cap = std::numeric_limits<size_t>::max())#
Constructs an arena with at most
capacitysimultaneously live buffers.- Parameters:
capacity – Number of stable :cpp:struct:
RawBufferslots.retention_cap – Maximum total capacity kept on the retained free lists. Defaults to unbounded, disabling eviction.
-
virtual RawBuffer *Allocate(size_t n_bytes) override#
-
class PreparedExecutionPlan#
- #include <prepared_execution.h>
Describes session preparation and invocation execution in one immutable graph.
Public Functions
-
explicit PreparedExecutionPlan(std::vector<TaskDescriptor> tasks)#
-
PreparedExecutionPlan(std::vector<TaskDescriptor> tasks, const RequiredPayloadManifest &payload_manifest)#
-
PreparedExecutionPlan(std::vector<TaskDescriptor> invocation_tasks, std::vector<PreparedMaterialization> materializations, const RequiredPayloadManifest &payload_manifest)#
-
inline const std::vector<TaskDescriptor> &tasks() const noexcept#
-
PreparedExecutionResult RunSequential(PreparedExecutionState &state, const PreparedTaskExecutor &executor) const#
Executes session producers and the invocation tasks through completion events.
- Parameters:
state – Mutable session state that owns reusable session-task generations.
executor – Executes a task descriptor. It may be called concurrently by the session worker and the invoking thread.
- Returns:
Fresh invocation diagnostics and the session generations it observed.
-
PreparedExecutionResult RunParallel(PreparedExecutionState &state, const PreparedTaskExecutor &executor, CpuExecutor &cpu_executor) const#
Executes ready tasks using persistent bounded I/O workers and
cpu_executor.CPU work is dispatched only through the supplied session executor; this method never creates another CPU worker pool.
-
ExecutionHandle PrepareAsync(PreparedExecutionState &state, const PreparedTaskExecutor &executor, CpuExecutor *cpu_executor = nullptr) const#
Submits only this plan’s session-scoped tasks and returns immediately.
state,executor, and (when supplied)cpu_executormust outlive the returned handle.
-
ExecutionHandle RunAsync(PreparedExecutionState &state, const PreparedTaskExecutor &executor, CpuExecutor *cpu_executor = nullptr) const#
Submits every task in this plan and returns immediately.
This plan,
state,executor, and (when supplied)cpu_executormust all outlive the returned handle.
-
void Prepare(PreparedExecutionState &state, const PreparedTaskExecutor &executor, CpuExecutor *cpu_executor = nullptr) const#
Synchronous
PrepareAsyncfollowed byWait.
Private Functions
-
PreparedExecutionResult Run(PreparedExecutionState &state, const PreparedTaskExecutor &executor, CpuExecutor *cpu_executor, const std::atomic<bool> *cancel_requested = nullptr) const#
Private Members
-
std::vector<TaskDescriptor> tasks_#
-
std::vector<PreparedKey> prepared_requirements_#
-
explicit PreparedExecutionPlan(std::vector<TaskDescriptor> tasks)#
-
struct PreparedExecutionResult#
- #include <prepared_execution.h>
-
class PreparedExecutionState#
- #include <prepared_execution.h>
Owns session preparation arenas and the mutable prepared-object residency state.
Public Functions
-
explicit PreparedExecutionState(size_t preparation_slots = 4, size_t prepared_slots = 4, size_t preparation_retention_cap = std::numeric_limits<size_t>::max(), size_t prepared_retention_cap = std::numeric_limits<size_t>::max(), PreparedSchedulerOptions scheduler_options = {})#
-
~PreparedExecutionState()#
-
inline PreparationArena &preparation_arena() noexcept#
-
inline PreparedArena &prepared_arena() noexcept#
-
AllocationHandle AllocatePrepared(size_t n_bytes)#
-
inline PreparedObjectStore &objects() noexcept#
-
inline const PreparedObjectStore &objects() const noexcept#
-
inline uint64_t readiness_epoch() const noexcept#
Private Functions
-
SessionTaskRequest RequestSessionTask(TaskId task_id, bool force_retry)#
Private Members
-
PreparationArena preparation_arena_#
-
PreparedArena prepared_arena_#
-
PreparedObjectStore objects_#
-
const PreparedExecutionPlan *hot_path_plan_ = nullptr#
-
uint64_t hot_path_epoch_ = 0#
Friends
- friend class PreparedExecutionPlan
-
explicit PreparedExecutionState(size_t preparation_slots = 4, size_t prepared_slots = 4, size_t preparation_retention_cap = std::numeric_limits<size_t>::max(), size_t prepared_retention_cap = std::numeric_limits<size_t>::max(), PreparedSchedulerOptions scheduler_options = {})#
-
struct PreparedKeyHash#
- #include <prepared_execution.h>
Public Functions
-
size_t operator()(const PreparedKey &key) const noexcept#
-
size_t operator()(const PreparedKey &key) const noexcept#
-
struct PreparedMaterialization#
- #include <prepared_execution.h>
Public Members
-
PreparedRequirementDescriptor requirement#
-
MaterializationRecipe selected#
-
TaskPriority priority = TaskPriority::kPrefetch#
-
PreparedRequirementDescriptor requirement#
-
struct PreparedObjectRequest#
- #include <prepared_execution.h>
Public Members
-
PreparedKey key#
-
uint64_t generation = 0#
-
TaskCompletion completion#
-
bool producer = false#
-
PreparedKey key#
-
struct PreparedObjectRequirement#
- #include <prepared_execution.h>
-
class PreparedObjectStore#
- #include <prepared_execution.h>
Tracks immutable prepared objects and shares one in-flight generation per key.
Public Functions
-
~PreparedObjectStore()#
-
PreparedObjectRequest Request(const PreparedObjectRequirement &requirement)#
Returns the resident generation or elects one caller to produce a new one.
-
void MarkPreparing(const PreparedObjectRequest &request)#
Transitions the request selected as producer from loading to preparing.
-
void Publish(const PreparedObjectRequest &request, AllocationHandle allocation)#
Atomically installs a complete allocation before satisfying its completion.
-
void Fail(const PreparedObjectRequest &request, std::exception_ptr error, std::string message = {})#
Fails the current generation and preserves its diagnostic exception.
-
std::optional<PreparedObjectView> Find(const PreparedKey &key) const#
Returns a resident object’s immutable view, or no value when not resident.
-
bool Evict(const PreparedKey &key)#
Evicts a resident generation and returns its allocation to its owner.
-
void AdmitAllocation(size_t n_bytes)#
Makes room for an allocation before it consumes a prepared-arena slot.
-
PreparedResidencyState State(const PreparedKey &key) const#
-
size_t resident_bytes() const#
-
size_t waiting_admissions() const#
-
inline size_t residency_budget() const noexcept#
-
inline uint64_t readiness_epoch() const noexcept#
Private Members
-
std::unordered_map<PreparedKey, std::unique_ptr<Entry>, PreparedKeyHash> entries_#
-
size_t residency_budget_#
-
size_t resident_bytes_ = 0#
-
size_t waiting_admissions_ = 0#
-
mutable uint64_t access_epoch_ = 0#
Private Static Functions
-
static void ValidateGeneration(const Entry &entry, const PreparedObjectRequest &request)#
-
~PreparedObjectStore()#
-
struct PreparedObjectView#
- #include <prepared_execution.h>
Public Members
-
RawBufferAllocator *owner = nullptr#
-
uint64_t generation = 0#
-
std::shared_ptr<const AllocationHandle> pin#
-
RawBufferAllocator *owner = nullptr#
-
struct PreparedRequirementDescriptor#
- #include <prepared_execution.h>
-
struct PreparedSchedulerOptions#
- #include <prepared_execution.h>
-
struct PreparedTaskTrace#
- #include <prepared_execution.h>
Public Members
-
TaskScope scope = TaskScope::kInvocation#
-
ResourceClass resource = ResourceClass::kCpu#
-
TaskPriority priority = TaskPriority::kPrefetch#
-
uint64_t start_ns = 0#
-
uint64_t end_ns = 0#
-
TaskScope scope = TaskScope::kInvocation#
-
using PreparedTaskExecutor = std::function<void(const TaskDescriptor&, PreparedExecutionState&)>#
-
namespace runtime
-
namespace core