#matrix-multiplication #matrix #dgemm #sgemm

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.

10 releases

0.2.1 Aug 22, 2022
0.2.0 Sep 4, 2021
0.1.7 Oct 24, 2019
0.1.6 Jun 27, 2018
0.1.0 Jan 24, 2017

#553 in Math

Download history 4/week @ 2024-02-14 16/week @ 2024-02-21 51/week @ 2024-02-28 6/week @ 2024-03-06 4/week @ 2024-03-13

80 downloads per month
Used in alumina

MIT/Apache

71KB
2K 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

~0.9–1.3MB
~23K SLoC