- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd like to use oneMKL in some of my projects and I'm starting to do some basic routine to understand how to use the library.
Here my MWE:
#include "mkl.h"
int main()
{
double A[3][3],
B[3][3],
C[3][3];
// some initialisation
for (size_t row = 0; row < 3; row++)
for (size_t col = 0; col < 3; col++)
{
A[row][col] = 10*(double)row+1;
B[row][col] = 0;
C[row][col] = 7;
}
for (size_t i = 0; i < 3; i++)
B[i][i] = 1+(double)i;
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3,
1, (double*)&A, 3, (double*)&B, 3, 0, (double*)&C, 3);
}
My configuration is:
- Windows 10
- Visual Studio 2019 16.11.19
- oneMKL 2022.0
I'm compiling both with MS compiler (v142 toolset) and the Intel C++ compiler 2022.
in terms of include and library directories, I'm using the $(oneMKLIncludeDir) and the $(oneMKLLibDir) macros and I'm adding the following libraries:
- mkl_intel_ilp64.lib (I've also changed it to the lp64 version with identical behaviour)
- mkl_sequential.lib
- mkl_core.lib
- libiomp5md.lib
All of the above doesn't seem to cause any issue because when I try to run it without the direct call everything works fine (with both compilers). Putting a breakpoint at the end and looking at the result, shows that dgemm is correctly executed.
However, my applications are mainly related to small matrices and vectors (at least for BLAS libraries); therefore, I'm interested in the direct call functionality.
If I try to activate it, building using the MS compiler fails with this error:
MWE.cpp(19,5): error C2440: 'initializing': cannot convert from 'const char [2]' to 'char *'
MWE.cpp(19,5): message : Conversion from string literal loses const qualifier (see /Zc:strictStrings)
Building with the Intel compiler succeeds, even though I get this error:
a value of type "const char *" cannot be used to initialize an entity of type "char *"
and in the build output I see these warnings:
1>MWE.cpp(19,5): : warning : ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
1> cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3, 1, (double*)&A, 3, (double*)&B, 3, 0, (double*)&C, 3);
1> ^
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(637,83): note: expanded from macro 'cblas_dgemm'
1>#define cblas_dgemm(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc) MKL_DC_CBLAS_DGEMM_CONVERT(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, mkl_dc_dgemm, dgemm_direct)
1> ^
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(494,26): note: expanded from macro 'MKL_DC_CBLAS_DGEMM_CONVERT'
1> char *ftrans[] = { "N", "T", "C"};\
1> ^
1>MWE.cpp(19,5): : warning : ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(637,83): note: expanded from macro 'cblas_dgemm'
1>#define cblas_dgemm(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc) MKL_DC_CBLAS_DGEMM_CONVERT(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, mkl_dc_dgemm, dgemm_direct)
1> ^
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(494,31): note: expanded from macro 'MKL_DC_CBLAS_DGEMM_CONVERT'
1> char *ftrans[] = { "N", "T", "C"};\
1> ^
1>MWE.cpp(19,5): : warning : ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(637,83): note: expanded from macro 'cblas_dgemm'
1>#define cblas_dgemm(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc) MKL_DC_CBLAS_DGEMM_CONVERT(layout, ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, mkl_dc_dgemm, dgemm_direct)
1> ^
1>C:\Program Files (x86)\Intel\oneAPI\mkl\2022.0.0\include/mkl_direct_call.h(494,36): note: expanded from macro 'MKL_DC_CBLAS_DGEMM_CONVERT'
1> char *ftrans[] = { "N", "T", "C"};\
1> ^
1>3 warnings generated.
1>Done building project "MWE.vcxproj".
To my understanding, the problem seems to be in how the argument for the matrix transposition is generated in mkl_direct_call.h on line 494.
If I try to change that line from the original:
char *ftrans[] = { "N", "T", "C"};\
to this modified version:
char Nchar = 'N';char Tchar = 'T';char Cchar = 'C';char *ftrans[] = { &Nchar, &Tchar, &Cchar};\
everything seems to work with both compiler without any warning being generated, as when the direct call isn't used.
Why do I see this behaviour? I mean, I understand why the compiler is throwing warnings because of the way line 494 is written, but:
- Am I missing some step in my setup?
- Is this a genuine bug in the direct call functionality?
- Am I going against some limitation in terms of which C (and C++) standard is allowed with MKL?
Moreover, this seems to be the default way the transposition argument is created in the entire mkl_direct_call.h, so I think I'm not the first one to encounter this issue and I'm struggling to understand what I'm missing.
Thanks for your attention,
Cesare
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for posting on Intel communities.
With the shared reproducer, we were able to compile and build successfully using Intel C++ compiler as well as the Visual Studio compiler. Attached are the screenshots for your reference.
Could you please let us know if we are missing anything? or Kindly get back to us with an updated source if there is a source mismatch.
Best Regards,
Shanmukh.SS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Shanmukh,
thanks for your reply.
I confirm that I cannot sort this issue. Based on the fact that in your screenshot cblas_dgemm is linted as main, I think that you aren't using the direct call functionality.
My understanding is that to activate it MKL_DIRECT_CALL_SEQ has to be added in the Preprocessor Definitions. When I do that, cblas_dgemm changes its colour and I get the error (and I can't compile it anymore with the MSVS compiler).
I've attached my solution folder in the zip file below, if you want to test it with my exact codebase.
Thanks!
Cesare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you please try running the same code under the C extension, as using the c extension activates MKL_DIRECT_CALL feature and let us know if the issue persists? We recommend you get through the below link for more details regarding improving performance for small-size parameters.
Best Regards,
Shanmukh.SS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
changing the file from .cpp to .c allows me to run the example:C version without error
However, in the .cpp version of the code you can see how the function colour is different respect to the main function; why was it the same in your examples? I get dgemm to be the same colour of main only when I'm not activating the direct call functionality, were you using it in your example?
C++ version showing the error
Thanks,
Cesare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
It's a limitation for using the MKL_DIRECT_CALL feature for being used in C applications and Fortran applications. Kindly go through the below link for more details regarding activating the feature and its applicability.
Please refer below link for MKL_DIRECT_CALL in C Applications:
Best Regards,
Shanmukh.SS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
A gentle reminder:
Has the information provided helped? Kindly let us know if you need any other information.
Best Regards,
Shanmukh.SS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Cesare,
We assume that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.
Best Regards,
Shanmukh.SS

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page