Skip to main content

UnifiedExecutor

Struct UnifiedExecutor 

Source
pub struct UnifiedExecutor { /* private fields */ }
Expand description

Unified executor for heterogeneous device execution.

Manages device contexts to enable parallel execution across any mix of devices. Uses timeline signals for cross-device synchronization.

§Stateless Execution Model (Tinygrad-Aligned)

The executor follows Tinygrad’s stateless execution model where:

  • Dependencies are computed at schedule time, not runtime
  • ExecutionPlan pre-computes kernel order via topological sort
  • No runtime dependency tracking is needed (zero memory accumulation)
  • Timeline signals handle cross-device synchronization only

Implementations§

Source§

impl UnifiedExecutor

Source

pub fn new(registry: &'static DeviceRegistry) -> Self

Create a new unified executor.

Source

pub fn add_device(&mut self, device_spec: DeviceSpec) -> Result<()>

Add a device to the executor.

Creates the device context with timeline signal and queues.

Source

pub fn context(&self, device: &DeviceSpec) -> Option<&DeviceContext>

Get the device context for a device specification.

Source

pub fn context_mut(&mut self, device: &DeviceSpec) -> Option<&mut DeviceContext>

Get the device context mutably.

Source

pub fn sync_strategy(from: &DeviceSpec, to: &DeviceSpec) -> SyncStrategy

Determine the synchronization strategy between two devices.

Source

pub fn single_device_check(&self, buffers: &[&Buffer]) -> Option<DeviceSpec>

Check if all operations on a single device.

Returns Some(device) if all buffers are on the same device, enabling the fast single-device path.

Source

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

Synchronize all devices.

Waits for all pending operations to complete on all devices.

Source

pub fn execute_kernel<F>( &mut self, device: &DeviceSpec, execute_fn: F, ) -> Result<u64>
where F: FnOnce() -> Result<()>,

Execute a kernel (sequential execution).

ExecutionPlan pre-computes kernel order at schedule time, so no runtime dependency tracking is needed. This follows Tinygrad’s stateless execution model.

§Arguments
  • device - Device to execute on
  • execute_fn - Function that performs the actual kernel execution
§Returns

The timeline value for this execution (can be used for cross-device sync).

Source

pub fn execute_transfer( &mut self, src: &Buffer, dst: &mut Buffer, src_device: &DeviceSpec, dst_device: &DeviceSpec, ) -> Result<u64>

Execute a buffer transfer (COPY operation).

Handles cross-device transfers with appropriate synchronization:

  • Same device: Direct copy using device’s copy queue
  • Same vendor (e.g., CUDA:0 → CUDA:1): Peer-to-peer transfer
  • Different vendors (e.g., CUDA → CPU): Stage through host memory
§Arguments
  • src - Source buffer
  • dst - Destination buffer (must be pre-allocated)
  • src_device - Device the source buffer is on
  • dst_device - Device the destination buffer is on
§Returns

The timeline value for this transfer operation.

Trait Implementations§

Source§

impl Debug for UnifiedExecutor

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