Skip to main content

CopyPlan

Struct CopyPlan 

Source
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

Source

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).

Source

pub fn execute_uninit<T>( &self, dest: &mut RawStridedMut<'_, MaybeUninit<T>>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
where T: Copy + Send + Sync,

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.

Source

pub fn execute<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
where T: Copy + Send + Sync,

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.

Source

pub fn execute_scale<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, scale: T, exec: Exec<'_>, ) -> Result<()>
where T: Copy + Mul<T, Output = T> + Send + Sync,

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.

Source

pub fn execute_conj<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
where T: Copy + ElementOpApply + Send + Sync,

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§

Source§

impl Clone for CopyPlan

Source§

fn clone(&self) -> Self

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 CopyPlan

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CopyPlan

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.