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) before replaying the prepared loops.
Overlapping src/dest memory is not supported, matching the rest of the
crate.
Ranks above RAW_FUSED_RANK_LIMIT are supported through the view-based
kernels; only that fallback path may allocate.
§Example
use strided_kernel::{CopyPlan, 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).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<CopyPlan, StridedError>
pub fn compile( dims: &[usize], dst_strides: &[isize], src_strides: &[isize], ) -> Result<CopyPlan, StridedError>
Compile a copy plan for the given layout pair.
Performs the layout validation and traversal construction (fuse + order) once:
dims,dst_strides, andsrc_stridesmust have equal length (StridedError::StrideLengthMismatch);- the total element count must not overflow
usize(StridedError::OffsetOverflow); - the destination layout must be injective, i.e. map distinct logical
indices to distinct offsets
(
StridedError::NonInjectiveOutputLayout).
Sourcepub fn execute<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
) -> Result<(), StridedError>where
T: Copy + MaybeSendSync,
pub fn execute<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
) -> Result<(), StridedError>where
T: Copy + MaybeSendSync,
dest = src. Allocation-free for ranks at most RAW_FUSED_RANK_LIMIT.
Sourcepub fn execute_scale<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
scale: T,
) -> Result<(), StridedError>
pub fn execute_scale<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, scale: T, ) -> Result<(), StridedError>
dest = scale * src. Allocation-free for ranks at most
RAW_FUSED_RANK_LIMIT.
Sourcepub fn execute_conj<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
) -> Result<(), StridedError>
pub fn execute_conj<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, ) -> Result<(), StridedError>
dest = conj(src). Allocation-free for ranks at most
RAW_FUSED_RANK_LIMIT.
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