Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix Multiplication Benchmark

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.

Highlights

  • Multiple matrix multiplication implementations
  • Loop-order optimization (ijk vs. 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

Implementations

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.

Requirements

Linux / WSL

Install Clang and OpenBLAS:

sudo apt update
sudo apt install clang libopenblas-dev

Verify the compiler installation:

clang --version

Windows

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 & Run

Linux / WSL

Build with JSON output enabled:

make OUTPUT_JSON=1

This generates:

lab6

Run the benchmark:

./lab6

Windows

From PowerShell:

make OUTPUT_JSON=1

This generates:

lab6.exe

Run:

.\lab6.exe

Clean

Linux / WSL

make clean

Windows

make clean

Benchmark Output

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

JSON Benchmark Output

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.

Performance Optimization

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.

Correctness Validation

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 Support

Platform Supported
Linux
WSL
Windows

The Makefile automatically selects platform-specific compiler and linker options.

Project Structure

.
├── Makefile
├── *.c
├── *.h
├── openblas/
│   ├── include/
│   │   └── cblas.h
│   └── lib/
│       └── libopenblas.a
└── README.md

Technologies

  • C
  • Clang / LLVM
  • OpenBLAS
  • AVX2
  • FMA
  • SIMD intrinsics
  • Cache blocking
  • Benchmarking / Performance Analysis
  • JSON

Key Concepts

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

About

C matrix multiplication lab comparing OpenBLAS with custom optimized implementations using cache blocking and AVX2/FMA.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages