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

137 vues (au cours des 30 derniers jours)
Wick
Wick le 20 Avr 2018
Modifié(e) : Taqu3 le 23 Juin 2022
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 commentaires
Wick
Wick le 6 Sep 2020
@Ned Flanders; I haven't kept my subscription up so I haven't updated for a while. Sorry.
Taqu3
Taqu3 le 23 Juin 2022
Modifié(e) : Taqu3 le 23 Juin 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).

Connectez-vous pour commenter.

Réponse acceptée

Ned Flanders
Ned Flanders le 18 Nov 2019
Modifié(e) : Ned Flanders le 2 Déc 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 commentaires
Yair Altman
Yair Altman le 17 Déc 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 le 4 Avr 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!]

Connectez-vous pour commenter.

Plus de réponses (3)

Heiko Weichelt
Heiko Weichelt le 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.
  2 commentaires
Carlo Monjaraz
Carlo Monjaraz le 15 Mar 2022
This is really awesome!!
Ned Flanders
Ned Flanders le 15 Mar 2022
Great news! Thanks for sharing!

Connectez-vous pour commenter.


Wick
Wick le 4 Déc 2019
Modifié(e) : Wick le 4 Déc 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 commentaires
Bernhard Wistawel
Bernhard Wistawel le 1 Fév 2021
Hi! Where can I find the instructions for MatLab on Linux (using RHEL)?
Bernhard Wistawel
Bernhard Wistawel le 24 Fév 2021
Will 2021a correct this behaviour? Or let us choose the BLAS distribution?

Connectez-vous pour commenter.


Ken M.
Ken M. le 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 commentaires
Yavor Dobrev
Yavor Dobrev le 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.
Heiko Weichelt
Heiko Weichelt le 15 Mar 2022
As of MATLAB R2022a, MATLAB ships a version of AOCL 3.1 that AMD custom-build for MATLAB. It can be activated as described here:

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by