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

101 ビュー (過去 30 日間)
Wick
Wick 2018 年 4 月 20 日
編集済み: Taqu3 2022 年 6 月 23 日
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 件のコメント
Wick
Wick 2020 年 9 月 6 日
@Ned Flanders; I haven't kept my subscription up so I haven't updated for a while. Sorry.
Taqu3
Taqu3 2022 年 6 月 23 日
編集済み: Taqu3 2022 年 6 月 23 日
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).

サインインしてコメントする。

採用された回答

Ned Flanders
Ned Flanders 2019 年 11 月 18 日
編集済み: Ned Flanders 2019 年 12 月 2 日
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 件のコメント
Yair Altman
Yair Altman 2019 年 12 月 17 日
@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 2020 年 4 月 4 日
@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!]

サインインしてコメントする。

その他の回答 (3 件)

Heiko Weichelt
Heiko Weichelt 2022 年 3 月 15 日
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 件のコメント
Carlo Monjaraz
Carlo Monjaraz 2022 年 3 月 15 日
This is really awesome!!
Ned Flanders
Ned Flanders 2022 年 3 月 15 日
Great news! Thanks for sharing!

サインインしてコメントする。


Wick
Wick 2019 年 12 月 4 日
編集済み: Wick 2019 年 12 月 4 日
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 件のコメント
Bernhard Wistawel
Bernhard Wistawel 2021 年 2 月 1 日
Hi! Where can I find the instructions for MatLab on Linux (using RHEL)?
Bernhard Wistawel
Bernhard Wistawel 2021 年 2 月 24 日
Will 2021a correct this behaviour? Or let us choose the BLAS distribution?

サインインしてコメントする。


Ken M.
Ken M. 2019 年 11 月 9 日
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 件のコメント
Yavor Dobrev
Yavor Dobrev 2021 年 3 月 26 日
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 2022 年 3 月 15 日
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:

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by