Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7016 Discussions

Simple vs CBLAS Matrix-Matrix Multiplication

sicb0161
Beginner
390 Views

Hi all,

using the evaluation version of the MKL, i have tested the accuracy of the matrix - matrix multiplication results of the sgemmby comparing them with the "simple" matrix - matrix multiplication. Simple here means:

float sum;
for (unsigned int i = 0; i < hA; ++i){
for (unsigned int j = 0; j < wB; ++j) {
sum = 0;
for (unsigned int k = 0; k < wA; ++k) {
sum += A[i * wA + k] * B[k * wB + j];
}
C[i * wB + j] = sum;
}
}

Comparing the results of the simple version and the MKL sgemm version, the failure percentage of sgemm lies in the range of 80% to 95 % with an average error of ca. 0.8 *10e-3 with randomly generated matrices uing the rand function from the stdlib.h and the matrix dimension 4096x4096.

Does someone know why the error precentage and the average error is that high ?

thanks in advance!

0 Kudos
3 Replies
TimP
Honored Contributor III
390 Views

If you are using compiler options which effectively force your C source to use K&R style double evaluation, you should get much better accuracy than you would get by optimizing for speed.

You would optimize for speed by using default int counters, and Intel compiler vectorizing options such as -xN. Then, you could regain accuracy at some cost in performance, by explicitly promoting to double, declaring

double sum

and

A[]* (double) B[]

0 Kudos
sicb0161
Beginner
390 Views
Maybe I don'T get your point, but my problem is not that the simple matrix-matrix multiplication method is producing errors but the much faster version sgemm using the Math Kernel Library from Intel.

So, I would like to know how to determine the accuracy of the already implemented sgemm MKL methods.

thanks
0 Kudos
Intel_C_Intel
Employee
390 Views

It's not clear to me what you mean by "error". Certainly one way to measure the error would be to convert the single precision array to a double precision array and run dgemm, and then check the results of MKL sgemm against the double precision values. Since MKL BLAS functions are tested with the standard xBLATn tests, and pass those, I would be surprised if the test I just suggested would show anything surprising. In xBLATn, x is the precision (in this case S) and n is the level of the BLAS, in this case 3.

Please clarify how you measured the error. Using the "simple" case is not an adequate test since you do not know its properties.

Bruce

0 Kudos
Reply