What, if anything, can be done to optimize performance for modern AMD CPU's?

144 views (last 30 days)
I have a AMD Threadripper CPU. I've seen suggestions that AMD-based computers will benefit from changing the math library from Intel's MKL to the AMD Core Math Library (ACML) along with recommendations to change the BLAS.SPEC file. Any threads relating to this seem quite old and it appears that AMD might have changed the name of its math library.
Is it still possible to optimize the math library for AMD's CPUs? If so, what do I need to do?
Thanks!
  27 Comments
Wick
Wick on 6 Sep 2020
@Ned Flanders; I haven't kept my subscription up so I haven't updated for a while. Sorry.
Taqu3
Taqu3 on 23 Jun 2022
Edited: Taqu3 on 23 Jun 2022
Just got my server with 3995 threadripper pro only to find out it performs worse than my laptop. When this issue will be properly addressed ? It is frustrating (version 2022a).

Sign in to comment.

Accepted Answer

Ned Flanders
Ned Flanders on 18 Nov 2019
Edited: Ned Flanders on 2 Dec 2019
You should read it if you want to understand the background.
EDIT: Before you start I have a short request for you that you could help me with and serve your own interest. Matlab will not implement this. If you think that Matlab should offer a permanent solution that serves all users independent of whether they use Intel or AMD CPUs, please make a feature request at Matlab to implement a nummeric library (e.g. OpenBLAS) that does not discriminate against non Intel CPUs. Mathworks will not make this change without people advocating for it. Thanks!
tl;dr
Solution 1 (Windows): Create a .bat file using e.g. "Notepad" with the following lines to start Matlab in AVX2 Mode.
@echo off
set MKL_DEBUG_CPU_TYPE=5
matlab.exe
Save as .txt and rename to .bat. If you double-click that file, Matlab will start the MKL in AVX2 Mode. If you start it the normal way, it will remain as always.
You can also download the .bat file from my highdrive if you trust me (which typically you should not as I am a random guy from the internet). If you delete the startup batch file provided in the download or the one you created yourself, its gone and your computer will be as it has been before.
Solution 2 (Windows): If you are happy with the results (which you surely will be :-)), you should make the setting permanent by entering MKL_DEBUG_CPU_TYPE=5 into the System Environment Variables. This has several advantages, one of them being that it applies to all instances of Matlab and not just the one opened using the .bat file.
Doing this will make the change permanent and available to ALL Programs using the MKL on your system until you delete the entry again.
LINUX: (Thanks to foreignrobot)
Simply type in a terminal:
export MKL_DEBUG_CPU_TYPE=5
and then run matlab from the same terminal.
For benchmarking, you can use this script:
To make it permanent in Linux edit your shell's configuration scripts (~/.bashrc for bash, ~/.zshrc for zsh etc) adding the line export MKL_DEBUG_CPU_TYPE=5. That'll apply in any newly opened shell and to apply it in an already open one simply do . ~/.bashrc or whatever your config script name is. (Thanks to lowpolybutt)
P.S.: In case you are on an older AMD FX CPU, you could test whether MKL_DEBUG_CPU_TYPE=4 works for you. This should enable AVX, but I haven't tested this.
  15 Comments
Yair Altman
Yair Altman on 17 Dec 2019
@Wick - try setting the Program Files path within quotation marks, as in "C:\Program Files\bla\bla\blas.dll";"C:\Program Files\bla2\bla2\blast.dll"
Aldo Corbellini
Aldo Corbellini on 4 Apr 2020
@Wick - Where did you find BLIS and/or OpenBLAS .dll for win64? I would like to test these libraries on my new AMD TR. All I was able to find are some build recipes to Linux GCC compilers!
[Hi, Yair!]

Sign in to comment.

More Answers (3)

Heiko Weichelt
Heiko Weichelt on 15 Mar 2022
After intense collaboration between MathWorks and AMD, as of MATLAB R2022a, MATLAB ships a custom-built version of AOCL 3.1 that can be activated as described here:
Notice that AOCL versions from other sources might not be configured / built correctly and may cause MATLAB to error, crash, or return incorrect results.

Wick
Wick on 4 Dec 2019
Edited: Wick on 4 Dec 2019
The Accepted Answer by @NedFlanders is the best solution so far. Use that one.
But in the comments of that answer, MathWorks staff member @PatQuillen shared some useful undocumented environment variables that allow anyone to hook into any external BLAS library. This has the potential to be very useful for getting other BLAS packages such as OpenBLAS or BLIS working within MATLAB. Those comments are already buried in that thread so I'm pulling them out as a stand-alone solution. I'll repeat the warning from those comments: "This comes with the same caveats that MathWorks has not qualified our products against alternate BLAS implementations, so as above, we can't confirm that using your own BLAS, such as OpenBLAS, will work correctly throughout our products."
We're going to be setting environment variables for the host operating system. This can be done in a temporary or permanent way outside of MATLAB for both Linux and Windows as can be seen in @NedFlander's reddit thread. However, I'm only going to use the setenv command to set these for only one instance of MATLAB.
MATLAB loads the BLAS library the first time it tries to execute a computation so you can make changes before that point. Once the BLAS library is loaded, there's no way to unload it. You'll have to restart.
The environment variable BLAS_VERBOSITY will set MATLAB to detail information to the Command Window about the loading process. A value of 1 is minimal information, 2 is more.
setenv('BLAS_VERBOSITY','1')
The environment variable BLAS_VERSION, if defined, will direct MATLAB to load the BLAS library from the specified file(s) rather than use its built-in default. The files should be the .so/.dll for the BLAS implementation you plan to use that follows the symbols defined by https://netlib.org/blas/.
setenv('BLAS_VERSION','c:\temp\mkl.dll')
Would load a copy of the MKL library copied into c:\temp. You can use a semicolon, comma, or space to join multiple file locations into a single definition of BLAS_VERSION. So if you're writing your own BLAS that doesn't support all the possible methods you could roll over to MKL as a failsafe, e.g.
  3 Comments

Sign in to comment.


Ken M.
Ken M. on 9 Nov 2019
You are saying don't use windows for matlab.
Since that is the easy way around, people stop complaining about it after the switch.
Many programs just work faster with linux so if speed is important then linux is an obvious choice also for matlab.
  9 Comments
Yavor Dobrev
Yavor Dobrev on 26 Mar 2021
Can you please provide details on how you link the AMD Ubuntu binaries (AOCL). I have tried:
export BLAS_VERSION=/home/dobrev/amd/aocl/3.0-6/lib/libblis.so
However, when use bench I get:
cpu_id: x86 Family 143 Model 96 Stepping 1, AuthenticAMD
BLAS: trying environment...
BLAS: loading /home/dobrev/amd/aocl/3.0-6/lib/libblis.so
BLAS: loaded /home/dobrev/amd/aocl/3.0-6/lib/libblis.so@0x7fcbf7ab2220
BLAS: /home/dobrev/amd/aocl/3.0-6/lib/libblis.so is not a compatibility layer.
I also tried using openBLAS with the same result.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!