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
impl ErasedFusedPlan
Sourcepub fn compile(
dtype: KernelDType,
plan: FusedPlan,
) -> Result<ErasedFusedPlan, StridedError>
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.
pub fn dtype(&self) -> KernelDType
pub fn plan(&self) -> &FusedPlan
Sourcepub fn execute(
&self,
dest: &mut ErasedRawStridedMut<'_>,
inputs: &[ErasedRawStridedRef<'_>],
exec: Exec<'_>,
) -> Result<(), StridedError>
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.
Sourcepub fn execute_outputs(
&self,
dests: &mut [ErasedRawStridedMut<'_>],
inputs: &[ErasedRawStridedRef<'_>],
exec: Exec<'_>,
) -> Result<(), StridedError>
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]);Sourcepub fn execute_uninit(
&self,
dest: &mut ErasedRawStridedUninitMut<'_>,
inputs: &[ErasedRawStridedPtr<'_>],
exec: Exec<'_>,
) -> Result<(), StridedError>
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.
Sourcepub fn execute_outputs_uninit(
&self,
dests: &mut [ErasedRawStridedUninitMut<'_>],
inputs: &[ErasedRawStridedPtr<'_>],
exec: Exec<'_>,
) -> Result<(), StridedError>
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
impl Clone for ErasedFusedPlan
Source§fn clone(&self) -> ErasedFusedPlan
fn clone(&self) -> ErasedFusedPlan
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ErasedFusedPlan
impl RefUnwindSafe for ErasedFusedPlan
impl Send for ErasedFusedPlan
impl Sync for ErasedFusedPlan
impl Unpin for ErasedFusedPlan
impl UnsafeUnpin for ErasedFusedPlan
impl UnwindSafe for ErasedFusedPlan
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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