r/rust • • 11h ago

🧠 educational Devlog: Optimizing f64 GEMM from 6.5 to ~40 GFLOP/s with a BLIS-style micro-kernel

https://adii.fyi/blog/optimizing-matmul-in-rust-from-naive-loops-to-blis/

I wanted to see how far I could push a single-threaded f64 matmul. Started with the usual i-k-j loop, and then spent quite a bit of time looking at asm, then experimenting with SIMD, and eventually working through BLIS-style blocking and packing.

Writing this up was a good way to document the whole process, so thought I'd share it here.

0 Upvotes

3 comments sorted by

0

u/codear 1h ago

While gains are indisputable, the tradeoff of this approach is a platform lock. And not just that - the system needs to support the very instructions you used.

I'm a bit surprised rust doesn't allow you to tap into vector instructions without inline assembly. I did some of that (vector optimizations) out of my curiosity and did not have to go that low.

Cool to see the potential but not sure if the benefits are worth the cost

1

u/frozen_beak 5m ago

Zero inline assembly here mate! Those are just cargo asm dumps of what LLVM generated, and Rust handles SIMD fine via std::arch intrinsics and auto-vectorization.

And mainly, Low-level optimization is hardware specific by nature, so targeting x86-64 just means aarch64 is separate work. Also for SIMD target we use AVX2+FMA which are hardware and cpu specific, I know but this is for my own NN implementation. Perhaps I should have stated that this is x86-64 specific only!!