Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matrix Multiplication Bench

Compare MatMul performance of various library implementations.

Setup

Note

Eigen and Google's Benchmark need to be located one directory up from gemm_microbench.

Install Eigen

#Get Eigen from the official website
wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip
#Unpack and set the correct name
unzip eigen-3.4.0.zip && rm eigen-3.4.0.zip && mv eigen-3.4.0 Eigen

If the above doesn't work, reference Eigen's Official Website

Install Google's Benchmark

# Check out the library.
$ git clone https://github.com/google/benchmark.git
# Go to the library root directory
$ cd benchmark
# Make a build directory to place the build output
$ cmake -E make_directory "build"# Generate build system files with cmake, and download any dependencies
$ cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
# or, starting with CMake 3.13, use a simpler form:# cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release -S . -B "build"# Build the library
$ cmake --build "build" --config Release
# Next, you can run the tests to check the build
$ cmake -E chdir "build" ctest --build-config Release
# Install the library globally& sudo cmake --build "build" --config Release --target install

If the above doesn't work, reference Google's Benchmark GitHub

Install Intel oneAPU Base Toolkit

# Download the installer
$ wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/4a5320d1-0b48-458d-9668-fd0e4501208c/intel-oneapi-base-toolkit-2025.1.3.7_offline.sh
# Run the install script
$ sudo sh ./intel-oneapi-base-toolkit-2025.1.3.7_offline.sh -a --silent --cli --eula accept
# Set the environment variables
$ . /opt/intel/oneapi/setvars.sh

If the above doesn't work, reference Intel oneAPI Base Toolkit's Official Website

Running the Benchmark

# Default setup where the max threads available on your system are used
make all
# This specifies how many threads should be used
make all THREADS=16

Results

The benchmark also checks that the result of the GEMM operation matches across all libraries and crates.

Single-thread

Test CaseLibraryLanguageResult
Input AEigenC++0.466s
matrixmultiplyRust0.599s
CBLASRust0.406s
Input BEigenC++0.495s
matrixmultiplyRust0.607s
CBLASRust0.409s
Input CEigenC++2.073s
matrixmultiplyRust2.644s
CBLASRust1.705s
Input DEigenC++40.823s
matrixmultiplyRust42.953s
CBLASRust29.670s

Grpahed Results for single-thread

2 Threads

Test CaseLibraryLanguageResult
Input AEigenC++0.268s
matrixmultiplyRust0.329s
CBLASRust0.207s
Input BEigenC++0.281s
matrixmultiplyRust0.343s
CBLASRust0.211s
Input CEigenC++1.151s
matrixmultiplyRust1.443s
CBLASRust0.852s
Input DEigenC++28.048s
matrixmultiplyRust25.668s
CBLASRust15.485s

Grpahed Results for 2 threads

4 Threads (Maximum Threads Supported by matrixmultiply)

Test CaseLibraryLanguageResult
Input AEigenC++0.172s
matrixmultiplyRust0.209s
CBLASRust0.122s
Input BEigenC++0.173s
matrixmultiplyRust0.191s
CBLASRust0.124s
Input CEigenC++0.609s
matrixmultiplyRust0.808s
CBLASRust0.480s
Input DEigenC++14.786s
matrixmultiplyRust15.655s
CBLASRust9.329s

Grpahed Results for 4 threads

8 Threads

Test CaseLibraryLanguageResult
Input AEigenC++0.091s
matrixmultiplyRust0.248s
CBLASRust0.0695s
Input BEigenC++0.0959s
matrixmultiplyRust0.253s
CBLASRust0.0668s
Input CEigenC++0.401s
matrixmultiplyRust0.976s
CBLASRust0.258s
Input DEigenC++5.503s
matrixmultiplyRust15.779s
CBLASRust4.948s

Grpahed Results for 8 threads

16 Threads

Test CaseLibraryLanguageResult
Input AEigenC++0.0691s
matrixmultiplyRust0.243s
CBLASRust0.0498s
Input BEigenC++0.0767s
matrixmultiplyRust0.246s
CBLASRust0.0343s
Input CEigenC++0.259s
matrixmultiplyRust1.024s
CBLASRust0.165s
Input DEigenC++3.381s
matrixmultiplyRust16.960s
CBLASRust3.994s

Grpahed Results for 16 threads

32 Threads

Test CaseLibraryLanguageResult
Input AEigenC++0.0606s
matrixmultiplyRust0.231s
CBLASRust0.0462s
Input BEigenC++0.0725s
matrixmultiplyRust0.240s
CBLASRust0.0555s
Input CEigenC++0.235s
matrixmultiplyRust0.966s
CBLASRust0.187s
Input DEigenC++2.933s
matrixmultiplyRust17.732s
CBLASRust3.597s

Grpahed Results for 32 threads

48 Threads (Maximum Threads Supported by my testing machine - Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz)

Test CaseLibraryLanguageResult
Input AEigenC++0.0629s
matrixmultiplyRust0.231s
CBLASRust0.0307s
Input BEigenC++0.0744s
matrixmultiplyRust0.234s
CBLASRust0.0462s
Input CEigenC++0.161s
matrixmultiplyRust1.009s
CBLASRust0.121s
Input DEigenC++3.065s
matrixmultiplyRust18.508s
CBLASRust3.928s

Grpahed Results for 48 threads

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages