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

DGEMM inconsistent result

Viet-Duc
Novice
977 Views

 

  • Library version: 2021.3
  • OS info and version: CentOS 7.9.2009
  • Compiler verison: icc version 2021.3.0 (gcc version 4.8.5 compatibility)
  • MKL linking command:
icc -O2 -std=c11 -mkl=sequential -L$MKLROOT/lib/intel64 dgemm.c -o dgemm.x

 

Dear Support Team,

I am measuring performance of matrix multiplication using dgemm().

The code to reproduce the issue is attached. dgemm() was invoked as following:

dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);

The example is a simple 3x3 multiplication. In the source code, there are two ways to initialize A and B. I marked these two methods with approriate comments in the file.

  • Double casting of interger: this gives correct C
  • Random number between (0,1]: this gives incorrect C

To rule out the possibility of thread interference, I linked with the sequential version of the library. 

The file 'correct.txt' is the expected output for randomized input matrices.

The file 'incorrect.txt' is the result I obtained with dgemm() for randomized input matrices

I appreciate if you can point me to the origin of this inconsistency.

(For some reason, I could not attach the files using forum, I appologize for the inconvenience)

0 Kudos
1 Solution
VidyalathaB_Intel
Moderator
908 Views

Hi,

 

Thanks for reaching out to us.

 

We tried the provided code from our end and could reproduce the results which you are getting.

 

But here are some observations:

 

To check the results we used cblas_dgemm where you will get an option to change the matrix layout (Row Major or Col Major)

 

Here is the function call

 

 

cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);

 

 

By using the above function call, we observed it is giving the correct result (matches with your expected result)

 

 

cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);

 

 

whereas the above function call gives the output which matches with your incorrect result.

 

VidyalathaB_Intel_0-1634017870163.png

 

>>dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);

 

By default dgemm follows the matrix layout as column-major, hence there is a mismatch in your expected and actual results.

 

Please find the attached file for the code snippet we have tried.

Hope the provided information helped.

 

Regards,

Vidya.

 

View solution in original post

0 Kudos
3 Replies
VidyalathaB_Intel
Moderator
909 Views

Hi,

 

Thanks for reaching out to us.

 

We tried the provided code from our end and could reproduce the results which you are getting.

 

But here are some observations:

 

To check the results we used cblas_dgemm where you will get an option to change the matrix layout (Row Major or Col Major)

 

Here is the function call

 

 

cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);

 

 

By using the above function call, we observed it is giving the correct result (matches with your expected result)

 

 

cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);

 

 

whereas the above function call gives the output which matches with your incorrect result.

 

VidyalathaB_Intel_0-1634017870163.png

 

>>dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);

 

By default dgemm follows the matrix layout as column-major, hence there is a mismatch in your expected and actual results.

 

Please find the attached file for the code snippet we have tried.

Hope the provided information helped.

 

Regards,

Vidya.

 

0 Kudos
Viet-Duc
Novice
887 Views

Dear Vidya,

 

Thanks for the detailed answer and test. I am able to obtain correct result using cblas_dgemm as you suggested.

 

Regards.

0 Kudos
VidyalathaB_Intel
Moderator
882 Views

Hi,


Thanks for accepting our solution.

As this issue is resolved, we are closing this thread. Please post a new question if you need any additional information from Intel as this thread will no longer be monitored.


Have a Good Day!


Regards,

Vidya.


0 Kudos
Reply