#simd #memory #aligned

simd_aligned

Safe and fast SIMD-aligned data structures with easy and transparent ‘flat’ access

6 releases

✓ Uses Rust 2018 edition

0.2.1 Jun 11, 2019
0.2.0 Jun 7, 2019
0.1.3 Sep 13, 2018
0.1.2 Aug 15, 2018

#129 in Data structures

Download history 16/week @ 2019-06-28 78/week @ 2019-07-05 68/week @ 2019-07-12 24/week @ 2019-07-19 46/week @ 2019-07-26 44/week @ 2019-08-02 13/week @ 2019-08-09 36/week @ 2019-08-16 52/week @ 2019-08-23 18/week @ 2019-08-30 29/week @ 2019-09-06 30/week @ 2019-09-13 72/week @ 2019-09-20 18/week @ 2019-09-27 28/week @ 2019-10-04

74 downloads per month
Used in 1 crate

MIT license

35KB
677 lines

Latest Version Travis-CI Status docs MIT

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::simd for easy data handling
  • supports everything from u8x2 to f64x8
  • think in flat slices (&[f32]), but get performance of properly aligned SIMD vectors (&[f32x16])
  • defines u8s, ..., f36s as "best guess" for current platform (WIP)
  • provides Vector and 2-dimensional MatrixD.

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.

use packed_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:         202 ns/iter (+/- 3)
test vectors::scalar       ... bench:       1,586 ns/iter (+/- 85)
test vectors::simd_aligned ... bench:         201 ns/iter (+/- 10)

Status

  • Aug 8, 2018: Initial version.

FAQ

How does it relate to faster and std::simd?

  • simd_aligned builds on top of std::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%).

Dependencies

~580KB
~12K SLoC