Derive Macro ExtensionType
#[derive(ExtensionType)]
{
// Attributes available to this derive:
#[extension_type]
}
Expand description
Maps structs and enums of backend tensor primitives across the Dispatch boundary.
Opt into #[extension_type(fusion)] (optionally fusion: cfg(...)) to support Fusion inputs
and outputs and generate a backend-independent NameMetadata type. It mirrors the struct’s
fields or enum’s variants, replacing tensors with TensorSpec and nested extension values with
their metadata. Ordinary fields are cloned and must implement Clone + Debug;
ordinary input fields must also be Send + Sync + 'static.
The metadata callback chooses the output variant and supplies the actual return values for non-tensor fields. Fusion returns those values without waiting for execution and ignores the backend’s later values for those fields. The callback must calculate what a direct backend call would return; otherwise enabling Fusion changes the result. Generated code does not check these field values. Empty variants are supported, but each operation still needs an input tensor for its device.
Tensor fields are mapped automatically. Nested extension values must be marked with
#[extension_type]; other fields pass through unchanged.
#[derive(ExtensionType)]
pub struct Inputs<B: Backend> {
pub lhs: FloatTensor<B>,
pub rhs: FloatTensor<B>,
}