Skip to main content

ExecutionPlan

Struct ExecutionPlan 

Source
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

Source

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).

Source

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.

Source

pub fn output_buffers(&self) -> Vec<&Buffer>

Get all output buffers.

Source

pub fn num_outputs(&self) -> usize

Number of outputs in this plan.

Source

pub fn buffer(&self, ast_id: u64) -> Option<&Buffer>

Get a buffer by AST id (for reading intermediate results).

Source

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).

Source

pub fn device(&self) -> &DeviceSpec

Get the primary device for this plan.

Source

pub fn buffers(&self) -> &[Buffer]

Get all buffers owned by this plan.

Source

pub fn buffers_mut(&mut self) -> &mut [Buffer]

Get mutable access to all buffers owned by this plan.

Source

pub fn buffer_at_mut(&mut self, index: usize) -> Option<&mut Buffer>

Get a mutable buffer by its index in the buffers array.

Source

pub fn prepared_kernels(&self) -> Vec<&PreparedKernel>

Get all prepared kernels.

Source

pub fn prepared_ops(&self) -> &[PreparedOp]

Get all prepared operations in schedule order.

Source

pub fn kernels(&self) -> impl Iterator<Item = &CachedKernel>

Iterate over compiled kernels (for inspecting generated source code).

Source

pub fn execute(&self) -> Result<()>

Execute the plan.

Uses dependency-aware operation ordering for all prepared op types.

Source

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);
}
Source

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.

Source

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.

Source

pub fn output_buffer_idx(&self) -> usize

Get the first output buffer index.

Source

pub fn ast_to_buffer_map(&self) -> &HashMap<u64, usize>

Get the AST ID to buffer index mapping.

Source

pub fn release_intermediate_buffers<F>(&self, remove_fn: F)
where F: Fn(u64),

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.

Source

pub fn release_all_buffers<F>(&self, remove_fn: F)
where F: Fn(u64),

Release ALL buffers from the global registry, including the output.

Trait Implementations§

Source§

impl Debug for ExecutionPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more