I have an AMD cpu and I'm trying to run some code that uses Intel-MKL. The code is significantly slower than I expected.
2 Answers
As of 2021, Intel unfortunately removed the MKL_DEBUG_CPU_TYPE
to prevent people on AMD use the workaround presented in the accepted answer. This means that the workaround no longer works, and AMD users have to either switch to OpenBLAS or keep using MKL.
To use the workaround, follow this method:
- Create a
conda
environment withconda
's and NumPy's MKL=2019. - Activate the environment
- Set
MKL_DEBUG_CPU_TYPE
= 5
The commands for the above steps:
conda create -n my_env -c anaconda python numpy mkl=2019.* blas=*=*mkl
conda activate my_env
conda env config vars set MKL_DEBUG_CPU_TYPE=5
And thats it!
-
2(I have not confirmed.) whoa. Intel removing this is significant move by Intel against AMD IMO. thanks for the update... very important news if true. Aug 26, 2021 at 17:24
-
Yes, this is very disappointing for scientists using AMD CPUs. And it doesn't look like Intel is ever gonna give up on "crippling" AMD, in my opinion. My miniconda python uses MKL 2020.3, and I haven't figured out how to get over the "cripple AMD" function, despite searching for weeks. Aug 26, 2021 at 17:37
UPDATE 2021-08-26: you can speed up older versions of MKL from before approximately 2020-08-31. Set the environment variable MKL_DEBUG_CPU_TYPE=5
then run your code.
NOTE: I do not know the exact date or version when Intel removed the environment variable workaround.
FYI this slow down affects anything that uses Intel-MKL library and runs on AMD CPU (i.e. affects all operating systems and affects all programming languages and all programs (older versions of Matlab, C, C++, Python, Anaconda-Python, Machine-Learning like Tensorflow and Pytorch , again anything that uses Intel-MKL library on AMD CPU)).
FYI Setting and getting environment variables is out of scope for this question but here are some helpful links:
- for Windows and another link with screenshots
- personally i do: "old" control panel --> system --> advanced --> environment variables --> system variables --> ceate new
- for Linux here is a general guide
- for the simple case of a
bash
user who wants to set the environment variable just for their own user append the lineexport MKL_DEBUG_CPU_TYPE=5
to your user's.bashrc
file
- for the simple case of a
p.s.
regarding the question "why/how does setting an environment variable cause code to run significantly faster?"
- The default behavior is for the Intel-MKL to check the CPU and run slower code if non-intel is detected.
- Setting the environment variable overrides the default behavior and causes the faster code to execute despite not having Intel hardware.
You are probably wondering "why would Intel have a software slow-down in their MKL library?
- Intel for many years had their compiled code check the CPU first then if the CPU was detected as non-intel the code would choose to run slower code
- there was a lawsuit
- a result of the lawsuit was that Intel had to disclose what they were doing but did not have to stop what they were doing
- here's the wiki page with more history and information: https://en.wikipedia.org/wiki/Intel_C%2B%2B_Compiler#Reception
-
2The detail, that the slow non-intel path uses SSE, while the faster path (triggered by MKL_DEBUG_CPU_TYPE=5) uses AVX2 is probably worth mentioning...– eadAug 3, 2020 at 13:22
-
@ead Given that Intel-MKL is closed-source software, I can't look at the code and so I can't make any claims about specifics other than the observation that it runs slower. Aug 3, 2020 at 13:49
-
There is no need to look into the code:
perf
tells everything one needs to know... While the trivia isn't uninteresting, it is too abstract to really understand what is the difference.– eadAug 3, 2020 at 14:21 -
@ead i've never used
perf
so that's amazing you can figure out something like this using open-source tools. Aug 3, 2020 at 14:30
Intel optimizations, for Intel compilers or other products, may not optimize to the same degree for non-Intel products.
. this new one is much more concise and readable (the old one was 10-20x longer, was an image containing text, and was written for lawyers (i.e. not layman)). it is disappointing that the old notice URL just stopped working tho.