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
impl UnifiedExecutor
Sourcepub fn new(registry: &'static DeviceRegistry) -> Self
pub fn new(registry: &'static DeviceRegistry) -> Self
Create a new unified executor.
Sourcepub fn add_device(&mut self, device_spec: DeviceSpec) -> Result<()>
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.
Sourcepub fn context(&self, device: &DeviceSpec) -> Option<&DeviceContext>
pub fn context(&self, device: &DeviceSpec) -> Option<&DeviceContext>
Get the device context for a device specification.
Sourcepub fn context_mut(&mut self, device: &DeviceSpec) -> Option<&mut DeviceContext>
pub fn context_mut(&mut self, device: &DeviceSpec) -> Option<&mut DeviceContext>
Get the device context mutably.
Sourcepub fn sync_strategy(from: &DeviceSpec, to: &DeviceSpec) -> SyncStrategy
pub fn sync_strategy(from: &DeviceSpec, to: &DeviceSpec) -> SyncStrategy
Determine the synchronization strategy between two devices.
Sourcepub fn single_device_check(&self, buffers: &[&Buffer]) -> Option<DeviceSpec>
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.
Sourcepub fn synchronize_all(&self) -> Result<()>
pub fn synchronize_all(&self) -> Result<()>
Synchronize all devices.
Waits for all pending operations to complete on all devices.
Sourcepub fn execute_kernel<F>(
&mut self,
device: &DeviceSpec,
execute_fn: F,
) -> Result<u64>
pub fn execute_kernel<F>( &mut self, device: &DeviceSpec, execute_fn: F, ) -> Result<u64>
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 onexecute_fn- Function that performs the actual kernel execution
§Returns
The timeline value for this execution (can be used for cross-device sync).
Sourcepub fn execute_transfer(
&mut self,
src: &Buffer,
dst: &mut Buffer,
src_device: &DeviceSpec,
dst_device: &DeviceSpec,
) -> Result<u64>
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 bufferdst- Destination buffer (must be pre-allocated)src_device- Device the source buffer is ondst_device- Device the destination buffer is on
§Returns
The timeline value for this transfer operation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UnifiedExecutor
impl !RefUnwindSafe for UnifiedExecutor
impl Send for UnifiedExecutor
impl Sync for UnifiedExecutor
impl Unpin for UnifiedExecutor
impl UnsafeUnpin for UnifiedExecutor
impl !UnwindSafe for UnifiedExecutor
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