#matrix #sgemm #dgemm

matrixmultiply_mt

Multithreaded Fork of bluss’s matrixmultiply crate. General matrix multiplication of f32 and f64 matrices in Rust. Supports matrices with general strides. Uses a microkernel strategy, so that the implementation is easy to parallelize and optimize. RUSTFLAGS="-C target-cpu=native" is your friend here.

8 releases

Uses old Rust 2015

0.1.7 Oct 24, 2019
0.1.6 Jun 27, 2018
0.1.5 Nov 23, 2017
0.1.1 Feb 12, 2017
0.1.0 Jan 24, 2017

#813 in Data structures

46 downloads per month
Used in alumina

MIT/Apache

73KB
1.5K SLoC

About

A multithreaded fork of bluss' matrixmultiply crate. General matrix multiplication for f32, f64 matrices. Allows arbitrary row, column strided matrices. Relies heavily on llvm to vectorise the floating point ops.

Tuning

To enable specialised vector instructions for you computer compile using: RUSTFLAGS="-C target-cpu=native" and MATMULFLAGS="flag1, flag2, ..." where one flag is an architecture flag:

arch_generic4x4           // fallback if architecture is unknown, should use x86 sse and ARM Neon
arch_generic4x4fma        // might be useful for newer ARM Neon
arch_penryn               // uses the extra x86_64 xmm registers
arch_sandybridge          // uses AVX
arch_haswell              // uses AVX2

and the rest are optional flags:

ftz_daz                   // (nightly) On x86 this will round denormals to zero to improve performance
prefetch                  // (nightly) Inserts prefetch instructions tuned for recent intel processors
no_multithreading         // disables multithreading

e.g. MATMULFLAGS="arch_sandybridge, ftz_daz"

On nightly, the build script will use CARGO_CFG_TARGET_FEATURE to guess the best architecture flag if one isnt supplied.

Dependencies

~1MB
~22K SLoC