pub struct CopyPlan { /* private fields */ }Expand description
A compiled copy traversal for one (dims, dst_strides, src_strides)
layout pair.
compile proves the layout facts once (rank agreement, extent overflow,
destination injectivity) and fuses/orders the loop nest; each execute*
call then only re-checks the per-call facts (that the supplied views carry
exactly the compiled layout) and selects the cache blocks for its element
type before replaying the prepared loops. The order in which elements are
visited is unspecified.
Overlapping src/dest memory is not supported, matching the rest of the
crate.
Ranks above RAW_FUSED_RANK_LIMIT are supported by the same fused
traversal, which then stores its axes in one rank-bounded allocation.
§Example
use strided_basic::{CopyPlan, Exec, RawStridedMut, RawStridedRef};
let dims = [2usize, 3];
let src_strides = [3isize, 1];
let dst_strides = [1isize, 2]; // transposed destination
let plan = CopyPlan::compile(&dims, &dst_strides, &src_strides).unwrap();
let src = [0.0f64, 1.0, 2.0, 10.0, 11.0, 12.0];
let mut dst = [0.0f64; 6];
let src_ref = RawStridedRef::new(&src, &dims, &src_strides, 0).unwrap();
let mut dst_mut = RawStridedMut::new(&mut dst, &dims, &dst_strides, 0).unwrap();
plan.execute(&mut dst_mut, &src_ref, Exec::serial()).unwrap();
assert_eq!(dst, [0.0, 10.0, 1.0, 11.0, 2.0, 12.0]);Implementations§
Source§impl CopyPlan
impl CopyPlan
Sourcepub fn compile(
dims: &[usize],
dst_strides: &[isize],
src_strides: &[isize],
) -> Result<Self>
pub fn compile( dims: &[usize], dst_strides: &[isize], src_strides: &[isize], ) -> Result<Self>
Compile a copy plan for the given layout pair.
Performs the layout validation and traversal construction (fuse + order) once.
§Errors
Returns StridedError::StrideLengthMismatch when dims,
dst_strides, and src_strides do not all have the same length,
StridedError::OffsetOverflow when the total element count does not
fit usize, and StridedError::NonInjectiveOutputLayout when the
destination layout cannot be proven injective (aliasing elements, or a
span the check cannot represent).
Sourcepub fn serial_cost<T>(&self) -> Duration
pub fn serial_cost<T>(&self) -> Duration
Serial time one replay of this plan is estimated at on this host, for
operands of T.
The rate is the one the plan’s own width decision uses: the Copy row,
plus the per-run cache-line term of its walk, plus the beyond-L2 term when
the working set does not fit the class’s L2 cache (strided-rs#364). The
element type is a parameter because compile stores only the layout; the
working set in bytes, and so the cache level that selects the rate, needs
size_of::<T>().
A caller that composes many plans under its own outer split can compare
this duration with Exec’s dispatch cost without restating the model, so
the two decisions stay consistent (strided-rs#363).
§Examples
use strided_basic::CopyPlan;
let plan = CopyPlan::compile(&[2, 3], &[1, 2], &[3, 1]).unwrap();
let cost: core::time::Duration = plan.serial_cost::<f64>();
assert!(cost > core::time::Duration::ZERO);Sourcepub fn execute_uninit<T>(
&self,
dest: &mut RawStridedMut<'_, MaybeUninit<T>>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_uninit<T>( &self, dest: &mut RawStridedMut<'_, MaybeUninit<T>>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = src into a potentially uninitialized destination.
On success every reachable logical destination element is initialized. Non-reachable holes in the backing allocation are not written.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = src. Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute_scale<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
scale: T,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_scale<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, scale: T, exec: Exec<'_>, ) -> Result<()>
dest = scale * src. Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute_conj<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_conj<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = conj(src). Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CopyPlan
impl RefUnwindSafe for CopyPlan
impl Send for CopyPlan
impl Sync for CopyPlan
impl Unpin for CopyPlan
impl UnsafeUnpin for CopyPlan
impl UnwindSafe for CopyPlan
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