AVX-512 optimized matrix-vector multiplication in C, benchmarked on Intel Cascade Lake CPUs. The project compares a scalar baseline against a SIMD vectorized kernel and shows how wider vector registers improve floating-point throughput for large dense matrix-vector workloads.
| Matrix Size | Vector Size | Scalar Baseline | AVX-512 Optimized | Speedup |
|---|---|---|---|---|
16 x 16 |
16 |
0.003088 ms |
0.002773 ms |
1.11x |
4096 x 4096 |
4096 |
46.48076 ms |
7.806032 ms |
5.95x |
The large 4096 x 4096 benchmark achieved the strongest result because the AVX-512 kernel processes 16 single-precision floating-point values per vector operation, allowing the SIMD version to amortize loop overhead and make better use of Cascade Lake vector hardware.
- Built a scalar matrix-vector multiplication baseline in C.
- Implemented an AVX-512 optimized kernel using Intel SIMD intrinsics.
- Used
_mm512_loadu_psto load 16floatvalues at a time. - Used
_mm512_fmadd_psto fuse multiply-add operations across AVX-512 lanes. - Used
_mm512_reduce_add_psto reduce vector lanes into each row's dot-product result. - Benchmarked small and large matrix sizes to compare SIMD benefit at different scales.
- Ran AVX-enabled workloads in a Slurm cluster environment on Cascade Lake CPUs.
- Used
srun --constraint=cascadelaketo ensure execution on AVX-512 capable hardware. - Generated assembly output to inspect emitted vector instructions such as
vaddps,vmulss, andvmovss.
The program computes:
C = A x B
Where:
Ais a denseN x Nsingle-precision floating-point matrix.Bis a dense vector of lengthN.Cis the output vector of lengthN.
Two kernels are benchmarked:
| Kernel | Description |
|---|---|
matrix_vector_multiplication |
Scalar baseline using nested loops. |
matrix_vector_multiplication_AVX |
AVX-512 vectorized version using 512-bit SIMD registers. |
.
|-- avx512_matrix_vector_multiplication.c
|-- avx512_matrix_vector_assembly.s
|-- AVX512_Matrix_Vector_Multiplication_Report.pdf
|-- Makefile
`-- README.md
Compile and run:
make runGenerate assembly for instruction-level inspection:
make asmgenerateThe matrix size is controlled by the N macro in avx512_matrix_vector_multiplication.c:
#define N 2048Change N to benchmark different matrix sizes.
Request an AVX-512 capable Cascade Lake node:
srun -N1 -n 8 -p courses --constraint=cascadelake --pty bashRun the compiled benchmark:
srun --constraint=cascadelake ./outputSee AVX512_Matrix_Vector_Multiplication_Report.pdf for the full benchmark walkthrough, CPU/AVX support verification, console outputs, speedup calculation, and assembly instruction discussion.