Skip to main content

LayerwisePolicy

Trait LayerwisePolicy 

Source
pub trait LayerwisePolicy<B, U>
where B: NeuralBackend,
{ type Lease: DerefMut<Target = U>; type Error; // Required methods fn begin( &mut self, initial: &B::Tensor, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error>; fn acquire<E, F>( &mut self, ordinal: usize, address: ExecutionUnitAddress, build: F, context: &<B::Tensor as Tensor>::Context, ) -> Result<Self::Lease, LayerwiseAcquireError<E, Self::Error>> where F: FnOnce(&<B::Tensor as Tensor>::Context) -> Result<U, E>; fn complete<'a, StateValues, ContextValues>( &mut self, ordinal: usize, address: ExecutionUnitAddress, lease: Self::Lease, output: &'a B::Tensor, state_values: StateValues, context_values: ContextValues, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error> where B::Tensor: 'a, StateValues: Iterator<Item = &'a B::Tensor>, ContextValues: Iterator<Item = &'a B::Tensor>; fn finish( &mut self, output: &B::Tensor, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error>; // Provided method fn abort( &mut self, active: Option<(usize, ExecutionUnitAddress, Self::Lease)>, _context: &<B::Tensor as Tensor>::Context, ) { ... } }
Expand description

Policy controlling acquisition and exact release of one execution unit.

Required Associated Types§

Source

type Lease: DerefMut<Target = U>

Concrete lease owning one populated unit and all residency guards.

Source

type Error

Concrete acquisition or completion failure.

Required Methods§

Source

fn begin( &mut self, initial: &B::Tensor, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error>

Starts one forward after architecture input preparation.

Source

fn acquire<E, F>( &mut self, ordinal: usize, address: ExecutionUnitAddress, build: F, context: &<B::Tensor as Tensor>::Context, ) -> Result<Self::Lease, LayerwiseAcquireError<E, Self::Error>>
where F: FnOnce(&<B::Tensor as Tensor>::Context) -> Result<U, E>,

Acquires one populated unit for exclusive execution.

The flat ordinal addresses storage while address preserves the architecture execution group and group-local unit index for scheduling.

Source

fn complete<'a, StateValues, ContextValues>( &mut self, ordinal: usize, address: ExecutionUnitAddress, lease: Self::Lease, output: &'a B::Tensor, state_values: StateValues, context_values: ContextValues, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error>
where B::Tensor: 'a, StateValues: Iterator<Item = &'a B::Tensor>, ContextValues: Iterator<Item = &'a B::Tensor>,

Retains the unit and dependent native values through exact completion.

Source

fn finish( &mut self, output: &B::Tensor, context: &<B::Tensor as Tensor>::Context, ) -> Result<(), Self::Error>

Completes the final output and releases any remaining unit guards.

Provided Methods§

Source

fn abort( &mut self, active: Option<(usize, ExecutionUnitAddress, Self::Lease)>, _context: &<B::Tensor as Tensor>::Context, )

Aborts an incomplete forward and releases all policy-owned state.

active contains the unit lease when execution stopped after acquisition but before exact completion. Implementations with no forward-scoped state may rely on the default, which simply drops it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§