Skip to main content

ErasedFusedPlan

Struct ErasedFusedPlan 

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

Dtype-erased wrapper around FusedPlan.

This is the erased replay boundary for unary map and zip-map elementwise families. It supports the same runtime op-code vocabulary as FusedPlan, but only for the scalar dtypes currently implementing FusedScalar. A plan may name one or more outputs; ErasedFusedPlan::execute_outputs and ErasedFusedPlan::execute_outputs_uninit write them all in one replay.

Implementations§

Source§

impl ErasedFusedPlan

Source

pub fn compile( dtype: KernelDType, plan: FusedPlan, ) -> Result<ErasedFusedPlan, StridedError>

Validate and store a fused elementwise plan for one dtype.

The plan must name at least one output; repeated output value ids are allowed and write the same value to each named destination.

§Errors

Returns an unsupported dtype, an input arity outside 1..=4, a zero-output plan, a malformed SSA DAG, or an operation the dtype does not support.

Source

pub fn dtype(&self) -> KernelDType

Source

pub fn plan(&self) -> &FusedPlan

Source

pub fn execute( &self, dest: &mut ErasedRawStridedMut<'_>, inputs: &[ErasedRawStridedRef<'_>], exec: Exec<'_>, ) -> Result<(), StridedError>

Execute a single-output fused elementwise plan through erased descriptors.

Forwarding front end for Self::execute_outputs; the plan must name exactly one output.

§Errors

Returns a typed dtype, input-count, shape, destination injectivity, or unsupported-operation error before any destination is written.

Source

pub fn execute_outputs( &self, dests: &mut [ErasedRawStridedMut<'_>], inputs: &[ErasedRawStridedRef<'_>], exec: Exec<'_>, ) -> Result<(), StridedError>

Execute a plan into one or more destinations in a single replay.

plan.outputs are written to dests in order. Every destination is validated before any write: dtype, shape against the inputs, and output injectivity. Overlapping initialized input/output memory is not supported; the mutable destination slices are exclusive, so only destination-versus-input overlap is a caller concern.

§Errors

Returns a typed dtype, input-count, destination-count, shape, destination injectivity, or unsupported-operation error before any destination is written.

§Examples
use strided_basic::{
    ErasedRawStridedMut, ErasedRawStridedRef, Exec, KernelDType,
};
use strided_fused::{ErasedFusedPlan, FusedInst, FusedOp, FusedPlan};

let plan = ErasedFusedPlan::compile(
    KernelDType::F64,
    FusedPlan::new(
        1,
        vec![0, 1],
        vec![FusedInst::new(FusedOp::Negate, vec![0])],
    ),
)
.unwrap();
let input = [1.0_f64, -2.0];
let dims = [2];
let strides = [1];
let inputs = [ErasedRawStridedRef::from_slice(&input, &dims, &strides, 0).unwrap()];
let mut pass_through = [0.0_f64; 2];
let mut negated = [0.0_f64; 2];
{
    let mut dests = [
        ErasedRawStridedMut::from_slice_mut(&mut pass_through, &dims, &strides, 0).unwrap(),
        ErasedRawStridedMut::from_slice_mut(&mut negated, &dims, &strides, 0).unwrap(),
    ];
    plan.execute_outputs(&mut dests, &inputs, Exec::serial())
        .unwrap();
}
assert_eq!(pass_through, [1.0, -2.0]);
assert_eq!(negated, [-1.0, 2.0]);
Source

pub fn execute_uninit( &self, dest: &mut ErasedRawStridedUninitMut<'_>, inputs: &[ErasedRawStridedPtr<'_>], exec: Exec<'_>, ) -> Result<(), StridedError>

Execute a single-output fused plan into fully overwritten uninitialized storage.

Forwarding front end for Self::execute_outputs_uninit; the plan must name exactly one output.

§Errors

Returns a typed dtype, input-count, shape, bounds, destination injectivity, unsupported-operation, or input/output-overlap error before any destination is written.

Source

pub fn execute_outputs_uninit( &self, dests: &mut [ErasedRawStridedUninitMut<'_>], inputs: &[ErasedRawStridedPtr<'_>], exec: Exec<'_>, ) -> Result<(), StridedError>

Execute a plan into one or more fully overwritten uninitialized destinations in a single replay.

Dtype, shape, destination injectivity, bounds, and input/output overlap are validated for every destination before any shared typed input descriptor is formed or any destination byte is written. On Ok(()), every logical destination element is initialized. An error leaves every destination untouched; a panic during execution may leave partial initialization, but the backing MaybeUninit storage remains safe to drop.

§Errors

Returns a typed dtype, input-count, destination-count, shape, bounds, destination injectivity, unsupported-operation, or input/output-overlap error. All error-producing validation completes before execution starts.

§Examples
use core::mem::MaybeUninit;
use strided_basic::{
    ErasedRawStridedPtr, ErasedRawStridedRef, ErasedRawStridedUninitMut,
    Exec, KernelDType,
};
use strided_fused::{ErasedFusedPlan, FusedInst, FusedOp, FusedPlan};

let plan = ErasedFusedPlan::compile(
    KernelDType::F32,
    FusedPlan::new(
        1,
        vec![0, 1],
        vec![FusedInst::new(FusedOp::Negate, vec![0])],
    ),
)
.unwrap();
let input = [1.0_f32, -2.0];
let dims = [2];
let strides = [1];
let input = ErasedRawStridedRef::from_slice(&input, &dims, &strides, 0).unwrap();
let pointers = [ErasedRawStridedPtr::from_ref(&input)];
let mut pass_through = [MaybeUninit::<f32>::uninit(); 2];
let mut negated = [MaybeUninit::<f32>::uninit(); 2];
{
    let mut dests = [
        ErasedRawStridedUninitMut::from_uninit_slice(
            &mut pass_through,
            &dims,
            &strides,
            0,
        )
        .unwrap(),
        ErasedRawStridedUninitMut::from_uninit_slice(&mut negated, &dims, &strides, 0).unwrap(),
    ];
    plan.execute_outputs_uninit(&mut dests, &pointers, Exec::serial())
        .unwrap();
}
// SAFETY: `execute_outputs_uninit` overwrites every reachable element.
assert_eq!(unsafe { pass_through[1].assume_init() }, -2.0);
// SAFETY: as above.
assert_eq!(unsafe { negated[1].assume_init() }, 2.0);

Trait Implementations§

Source§

impl Clone for ErasedFusedPlan

Source§

fn clone(&self) -> ErasedFusedPlan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ErasedFusedPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.