Skip to main content

ErasedReducePlan

Struct ErasedReducePlan 

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

Dtype-erased reduction wrapper.

This is the erased replay boundary for full-tensor scalar reductions and axis reductions with a fixed output layout. It supports only operations with an unambiguous identity value in the selected dtype.

§Evaluation order

The op is matched once per execution; every loop runs a kernel specialized for one (dtype, op) pair. Integer results are exact (wrapping) and ReduceOp::Max / ReduceOp::Min do not depend on order, so the rules below only affect the rounding of floating point and complex ReduceOp::Sum, ReduceOp::Product and ReduceOp::SumSquares. Two details of float max and min follow the visit order: a NaN input makes the result NaN, but which NaN (payload and sign) is returned is unspecified, and when the extremum is a zero its sign is unspecified if both +0.0 and -0.0 occur.

  • Full reductions (from Self::compile, or Self::compile_axes with every axis reduced) visit the source in a layout derived order: extent one axes are dropped, the rest are ordered by increasing absolute stride and contiguous axes are fused into runs. Each run is reduced by the SIMD kernel (unit stride, simd feature), a sixteen lane kernel (other unit stride runs) or an eight lane kernel (strided runs), and runs are combined left to right. A dense column major source therefore reduces exactly like one contiguous slice.
  • With a parallel context and more than MINTHREADLENGTH elements, a full reduction splits the traversal into one deterministic range per worker thread. Each range runs the same run kernel as the serial path and the partials are combined in a fixed tree. The result is bitwise repeatable for a fixed layout and thread count, but may differ between thread counts and from the serial result.
  • Axis reductions with kept axes compute every output independently, so the result never depends on the context or thread count. Each output folds its reduced elements sequentially in caller reduced axis order, except that a unit stride leading reduced run (after fusing adjacent reduced axes) of length at least 16 is reduced by the contiguous run kernel, with runs folded in order. When instead the leading kept axis has unit stride, adjacent outputs are accumulated as a block from one contiguous source run per reduced element; each output still folds in caller reduced axis order.

Implementations§

Source§

impl ErasedReducePlan

Source

pub fn compile( dtype: KernelDType, op: ReduceOp, dims: &[usize], src_strides: &[isize], ) -> Result<Self>

Validate and store a full-reduction plan for one dtype and source layout.

Source

pub fn compile_axes( dtype: KernelDType, op: ReduceOp, src_dims: &[usize], src_strides: &[isize], dest_dims: &[usize], dest_strides: &[isize], axes: &[usize], ) -> Result<Self>

Validate and store an axis-reduction plan for one dtype and fixed source/output layouts.

axes names the source axes reduced away. Output dimensions must be the remaining source dimensions in source-axis order. When all axes are reduced, any output layout with exactly one reachable element is accepted.

Source

pub fn dtype(&self) -> KernelDType

Source

pub fn op(&self) -> ReduceOp

Source

pub fn execute( &self, ctx: &ExecContext, dest: &mut ErasedRawStridedMut<'_>, src: &ErasedRawStridedRef<'_>, ) -> Result<()>

Execute the reduction into an erased output descriptor.

Source

pub fn execute_uninit( &self, ctx: &ExecContext, dest: &mut ErasedRawStridedUninitMut<'_>, src: &ErasedRawStridedPtr<'_>, ) -> Result<()>

On success, every reachable destination slot is fully overwritten; unreachable holes are neither read nor initialized. Validation errors are returned before any destination write. A panic during execution may leave a partially initialized MaybeUninit destination, which is still safely droppable; no readable value is promised for unwritten reachable slots.

Trait Implementations§

Source§

impl Clone for ErasedReducePlan

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 ErasedReducePlan

Source§

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

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> MaybeSend for T

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> MaybeSync for 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 = !

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.