A C-based benchmark and performance study of multiple matrix multiplication implementations, ranging from basic loop-based approaches to cache blocking and AVX2/FMA vectorization.
The project compares custom implementations against OpenBLAS cblas_dgemm and validates the numerical correctness of each optimized implementation.
- Multiple matrix multiplication implementations
- Loop-order optimization (
ijkvs.ikj) - Cache blocking / tiling
- AVX2/FMA SIMD optimization
- 64-byte aligned memory
- Performance measurement in GFLOP/s
- Numerical correctness validation against OpenBLAS
- Optional JSON output for benchmark results
- Cross-platform support for Linux, WSL, and Windows
| Implementation | Description |
|---|---|
ijk |
Basic triple-loop matrix multiplication |
ikj |
Loop-order optimized implementation |
| Blocked MM | Cache-blocked matrix multiplication |
| Optimized MM | Further optimized blocked implementation |
| AVX2/FMA MM | SIMD implementation using AVX2/FMA intrinsics |
cblas_dgemm |
OpenBLAS reference implementation |
The optimized implementations use 64-byte aligned memory and AVX2/FMA intrinsics where applicable.
Install Clang and OpenBLAS:
sudo apt update
sudo apt install clang libopenblas-dev
Verify the compiler installation:
clang --version
Install:
- LLVM/Clang
- A Windows-compatible OpenBLAS installation
The OpenBLAS installation should contain:
openblas/
├── include/
│ └── cblas.h
└── lib/
└── libopenblas.a
Place the openblas directory in the project root.
OpenBLAS binaries are not included in this repository and must be installed separately for the target platform.
Build with JSON output enabled:
make OUTPUT_JSON=1
This generates:
lab6
Run the benchmark:
./lab6
From PowerShell:
make OUTPUT_JSON=1
This generates:
lab6.exe
Run:
.\lab6.exe
make clean
make clean
The program reports the execution time and achieved performance in GFLOP/s for each matrix multiplication implementation.
It also compares the numerical results of the custom implementations against the OpenBLAS cblas_dgemm reference implementation.
Example:
cblas_dgemm Matrix Multiplication
time spent = ... us, GFLOP/s = ...
OptimizedMM2
time spent = ... us, GFLOP/s = ...
Correctness: pass
OptimizedMM3
time spent = ... us, GFLOP/s = ...
Correctness: pass
OptimizedMM4
time spent = ... us, GFLOP/s = ...
Correctness: pass
When built with:
make OUTPUT_JSON=1
the benchmark also generates:
Result.json
The file contains profiling information collected during the benchmark and can be used for further analysis or visualization.
Result.json is generated locally and is not tracked by Git.
The project explores several levels of optimization:
Naive ijk
↓
Loop-order optimization (ikj)
↓
Cache blocking
↓
Optimized blocking
↓
AVX2/FMA vectorization
↓
OpenBLAS cblas_dgemm
These implementations allow the performance impact of memory access patterns, cache locality, blocking strategies, and SIMD vectorization to be compared directly.
Each custom matrix multiplication implementation is validated against the result produced by OpenBLAS cblas_dgemm.
The benchmark reports whether the computed result passes the numerical correctness check:
Correctness: pass
This ensures that performance optimizations do not compromise numerical accuracy.
| Platform | Supported |
|---|---|
| Linux | ✓ |
| WSL | ✓ |
| Windows | ✓ |
The Makefile automatically selects platform-specific compiler and linker options.
.
├── Makefile
├── *.c
├── *.h
├── openblas/
│ ├── include/
│ │ └── cblas.h
│ └── lib/
│ └── libopenblas.a
└── README.md
- C
- Clang / LLVM
- OpenBLAS
- AVX2
- FMA
- SIMD intrinsics
- Cache blocking
- Benchmarking / Performance Analysis
- JSON
This project explores several low-level performance optimization concepts, including:
- CPU cache locality
- Memory access patterns
- Loop ordering
- Cache blocking / tiling
- SIMD vectorization
- AVX2 and FMA instructions
- Aligned memory access
- BLAS-based numerical computing
- Performance measurement using GFLOP/s