85.3 GFlops: Optimizing FP32 Matrix Multiplication on a Single AMD Zen 3 Core
The author of the zen3‑gemm repository built 28 C++ intrinsics variants that combine three‑level cache tiling, register blocking, FMA‑chaining, on‑the‑fly packing of matrix B, and 32‑byte alignment. The top‑scoring variant, MX24, uses a 4‑line register block, a chain‑4 FMA schedule, and a B‑pack buffer sized 256 × BK, delivering 85.30 GFLOPS. This is 56.5 × faster than a naïve ijk implementation and sits at 63.5 % of the theoretical Zen 3 single‑core ceiling (2 FMA ports × 8 floats × 2 ops × 4.2 GHz). The study also shows that aggressive tricks such as software prefetching or non‑temporal stores degrade performance on Zen 3, confirming the processor’s strong hardware prefetcher and cache coherence behavior.
The result matters because most developers rely on pre‑compiled BLAS libraries that hide such low‑level tuning. Achieving library‑grade throughput with a single source file demonstrates that carefully crafted intrinsics can still outperform generic compiler output on modern CPUs. Zen 3’s 4‑cycle FMA latency, limited YMM register file (16 registers), and 32 KB L1 cache create a narrow sweet spot that the MX24 kernel exploits; similar hand‑tuned kernels on Intel’s Ice Lake or Sapphire Rapids have reported comparable percentages of peak, suggesting the technique is portable across x86 SIMD architectures. The work also highlights that many “optimizations” (e.g., larger register blocks, deeper chaining) backfire when they exceed register or cache capacity, reinforcing the need for exhaustive empirical tuning rather than theoretical assumptions.
Looking ahead, the open‑source kernel provides a baseline for extending single‑core GEMM to multi‑core scaling, mixed‑precision, or upcoming Zen 4/5 CPUs that add more registers (AVX‑512‑style) and
About the Source
This analysis is based on reporting by Hacker News. Here is a short excerpt for context:
CommentsRead the original at Hacker News