Trait FusionRuntime
pub trait FusionRuntime:
Sized
+ Send
+ Sync
+ Debug
+ 'static {
type OptimizationState: Serialize + DeserializeOwned;
type Optimization: Optimization<Self>;
type FusionHandle: Clone + Send;
type FusionDevice: DeviceOps;
// Required method
fn fusers(
device: Self::FusionDevice,
) -> Vec<Box<dyn OperationFuser<Self::Optimization>>>;
// Provided methods
fn alias_handle(handle: &Self::FusionHandle) -> Self::FusionHandle { ... }
fn free_handle(
handles: &mut HandleContainer<Self::FusionHandle>,
tensor: &TensorIr,
ran: OperationRan,
) { ... }
}Expand description
Trait that defines a runtime that will benefits from fused operations.
Required Associated Types§
type OptimizationState: Serialize + DeserializeOwned
type OptimizationState: Serialize + DeserializeOwned
The state that can be serialized for an optimization.
type Optimization: Optimization<Self>
type Optimization: Optimization<Self>
Optimization type for the backend.
type FusionHandle: Clone + Send
type FusionHandle: Clone + Send
Handle used to store tensor dynamically.
type FusionDevice: DeviceOps
type FusionDevice: DeviceOps
Device used by the runtime.
Required Methods§
fn fusers(
device: Self::FusionDevice,
) -> Vec<Box<dyn OperationFuser<Self::Optimization>>>
fn fusers( device: Self::FusionDevice, ) -> Vec<Box<dyn OperationFuser<Self::Optimization>>>
The list of fusers that will be used to optimize the computational graph.
Provided Methods§
fn alias_handle(handle: &Self::FusionHandle) -> Self::FusionHandle
fn alias_handle(handle: &Self::FusionHandle) -> Self::FusionHandle
Create a cross-stream alias of handle to register under a fresh tensor id.
Called by MultiStream::tag_shared_view when
a tensor is shared from one stream to another. The new handle must be an independent
container entry over the same backing buffer, so that consuming one alias (a ReadWrite
last-use that frees its handle) never frees the buffer out from under the other stream.
The default just clones the handle, which is exactly right for local backends whose handle
is an Arc-style refcount over a device buffer — the clone is a new map entry sharing the
allocation. Backends whose handle is a remote resource (the router/remote backend, where
the handle is a thin id pointing at a server-side tensor) must override this: a bare clone
keeps the same server id, so all aliases collapse to one server handle and the first consume
frees it for everyone. Such backends allocate a fresh server id aliasing the same buffer.
fn free_handle(
handles: &mut HandleContainer<Self::FusionHandle>,
tensor: &TensorIr,
ran: OperationRan,
)
fn free_handle( handles: &mut HandleContainer<Self::FusionHandle>, tensor: &TensorIr, ran: OperationRan, )
Reclaim a ReadWrite (last-use) handle as the fusion engine drains a block.
The default removes the container entry; the handle’s own Drop releases the backend
resource. This is correct for local backends, whose handle is an Arc-style buffer refcount.
A runtime whose handle is a remote resource must override this. The router/remote backend
frees a tensor by registering an OperationIr::Drop, but a block that ran already freed
it server-side — a replayed op (including any Drop) pops its ReadWrite inputs there. So
letting the handle’s Drop run registers a second, redundant Drop for the same id (the
“unfused drop” traffic), and the override suppresses that re-registration.
ran is what says whether that holds for this operation: a block is drained whether or
not its operations ran, and one that did not was never replayed, so the server still holds
its inputs and only the handle’s own Drop will free them.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".