Skip to main content

MainLoop

Trait MainLoop 

Source
pub trait MainLoop {
    const BLOCK_SIZE: usize;

    // Required method
    unsafe fn main<S, L, R, A>(
        loader: &Loader<S, L, R, A>,
        trip_count: usize,
        epilogues: usize,
    ) -> S::Accumulator
       where A: Architecture,
             S: SIMDSchema<L, R, A>;
}
Expand description

A representation of the main unrolled-loop for SIMD kernels.

Required Associated Constants§

Source

const BLOCK_SIZE: usize

The effective number of unrolling (in terms of SIMD vectors) performed by this kernel. For example, if BLOCK_SIZE = 4 and the SIMD width is 8, than each iteration of the main loop will process 4 * 8 = 32 elements.

This parameter will be used to compute the number of full-width epilogues that need to be executed.

Required Methods§

Source

unsafe fn main<S, L, R, A>( loader: &Loader<S, L, R, A>, trip_count: usize, epilogues: usize, ) -> S::Accumulator
where A: Architecture, S: SIMDSchema<L, R, A>,

Perform the main unrolled loops of a SIMD kernel. This loop is expected to process all elements in the range [0, trip_count * S::get_simd_width() * Self::BLOCK_SIZE) and return an accumulator consisting of the result.

§Arguments
  • loader: A SIMD loader to emit loads to the two source spans.
  • trip_count: The number of blocks of size BLOCK_SIZE to process. A single “trip” will process S::get_simd_width() * Self::BLOCK_SIZE elements. So, computation of trip_count should be computed as:
    let trip_count = len / (S::get_simd_width() * <_ as MainLoop>::BLOCK_SIZE);
  • epilogues: The number of S::get_simd_width() vectors remaining after all the main blocks have been processed. This is guaranteed to be less than Self::BLOCK_SIZE.
§Safety

All elements in the accessed range must be valid. The memory addresses touched are

let block_size = Self::BLOCK_SIZE;
let simd_width = S::get_simd_width();
[
    loader.left,
    loader.left + trip_count * simd_width + block_size + epilogues * simd_width
)
[
    loader.right,
    loader.right + trip_count * simd_width + block_size + epilogues * simd_width
)

The loader will ensure that all accesses are in-bounds in debug builds.

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§