HPMC User Guide v 1.00
© 2026 Bassem W. Jamaleddine
Figure 4.1.3 shows the result of matrix multiplication on the GPU. The plots are for the operations performed on various matrix sizes, considering operations to be performed as FMA and noFMA on either double precision or single precision.
The result is explicitly drawn from the programming exercise explained in this section.
■ Measuring Gigaflops for Matrix Multiplication with Double Precision on the GPU
Consider the following program.
This section is not included in the SAMPLE PREVIEW.
Notice how the performance in GFlops dropped by almost 50% when compared to the fused operations.
07:20 root@HPMC: /AxBcuda # perl loop2-AxBd-notfused DP ./AxBd-notfused.gpu 100 matrixsize 100 iterations in 0.024127 elapsed seconds 4.14473 GFlop/s DP ./AxBd-notfused.gpu 200 matrixsize 100 iterations in 0.0369971 elapsed seconds 21.6233 GFlop/s DP ./AxBd-notfused.gpu 300 matrixsize 100 iterations in 0.094897 elapsed seconds 28.4519 GFlop/s DP ./AxBd-notfused.gpu 400 matrixsize 100 iterations in 0.118588 elapsed seconds 53.9684 GFlop/s DP ./AxBd-notfused.gpu 500 matrixsize 100 iterations in 0.1562 elapsed seconds 80.0256 GFlop/s
■ Measuring Gigaflops for Matrix Multiplication with Single Precision on the GPU
We will rewrite the program AxBd.cu by changing the data type of the matrix elements from double to float.
The following program AxBf.cu is the same as AxBd.cu except the data type of the matrix elements is single precision float. AxBf.cu is shown in the following Listing 4.3.2.
This section is not included in the SAMPLE PREVIEW.
07:20 root@HPMC: /AxBcuda # perl loop1-AxBf-fused SP ./AxBf-fused.gpu 100 matrixsize 100 iterations in 0.0297391 elapsed seconds 6.72514 GFlop/s SP ./AxBf-fused.gpu 200 matrixsize 100 iterations in 0.030504 elapsed seconds 52.4522 GFlop/s SP ./AxBf-fused.gpu 300 matrixsize 100 iterations in 0.060467 elapsed seconds 89.3049 GFlop/s SP ./AxBf-fused.gpu 400 matrixsize 100 iterations in 0.118349 elapsed seconds 108.155 GFlop/s SP ./AxBf-fused.gpu 500 matrixsize 100 iterations in 0.123512 elapsed seconds 202.409 GFlop/s SP ./AxBf-fused.gpu 600 matrixsize 100 iterations in 0.121598 elapsed seconds 355.269 GFlop/s SP ./AxBf-fused.gpu 700 matrixsize 100 iterations in 0.145617 elapsed seconds 471.099 GFlop/s SP ./AxBf-fused.gpu 800 matrixsize 100 iterations in 0.174479 elapsed seconds 586.89 GFlop/s
Notice how for single precision floats the performance is higher when compared to double precision (using fused operations), Also note that we can fit larger size of the matrix, since two floats take the space of a one double.
Now we compile the AxBf.cu into its binary AxBf-notfused.gpu to measure the performance on floats by restricting the fused operations.
The program is compiled with nvcc options to disable the fused operations:
# nvcc -Xptxas --fmad=false -o AxBf-notfused.gpu AxBf.cu
for ($i=1; $i<=8; $i+=1) {
$size = $i * 100;
# nvcc -Xptxas --fmad=false -o AxBf-notfused.gpu AxBf.cu
system("./AxBf-notfused.gpu $size 100 0");
}
07:20 root@HPMC: /AxBcuda # perl loop1-AxBf-notfused SP ./AxBf-notfused.gpu 100 matrixsize 100 iterations in 0.029628 elapsed seconds 3.37518 GFlop/s SP ./AxBf-notfused.gpu 200 matrixsize 100 iterations in 0.0286441 elapsed seconds 27.929 GFlop/s SP ./AxBf-notfused.gpu 300 matrixsize 100 iterations in 0.0578859 elapsed seconds 46.6435 GFlop/s SP ./AxBf-notfused.gpu 400 matrixsize 100 iterations in 0.0880022 elapsed seconds 72.7255 GFlop/s SP ./AxBf-notfused.gpu 500 matrixsize 100 iterations in 0.114684 elapsed seconds 108.995 GFlop/s SP ./AxBf-notfused.gpu 600 matrixsize 100 iterations in 0.121103 elapsed seconds 178.36 GFlop/s SP ./AxBf-notfused.gpu 700 matrixsize 100 iterations in 0.143003 elapsed seconds 239.855 GFlop/s SP ./AxBf-notfused.gpu 800 matrixsize 100 iterations in 0.173395 elapsed seconds 295.28 GFlop/s
On the GPU the matrix multiplication using doubles should
not exceed matrix size 500x500.
When replacing double with float the matrix size can 800x800.
Fused operations can double the performance measured in GFlops.
The GPU kernel will throw a fault if the matrix cannot fit
in the GPU's grid.
MPI programming has no restriction on the size of the matrix
because MPI threads are not limited to the cores on the MIC,
and one can specify as many threads (even exceeding the MIC's
cores) because MPI manages its threads. This will be seen
in the Chapter about MPI programming.
not exceed matrix size 500x500.
When replacing double with float the matrix size can 800x800.
Fused operations can double the performance measured in GFlops.
The GPU kernel will throw a fault if the matrix cannot fit
in the GPU's grid.
MPI programming has no restriction on the size of the matrix
because MPI threads are not limited to the cores on the MIC,
and one can specify as many threads (even exceeding the MIC's
cores) because MPI manages its threads. This will be seen
in the Chapter about MPI programming.
■ NVIDIA Profiling with nvvp
The command nvvp is NVIDIA visual profiler. It is a useful tool to visualize how the GPU executes a program through the GPU kernel. Do not rely on it to calculate the GPU utilization. The profiler executing the program AxBd.gpu is shown in Figure 4.3.2.
23:25 root@HPMC: /AxBcuda # nvvp ./AxBd.gpu 500 100 1