Skip to main content

SIMDSchema

Trait SIMDSchema 

Source
pub trait SIMDSchema<T, U, A: Architecture = Current>: Copy {
    type SIMDWidth: Constant<Type = usize>;
    type Accumulator: Add<Output = Self::Accumulator> + Debug + Copy;
    type Left: SIMDVector<Arch = A, Scalar = T, ConstLanes = Self::SIMDWidth>;
    type Right: SIMDVector<Arch = A, Scalar = U, ConstLanes = Self::SIMDWidth>;
    type Return;
    type Main: MainLoop;

    // Required methods
    fn init(&self, arch: A) -> Self::Accumulator;
    fn accumulate(
        &self,
        x: Self::Left,
        y: Self::Right,
        acc: Self::Accumulator,
    ) -> Self::Accumulator;
    fn reduce(&self, x: Self::Accumulator) -> Self::Return;

    // Provided methods
    fn combine(
        &self,
        x: Self::Accumulator,
        y: Self::Accumulator,
    ) -> Self::Accumulator { ... }
    unsafe fn epilogue(
        &self,
        arch: A,
        x: *const T,
        y: *const U,
        len: usize,
        acc: Self::Accumulator,
    ) -> Self::Accumulator { ... }
    fn get_simd_width() -> usize { ... }
    fn get_main_bocksize() -> usize { ... }
}
Expand description

An interface trait for SIMD operations.

Patterns like unrolling, pointer arithmetic, and epilogue handling are common across many different combinations of left and right hand types for distance computations.

This higher level handling is delegated to functions like simd_op, which in turn uses a SIMDSchema to customize the mechanics of loading and accumulation.

Required Associated Types§

Source

type SIMDWidth: Constant<Type = usize>

The desired SIMD read width. Reads from the input slice will be use this stride when accessing memory.

Source

type Accumulator: Add<Output = Self::Accumulator> + Debug + Copy

The type used to represent partial accumulated values.

Source

type Left: SIMDVector<Arch = A, Scalar = T, ConstLanes = Self::SIMDWidth>

The type used for the left-hand side.

Source

type Right: SIMDVector<Arch = A, Scalar = U, ConstLanes = Self::SIMDWidth>

The type used for the right-hand side.

Source

type Return

The final return type. This is often f32 for complete distance functions, but need not always be.

Source

type Main: MainLoop

The implementation of the main loop.

Required Methods§

Source

fn init(&self, arch: A) -> Self::Accumulator

Initialize an empty (identity) accumulator.

Source

fn accumulate( &self, x: Self::Left, y: Self::Right, acc: Self::Accumulator, ) -> Self::Accumulator

Perform an accumulation.

Source

fn reduce(&self, x: Self::Accumulator) -> Self::Return

Perform a reduction on the accumulator to yield the final result.

This will be called at the end of distance processing.

Provided Methods§

Source

fn combine( &self, x: Self::Accumulator, y: Self::Accumulator, ) -> Self::Accumulator

Combine two independent accumulators (allows for unrolling).

Source

unsafe fn epilogue( &self, arch: A, x: *const T, y: *const U, len: usize, acc: Self::Accumulator, ) -> Self::Accumulator

A supplied trait for dealing with non-full-width epilogues. Often, masked based loading will do the right thing, but for architectures like AVX2 that have limited support for masking 8 and 16-bit operations, using a scalar fallback may just be better.

This provides a customization point to enable a scalar fallback.

§Safety
  • Both pointers x and y must point to memory.
  • It must be safe to read len contiguous items of type T starting at x and len contiguous items of type U starting at y.

The following guarantee is made:

  • No read will be emitted to memory locations at and after x.add(len) and y.add(len).
Source

fn get_simd_width() -> usize

!! Do not extend this function !!

Due to limitations on how associated constants can be used, we need a function to access the SIMD width and rely on the compiler to constant propagate the result.

Source

fn get_main_bocksize() -> usize

!! Do not extend this function !!

Due to limitations on how associated constants can be used, we need a function to access the unroll factor of the main loop and rely on the compiler to constant propagate the result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl SIMDSchema<f32, f32> for CosineStateless

Source§

impl SIMDSchema<f32, f32> for IP

Source§

impl SIMDSchema<f32, f32> for L1Norm

Source§

impl SIMDSchema<f32, f32> for L2

Source§

impl SIMDSchema<f32, f32, V3> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V3> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V3> for L1Norm

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V3> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V4> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V4> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V4> for L1Norm

Available on x86-64 only.
Source§

impl SIMDSchema<f32, f32, V4> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8> for CosineStateless

Source§

impl SIMDSchema<i8, i8> for IP

Source§

impl SIMDSchema<i8, i8> for L2

Source§

impl SIMDSchema<i8, i8, V3> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8, V3> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8, V3> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8, V4> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8, V4> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<i8, i8, V4> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8> for CosineStateless

Source§

impl SIMDSchema<u8, u8> for IP

Source§

impl SIMDSchema<u8, u8> for L2

Source§

impl SIMDSchema<u8, u8, V3> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8, V3> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8, V3> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8, V4> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8, V4> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<u8, u8, V4> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16> for CosineStateless

Source§

impl SIMDSchema<f16, f16> for IP

Source§

impl SIMDSchema<f16, f16> for L1Norm

Source§

impl SIMDSchema<f16, f16> for L2

Source§

impl SIMDSchema<f16, f16, V3> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V3> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V3> for L1Norm

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V3> for L2

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V4> for CosineStateless

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V4> for IP

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V4> for L1Norm

Available on x86-64 only.
Source§

impl SIMDSchema<f16, f16, V4> for L2

Available on x86-64 only.
Source§

impl<A> SIMDSchema<f32, f16, A> for CosineStateless
where A: Architecture,

Source§

impl<A> SIMDSchema<f32, f16, A> for IP
where A: Architecture,

Source§

impl<A> SIMDSchema<f32, f16, A> for L2
where A: Architecture,

Source§

impl<T, U, R, A> SIMDSchema<T, U, A> for Resumable<R>
where A: Architecture, R: ResumableSIMDSchema<T, U, A>,

Source§

type SIMDWidth = <<R as ResumableSIMDSchema<T, U, A>>::NonResumable as SIMDSchema<T, U, A>>::SIMDWidth

Source§

type Accumulator = <<R as ResumableSIMDSchema<T, U, A>>::NonResumable as SIMDSchema<T, U, A>>::Accumulator

Source§

type Left = <<R as ResumableSIMDSchema<T, U, A>>::NonResumable as SIMDSchema<T, U, A>>::Left

Source§

type Right = <<R as ResumableSIMDSchema<T, U, A>>::NonResumable as SIMDSchema<T, U, A>>::Right

Source§

type Return = Resumable<R>

Source§

type Main = <<R as ResumableSIMDSchema<T, U, A>>::NonResumable as SIMDSchema<T, U, A>>::Main