Implemented a General Matrix MUltiplication(GEMM) on my sandy Bridge i3 2n gen old processor which achived execution time of less than 0.161s sec from 58.8 sec in naive, ALso while benchmakrking it with OPENBLAS an industry standard matrix multiplication library, my code achived the efficiey of more than 70.55% relative to the openBLAS whose executation time was approx 0.113 sec, Just 0.048sec more than mine
This project documents the optimization journey of a Double-Precision General Matrix Multiplication (DGEMM) kernel — starting from naive triple loops, progressing through L1 cache tiling and manual AVX-256 register blocking (8×4), and finally benchmarking against the industry-standard OpenBLAS implementation.
The goal was not to outperform OpenBLAS or achieve theoretical peak GFLOPS, but to analyze how execution behavior changes under different optimization techniques, algorithmic choices, and hardware constraints.
The benchmark below compares execution time, achieved GFLOPS, and percentage of theoretical peak throughput for a 1024×1024 matrix multiplication workload.
Median of 30 runs.
All benchmarks were executed on bare-metal hardware.
- CPU: Intel® Core™ i3-2120 @ 3.30 GHz (Sandy Bridge / 2nd Gen)
- Topology: 2 Physical Cores / 4 Threads
- Instruction Set: AVX (256-bit registers)
- Limitations: No AVX2 and no FMA (Fused Multiply-Add), requiring separate multiply and add instructions
- L1 Data Cache: 64 KiB total (32 KiB per core)
- Peak Theoretical Compute: ~52.8 GFLOPS (Double Precision)
Baseline implementation using standard triple nested loops.
Partitioned matrices into cache-friendly tiles with padding to improve locality,reduce memory stalls and eliminate cache set collision.
Used AVX-256 intrinsics to process multiple double-precision values in parallel and reduce scalar instruction overhead.
Compared the handwritten implementation against a production-grade BLAS library.
MIT Performance Engineering: https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/video_galleries/lecture-videos/
Agner Fog — Optimizing Software in C++: https://www.agner.org/optimize/optimizing_cpp.pdf
Matrix Multiplication Optimization Notes: https://michalpitr.substack.com/p/optimizing-matrix-multiplication
If you're interested, I can also publish a detailed write-up covering the exact optimization path, benchmark methodology, cache effects, and AVX implementation decisions.
Feel free to explore, modify, benchmark, or improve it.
Reach me out at
Telegram
X/Twitter
Email: vermaadityansh@gmail.com
Keep learning :>
