pub struct ExecutionPlan { /* private fields */ }Expand description
Pre-compiled execution plan for a computation graph.
Created once via prepare(), then executed multiple times.
The plan owns all its buffers and compiled kernels.
Implementations§
Source§impl ExecutionPlan
impl ExecutionPlan
Sourcepub fn output_buffer(&self) -> Option<&Buffer>
pub fn output_buffer(&self) -> Option<&Buffer>
Get the first (or only) output buffer after execution.
Returns None for plans with no output buffers (for example, plans
constructed before set_output_buffer* is called).
Sourcepub fn output_buffer_at(&self, position: usize) -> Option<&Buffer>
pub fn output_buffer_at(&self, position: usize) -> Option<&Buffer>
Get output buffer by position (matches SINK source order for batch).
Returns None if position is out of range.
Sourcepub fn output_buffers(&self) -> Vec<&Buffer>
pub fn output_buffers(&self) -> Vec<&Buffer>
Get all output buffers.
Sourcepub fn num_outputs(&self) -> usize
pub fn num_outputs(&self) -> usize
Number of outputs in this plan.
Sourcepub fn buffer(&self, ast_id: u64) -> Option<&Buffer>
pub fn buffer(&self, ast_id: u64) -> Option<&Buffer>
Get a buffer by AST id (for reading intermediate results).
Sourcepub fn buffer_mut_by_id(&mut self, ast_id: u64) -> Option<&mut Buffer>
pub fn buffer_mut_by_id(&mut self, ast_id: u64) -> Option<&mut Buffer>
Get a mutable buffer by AST id (for copyin() on input buffers).
Sourcepub fn device(&self) -> &DeviceSpec
pub fn device(&self) -> &DeviceSpec
Get the primary device for this plan.
Sourcepub fn buffers_mut(&mut self) -> &mut [Buffer]
pub fn buffers_mut(&mut self) -> &mut [Buffer]
Get mutable access to all buffers owned by this plan.
Sourcepub fn buffer_at_mut(&mut self, index: usize) -> Option<&mut Buffer>
pub fn buffer_at_mut(&mut self, index: usize) -> Option<&mut Buffer>
Get a mutable buffer by its index in the buffers array.
Sourcepub fn prepared_kernels(&self) -> Vec<&PreparedKernel>
pub fn prepared_kernels(&self) -> Vec<&PreparedKernel>
Get all prepared kernels.
Sourcepub fn prepared_ops(&self) -> &[PreparedOp]
pub fn prepared_ops(&self) -> &[PreparedOp]
Get all prepared operations in schedule order.
Sourcepub fn kernels(&self) -> impl Iterator<Item = &CachedKernel>
pub fn kernels(&self) -> impl Iterator<Item = &CachedKernel>
Iterate over compiled kernels (for inspecting generated source code).
Sourcepub fn execute(&self) -> Result<()>
pub fn execute(&self) -> Result<()>
Execute the plan.
Uses dependency-aware operation ordering for all prepared op types.
Sourcepub fn execute_profiled(&self) -> Result<Vec<KernelProfile>>
pub fn execute_profiled(&self) -> Result<Vec<KernelProfile>>
Execute the plan with per-kernel timing.
Returns a KernelProfile for each kernel in execution order.
§Example
let plan = tensor.prepare()?;
let profiles = plan.execute_profiled()?;
// Sort by time descending
let mut sorted = profiles;
sorted.sort_by(|a, b| b.elapsed.cmp(&a.elapsed));
for p in &sorted[..10.min(sorted.len())] {
println!("{:>8.3}ms {}", p.elapsed.as_secs_f64() * 1000.0, p.kernel.entry_point);
}Sourcepub fn execute_with_vars(&mut self, var_vals: &[(&str, i64)]) -> Result<()>
pub fn execute_with_vars(&mut self, var_vals: &[(&str, i64)]) -> Result<()>
Re-execute the plan with different variable bindings.
The kernel code is NOT recompiled; only the vals passed to each kernel
are updated. Buffers must be allocated to max variable values (which is
the default when using Variable::bind()).
§Safety contract
Variable values must fall within [min_val, max_val] bounds defined
at Variable::new() time. Exceeding max_val causes out-of-bounds buffer
access (buffers are allocated to max_val). Use Variable::bind() to
validate bounds before calling this method.
Variables not present in var_vals keep their existing values from
prepare() (or the previous execute_with_vars call). Internal
variables like core_id are left untouched.
Sourcepub fn execute_with_vars_profiled(
&mut self,
var_vals: &[(&str, i64)],
) -> Result<Vec<KernelProfile>>
pub fn execute_with_vars_profiled( &mut self, var_vals: &[(&str, i64)], ) -> Result<Vec<KernelProfile>>
Re-execute the plan with different variable bindings and per-kernel timing.
Updates kernel vals the same way as Self::execute_with_vars and then
executes via Self::execute_profiled.
Sourcepub fn output_buffer_idx(&self) -> usize
pub fn output_buffer_idx(&self) -> usize
Get the first output buffer index.
Sourcepub fn ast_to_buffer_map(&self) -> &HashMap<u64, usize>
pub fn ast_to_buffer_map(&self) -> &HashMap<u64, usize>
Get the AST ID to buffer index mapping.
Sourcepub fn release_intermediate_buffers<F>(&self, remove_fn: F)
pub fn release_intermediate_buffers<F>(&self, remove_fn: F)
Release intermediate buffers from the global buffer registry.
Call this after you’re done executing the plan to free intermediate buffers from the global registry. The output buffer is preserved.
Sourcepub fn release_all_buffers<F>(&self, remove_fn: F)
pub fn release_all_buffers<F>(&self, remove_fn: F)
Release ALL buffers from the global registry, including the output.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ExecutionPlan
impl !RefUnwindSafe for ExecutionPlan
impl Send for ExecutionPlan
impl Sync for ExecutionPlan
impl Unpin for ExecutionPlan
impl UnsafeUnpin for ExecutionPlan
impl !UnwindSafe for ExecutionPlan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more