7 releases
0.1.6 | Feb 28, 2024 |
---|---|
0.1.5 | May 4, 2022 |
0.1.4 | Apr 3, 2022 |
0.1.3 | Feb 11, 2022 |
#400 in Hardware support
22 downloads per month
100KB
2.5K
SLoC
LLML's SIMD
SIMD (Single Instruction Multiple Data) extension for a variety of targets. This project was initially started to facilitate the expansion of LLML's suported targets & features
Contents
This crate/library contains bindings to native-level SIMD instructions (alongside some polyfill) for SSE, AVX (see AVX support), NEON & WASM. It also contains naive implementations of all data-types (see naive implementation)
No std
llml_simd
is a no_std crate. This means that it can be used for embeded systems projects seamlessly.
Naive implementation
If no supported target is detected (or if you enable the feature force_naive
), Rust will compile the the SIMD vectors in naive mode. This mode represent's all data types as an array, executing most of the methods via iterators. This mode, while not recommended, is usefull if you intend to share code with some other programm that doesn't have SIMD support.
Warning
While not explicitly SIMD,rustc
might still optimize some parts of the code to utilize SIMD instructions if it can and you allow it to. If you want to fully disable SIMD instructions, use--target-feature=-sse
on x86/x86_64 and--target-feature=-neon
on arm/aarch64 (naive mode will be used automatically in those cases, not requiring to enableforce_naive
)
AVX Support
If Rust detects avx
as a target feature and you have the use_avx
feature enabled (see features), llml_simd
will compile all vectors over 128-bit long with AVX instructions, increasing performance significantly.
JavaScript Library
Thanks to WASM, llml_simd
is available for JavaScript/TypeScript via npm.
You can install it into your Node project with npm i llml_simd
Features
Feature | Description |
---|---|
use_std |
Enables standard library functionality. Enabled by default |
force_naive |
Forces naive types (see Naive implementation) |
use_avx |
Enables the use of AVX SIMD types (see AVX support) |
random |
Enables random generation of vectors via rand |
serialize |
Enables serialization and deserialization of vectors via serde |
Examples
Dot product (Rust)
use llml_simd::float::single::f32x4;
pub fn main() {
let alpha = f32x4::new([1., 2., 3., 4.]);
let beta = f32x4::new([5., 6., 7., 8.]);
let dot = (alpha * beta).sum();
assert_eq!(dot, 70.);
}
Dot product (JavaScript)
import { f32x4 } from llml_simd
let alpha = new f32x4(new Float32Array([1, 2, 3, 4]))
let beta = new f32x4(new Float32Array([5, 6, 7, 8]))
let dot = alpha.mul(beta).sum()
console.assert(dot === 70)
Dependencies
~1.5MB
~40K SLoC