Crate simd_aligned
source ·Expand description
NOTE - Do not use this crate for now. It has been reactivated to make FFSVM compile again, but needs some architectural work.
§In One Sentence
You want to use std::simd but realized there is no simple, safe and fast way to align your f32x8 (and friends) in memory and treat them as regular f32 slices for easy loading and manipulation; simd_aligned to the rescue.
§Highlights
- built on top of
std::simdfor easy data handling - supports everything from
u8x2tof64x8 - think in flat slices (
&[f32]), but get performance of properly aligned SIMD vectors (&[f32x16]) - defines
u8s, …,f36sas “best guess” for current platform (WIP) - provides N-dimensional
VectorDand NxM-dimensionalMatrixD.
Note: Right now this is an experimental crate. Features might be added or removed depending on how std::simd evolves. At the end of the day it’s just about being able to load and manipulate data without much fuzz.
§Examples
Produces a vector that can hold 10 elements of type f64. Might internally
allocate 5 elements of type f64x2, or 3 of type f64x4, depending on the platform.
All elements are guaranteed to be properly aligned for fast access.
#![feature(portable_simd)]
use std::simd::*;
use simd_aligned::*;
// Create vectors of `10` f64 elements with value `0.0`.
let mut v1 = VectorD::<f64s>::with(0.0, 10);
let mut v2 = VectorD::<f64s>::with(0.0, 10);
// Get "flat", mutable view of the vector, and set individual elements:
let v1_m = v1.flat_mut();
let v2_m = v2.flat_mut();
// Set some elements on v1
v1_m[0] = 0.0;
v1_m[4] = 4.0;
v1_m[8] = 8.0;
// Set some others on v2
v2_m[1] = 0.0;
v2_m[5] = 5.0;
v2_m[9] = 9.0;
let mut sum = f64s::splat(0.0);
// Eventually, do something with the actual SIMD types. Does
// `std::simd` vector math, e.g., f64x8 + f64x8 in one operation:
sum = v1[0] + v2[0];§Benchmarks
There is no performance penalty for using simd_aligned, while retaining all the
simplicity of handling flat arrays.
test vectors::packed ... bench: 77 ns/iter (+/- 4)
test vectors::scalar ... bench: 1,177 ns/iter (+/- 464)
test vectors::simd_aligned ... bench: 71 ns/iter (+/- 5)§FAQ
§How does it relate to faster and std::simd?
-
simd_alignedbuilds on top ofstd::simd. At aims to provide common, SIMD-aligned data structure that support simple and safe scalar access patterns. -
faster(as of today) is really good if you already have exiting flat slices in your code and want operate them “full SIMD ahead”. However, in particular when dealing with multiple slices at the same time (e.g., kernel computations) the performance impact of unaligned arrays can become a bit more noticeable (e.g., in the case of ffsvm up to 10% - 20%).
Re-exports§
pub use crate::matrix::AccessStrategy;pub use crate::matrix::Columns;pub use crate::matrix::Rows;pub use crate::arch::current::*;
Modules§
- Contains vector definitions with a fixed bit width.
- cmpExperimentalTraits for comparing and ordering vectors.
- numExperimentalTraits for vectors with numeric elements.
- preludeExperimentalThe portable SIMD prelude.
- ptrExperimentalTraits for vectors of pointers.
- Unified views on SIMD types.
Macros§
- simd_swizzleExperimentalConstructs a new SIMD vector by copying elements from selected elements in other vectors.
Structs§
- LaneCountExperimentalSpecifies the number of lanes in a SIMD vector as a type.
- MaskExperimentalA SIMD vector mask for
Nelements of width specified byElement. - A dynamic (heap allocated) matrix with one axis aligned for fast and safe SIMD access that also provides a flat view on its data.
- Produced by
MatrixD::flat, this allow for flat matrix access. - Provided by
MatrixD::flat_mut, this allow for flat, mutable matrix access. - SimdExperimentalA SIMD vector with the shape of
[T; N]but the operations ofT. - A dynamic (heap allocated) vector aligned for fast and safe SIMD access that also provides a flat view on its data.
Traits§
- MaskElementExperimentalMarker trait for types that may be used as SIMD mask elements.
- SimdCastExperimentalSupporting trait for
Simd::cast. Typically doesn’t need to be used directly. - SimdElementExperimentalMarker trait for types that may be used as SIMD vector elements.
- StdFloatExperimentalThis trait provides a possibly-temporary implementation of float functions that may, in the absence of hardware support, canonicalize to calling an operating system’s
math.hdynamically-loaded library (also known as a shared object). As these conditionally require runtime support, they should only appear in binaries built assuming OS support:std. - SupportedLaneCountExperimentalStatically guarantees that a lane count is marked as supported.
- SwizzleExperimentalCreate a vector from the elements of another vector.
- ToBytesExperimentalConvert SIMD vectors to vectors of bytes
Functions§
- Converts an slice of SIMD vectors into a flat slice of elements.
- Converts a mutable slice of SIMD vectors into a flat slice of elements.
Type Aliases§
- f32x1ExperimentalA SIMD vector with one element of type
f32. - f32x2ExperimentalA SIMD vector with two elements of type
f32. - f32x4ExperimentalA SIMD vector with four elements of type
f32. - f32x8ExperimentalA SIMD vector with eight elements of type
f32. - f32x16ExperimentalA SIMD vector with 16 elements of type
f32. - f32x32ExperimentalA SIMD vector with 32 elements of type
f32. - f32x64ExperimentalA SIMD vector with 64 elements of type
f32. - f64x1ExperimentalA SIMD vector with one element of type
f64. - f64x2ExperimentalA SIMD vector with two elements of type
f64. - f64x4ExperimentalA SIMD vector with four elements of type
f64. - f64x8ExperimentalA SIMD vector with eight elements of type
f64. - f64x16ExperimentalA SIMD vector with 16 elements of type
f64. - f64x32ExperimentalA SIMD vector with 32 elements of type
f64. - f64x64ExperimentalA SIMD vector with 64 elements of type
f64. - i8x1ExperimentalA SIMD vector with one element of type
i8. - i8x2ExperimentalA SIMD vector with two elements of type
i8. - i8x4ExperimentalA SIMD vector with four elements of type
i8. - i8x8ExperimentalA SIMD vector with eight elements of type
i8. - i8x16ExperimentalA SIMD vector with 16 elements of type
i8. - i8x32ExperimentalA SIMD vector with 32 elements of type
i8. - i8x64ExperimentalA SIMD vector with 64 elements of type
i8. - i16x1ExperimentalA SIMD vector with one element of type
i16. - i16x2ExperimentalA SIMD vector with two elements of type
i16. - i16x4ExperimentalA SIMD vector with four elements of type
i16. - i16x8ExperimentalA SIMD vector with eight elements of type
i16. - i16x16ExperimentalA SIMD vector with 16 elements of type
i16. - i16x32ExperimentalA SIMD vector with 32 elements of type
i16. - i16x64ExperimentalA SIMD vector with 64 elements of type
i16. - i32x1ExperimentalA SIMD vector with one element of type
i32. - i32x2ExperimentalA SIMD vector with two elements of type
i32. - i32x4ExperimentalA SIMD vector with four elements of type
i32. - i32x8ExperimentalA SIMD vector with eight elements of type
i32. - i32x16ExperimentalA SIMD vector with 16 elements of type
i32. - i32x32ExperimentalA SIMD vector with 32 elements of type
i32. - i32x64ExperimentalA SIMD vector with 64 elements of type
i32. - i64x1ExperimentalA SIMD vector with one element of type
i64. - i64x2ExperimentalA SIMD vector with two elements of type
i64. - i64x4ExperimentalA SIMD vector with four elements of type
i64. - i64x8ExperimentalA SIMD vector with eight elements of type
i64. - i64x16ExperimentalA SIMD vector with 16 elements of type
i64. - i64x32ExperimentalA SIMD vector with 32 elements of type
i64. - i64x64ExperimentalA SIMD vector with 64 elements of type
i64. - isizex1ExperimentalA SIMD vector with one element of type
isize. - isizex2ExperimentalA SIMD vector with two elements of type
isize. - isizex4ExperimentalA SIMD vector with four elements of type
isize. - isizex8ExperimentalA SIMD vector with eight elements of type
isize. - isizex16ExperimentalA SIMD vector with 16 elements of type
isize. - isizex32ExperimentalA SIMD vector with 32 elements of type
isize. - isizex64ExperimentalA SIMD vector with 64 elements of type
isize. - mask8x1ExperimentalA SIMD mask with one element for vectors with 8-bit element types.
- mask8x2ExperimentalA SIMD mask with two elements for vectors with 8-bit element types.
- mask8x4ExperimentalA SIMD mask with four elements for vectors with 8-bit element types.
- mask8x8ExperimentalA SIMD mask with eight elements for vectors with 8-bit element types.
- mask8x16ExperimentalA SIMD mask with 16 elements for vectors with 8-bit element types.
- mask8x32ExperimentalA SIMD mask with 32 elements for vectors with 8-bit element types.
- mask8x64ExperimentalA SIMD mask with 64 elements for vectors with 8-bit element types.
- mask16x1ExperimentalA SIMD mask with one element for vectors with 16-bit element types.
- mask16x2ExperimentalA SIMD mask with two elements for vectors with 16-bit element types.
- mask16x4ExperimentalA SIMD mask with four elements for vectors with 16-bit element types.
- mask16x8ExperimentalA SIMD mask with eight elements for vectors with 16-bit element types.
- mask16x16ExperimentalA SIMD mask with 16 elements for vectors with 16-bit element types.
- mask16x32ExperimentalA SIMD mask with 32 elements for vectors with 16-bit element types.
- mask16x64ExperimentalA SIMD mask with 64 elements for vectors with 16-bit element types.
- mask32x1ExperimentalA SIMD mask with one element for vectors with 32-bit element types.
- mask32x2ExperimentalA SIMD mask with two elements for vectors with 32-bit element types.
- mask32x4ExperimentalA SIMD mask with four elements for vectors with 32-bit element types.
- mask32x8ExperimentalA SIMD mask with eight elements for vectors with 32-bit element types.
- mask32x16ExperimentalA SIMD mask with 16 elements for vectors with 32-bit element types.
- mask32x32ExperimentalA SIMD mask with 32 elements for vectors with 32-bit element types.
- mask32x64ExperimentalA SIMD mask with 64 elements for vectors with 32-bit element types.
- mask64x1ExperimentalA SIMD mask with one element for vectors with 64-bit element types.
- mask64x2ExperimentalA SIMD mask with two elements for vectors with 64-bit element types.
- mask64x4ExperimentalA SIMD mask with four elements for vectors with 64-bit element types.
- mask64x8ExperimentalA SIMD mask with eight elements for vectors with 64-bit element types.
- mask64x16ExperimentalA SIMD mask with 16 elements for vectors with 64-bit element types.
- mask64x32ExperimentalA SIMD mask with 32 elements for vectors with 64-bit element types.
- mask64x64ExperimentalA SIMD mask with 64 elements for vectors with 64-bit element types.
- masksizex1ExperimentalA SIMD mask with one element for vectors with pointer-sized element types.
- masksizex2ExperimentalA SIMD mask with two elements for vectors with pointer-sized element types.
- masksizex4ExperimentalA SIMD mask with four elements for vectors with pointer-sized element types.
- masksizex8ExperimentalA SIMD mask with eight elements for vectors with pointer-sized element types.
- masksizex16ExperimentalA SIMD mask with 16 elements for vectors with pointer-sized element types.
- masksizex32ExperimentalA SIMD mask with 32 elements for vectors with pointer-sized element types.
- masksizex64ExperimentalA SIMD mask with 64 elements for vectors with pointer-sized element types.
- u8x1ExperimentalA SIMD vector with one element of type
u8. - u8x2ExperimentalA SIMD vector with two elements of type
u8. - u8x4ExperimentalA SIMD vector with four elements of type
u8. - u8x8ExperimentalA SIMD vector with eight elements of type
u8. - u8x16ExperimentalA SIMD vector with 16 elements of type
u8. - u8x32ExperimentalA SIMD vector with 32 elements of type
u8. - u8x64ExperimentalA SIMD vector with 64 elements of type
u8. - u16x1ExperimentalA SIMD vector with one element of type
u16. - u16x2ExperimentalA SIMD vector with two elements of type
u16. - u16x4ExperimentalA SIMD vector with four elements of type
u16. - u16x8ExperimentalA SIMD vector with eight elements of type
u16. - u16x16ExperimentalA SIMD vector with 16 elements of type
u16. - u16x32ExperimentalA SIMD vector with 32 elements of type
u16. - u16x64ExperimentalA SIMD vector with 64 elements of type
u16. - u32x1ExperimentalA SIMD vector with one element of type
u32. - u32x2ExperimentalA SIMD vector with two elements of type
u32. - u32x4ExperimentalA SIMD vector with four elements of type
u32. - u32x8ExperimentalA SIMD vector with eight elements of type
u32. - u32x16ExperimentalA SIMD vector with 16 elements of type
u32. - u32x32ExperimentalA SIMD vector with 32 elements of type
u32. - u32x64ExperimentalA SIMD vector with 64 elements of type
u32. - u64x1ExperimentalA SIMD vector with one element of type
u64. - u64x2ExperimentalA SIMD vector with two elements of type
u64. - u64x4ExperimentalA SIMD vector with four elements of type
u64. - u64x8ExperimentalA SIMD vector with eight elements of type
u64. - u64x16ExperimentalA SIMD vector with 16 elements of type
u64. - u64x32ExperimentalA SIMD vector with 32 elements of type
u64. - u64x64ExperimentalA SIMD vector with 64 elements of type
u64. - usizex1ExperimentalA SIMD vector with one element of type
usize. - usizex2ExperimentalA SIMD vector with two elements of type
usize. - usizex4ExperimentalA SIMD vector with four elements of type
usize. - usizex8ExperimentalA SIMD vector with eight elements of type
usize. - usizex16ExperimentalA SIMD vector with 16 elements of type
usize. - usizex32ExperimentalA SIMD vector with 32 elements of type
usize. - usizex64ExperimentalA SIMD vector with 64 elements of type
usize.