What, if anything, can be done to optimize performance for modern AMD CPU's?
Ältere Kommentare anzeigen
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 Kommentare
Wick
am 11 Mai 2018
MikeCC
am 4 Okt. 2018
Just wondering if you have any updates? My new 2950x threadripper build is way below expectation...I'm talking about 50% more in terms of running time comparing with the i7 6700HQ laptop pc I got.
Wick
am 4 Okt. 2018
Philip Borghesani
am 4 Okt. 2018
I suggest that people who care about this put in an enhancement request with support. This is your typical chicken and egg or squeaky wheel issue. Until there are (large? noisy? pre-sales?) customers who want this, and we know about it, improvement will be a low priority.
For many customers with typical smaller problems less fast cores with MATLAB will beat more slower cores, this does still favor Intel.
Wick
am 24 Mai 2019
Star Strider
am 24 Mai 2019
Bearbeitet: Walter Roberson
am 24 Mai 2019
Submit an enhancement request by using the Contact Us link (the telephone handset icon) in the upper right corner of this page.
I’m definitely hoping for this, since my primary MATLAB machine has a Ryzen 7 1800X.
Wick
am 24 Mai 2019
Star Strider
am 24 Mai 2019
Never say ‘never’!
I’m ‘following’ this post, so I’m eager to see any developments.
Ned Flanders
am 6 Jun. 2019
Bearbeitet: Ned Flanders
am 6 Jun. 2019
The problem does not arise from the AMD CPU but from the Intel MKL library which uses a 'discriminating CPU dispatcher' which does not only discriminate CPUs by their SIMD extensions (e.g. AVX2) but also (and that sucks) by their vendor string. Every CPU that does not report back 'Genuine Intel' will make the dispatcher to use the slowest option excluding for example the use of AVX2 although the CPU supports it.
Thats Intels scummy way to boost their CPU sales.
The only option you have is to use other math libraries than the MKL.
AMD offerst the LibM which includes 128bit and 256bit vector extensions and has recently been updated to version 3.3.0
IMHO Matlab developers should spend some efforts on this given that we are all (well paying) customers and not only people with an Intel CPU.
Ned Flanders
am 6 Jun. 2019
Bearbeitet: Ned Flanders
am 6 Jun. 2019
Maybe you want to address this on a more public social media channel like Twitter and ad some hashtags for visability. This is a widespread problem. Many of us use AMD Ryzen now as they are fantastic of most usecases.
In this case, to my understanding, it would be relatively simple to implement and at least offer an alternative Math Lib like OpenBLAS that includes the libM in Matlab.
Look at Octave... you can choose the Lib when installing it. So why would Matlab not be able to do the same in the interest of their paying customers.
It really should happen!
I am not sure whether it is possible to tweak Matlab to use other libs. I will look into this when I have some more time.
I also dont quite understand how your thread can have 59 views and only 3 vote ups. This should be in everys matlab users unterest to be able to freely chose your hardware.
Ned Flanders
am 15 Nov. 2019
@Wick
In case you are still reading this. I came across this:
I have recently seen some people recommending using MKL on AMD, with the MKL_DEBUG_CPU_TYPE environment variable set to 5, as in:
export MKL_DEBUG_CPU_TYPE=5
This overrides the CPU dispatching in MKL, and forces the AVX2 codepath (the one MKL naturally uses on Intel parts without AVX512), otherwise MKL chooses an unoptimized SSE path with abysmal performance. But with the AVX2 path, MKL performs very well on Zen2, usually even outperforming BLIS and OpenBLAS!
Not sure whether this is possible in Matlab, but if so, you should definately try.
Star Strider
am 15 Nov. 2019
@Ned Flanders — Please enlarge on this, ideally with relevant links that explain this in more detail. (I am not as knowledgable on this as others may be, and need to be brought up to speed.)
Ned Flanders
am 15 Nov. 2019
Bearbeitet: Ned Flanders
am 15 Nov. 2019
I wish I could elaborate on this, but I don't know much about these things either.
Just Google export MKL_DEBUG_CPU_TYPE=5
As many people seem to be using AMD Epyc now, this came up and seems to solve the problem with the MKL on AMD CPUs. What I can't tell is whether this is something you can do or whether this is something Mathworks could patch into Matlab. In anycase... it works. CPU Performance on AMD CPUs is restored that way.
See for example: https://www.phoronix.com/forums/forum/hardware/processors-memory/1126558-amd-epyc-7302-7402-7502-7742-linux-performance-benchmarks?p=1126644#post1126644
Or:
"Note that by default, PyTorch uses the Intel MKL, that gimps AMD processors. In order to prevent that, execute those lines before starting the benchmark:"
"export MKL_DEBUG_CPU_TYPE=5"
To my understanding (which is limited) one could include this in the startup script in Matlab itself, but someone will have to explain the details to us.
Wick
am 15 Nov. 2019
Ned Flanders
am 15 Nov. 2019
Bearbeitet: Ned Flanders
am 15 Nov. 2019
I opened up a reddit thread on this. There are some suggestions.
Maybe you could try:
And no, I believe its only how the mkl is run not compiled. If you run it in this debug mode, it is forced to use AVX2
Here is how to set environment variables for the mkl in windows:
https://software.intel.com/en-us/mkl-windows-developer-guide-setting-environment-variables
We'll get this fixed gentlemen!
Ned Flanders
am 17 Nov. 2019
@Wick
Problem solved!
Enjoy and let me know how it works for you!
Wick
am 17 Nov. 2019
Ned Flanders
am 17 Nov. 2019
Told you! Never give up! hehe
Thanks for the feedback, I reworked the post on reddit accordingly. No download needed anymore. Ideally, if you're happy, use system variables to make the fix permanent. --> see reddit.
So how much do you gain on the TR?
Unfortunately this Debug Mode is undocumented by Intel (for very good reasons i guess... these gangsters)
Wick
am 17 Nov. 2019
Ned Flanders
am 10 Dez. 2019
Bearbeitet: Ned Flanders
am 10 Dez. 2019
@wick
Could you test on your TR whether disabled SMT is faster? Matlab starts one thread per Core (not available thread) on Intel and AMD CPUs and my quick test suggests that SMT off is somewhat faster. (another 5-10%)
Wick
am 12 Dez. 2019
Ned Flanders
am 29 Mär. 2020
@wick
Apparently 2020a includes the Workaround but setting the workaround does not work on all systems reliably yet. Can you confirm it works on your build? You possibly need to remove the sys variable before you upgrade to 2020a.
Ned
Wick
am 6 Sep. 2020
Akzeptierte Antwort
Weitere Antworten (3)
Heiko Weichelt
am 15 Mär. 2022
6 Stimmen
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 Kommentare
Carlo Monjaraz
am 15 Mär. 2022
This is really awesome!!
Ned Flanders
am 15 Mär. 2022
Great news! Thanks for sharing!
3 Kommentare
Rasoul Nikbakht
am 14 Okt. 2020
Could you please elaborate on this comment?
I have an AMD CPU, Ryzen 2970wx, and It seems they have a very efficient implementation of the BLAS library, which they call it BLIS. I would like to change the Matlab default BLAS library (intel) to the AMD one. Currently, even with applying the trick export MKL_DEBUG_CPU_TYPE=5 Matlab on AMD CPU (using Ubuntu 18) is not as fast as it supposed to be.
I think any other library rather than Intel MKL should work fine for AMD CPUS.
Bernhard Wistawel
am 1 Feb. 2021
Hi! Where can I find the instructions for MatLab on Linux (using RHEL)?
Bernhard Wistawel
am 24 Feb. 2021
Will 2021a correct this behaviour? Or let us choose the BLAS distribution?
Ken M.
am 9 Nov. 2019
0 Stimmen
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 Kommentare
Bruno Luong
am 9 Nov. 2019
"Many programs just work faster with linux"
Any evident to back up this claim?
I did a benchmark might be 10 year back and they are comparable.
If you run BENCH on R2019B you'll see the fastest benchmark make by TMW is Windows 7 followed by Linux, though it is not the same HW.
Some compare test from Hardware Unboxed
If you don't mind the change, I wouldn't stay with windows. Overal I think it is a win for everyone. Maybe the main reason is that linux can handle more cores easier.
I also use an astronomy program pixinsight and it also works much faster on linux than windows.
Wick
am 10 Nov. 2019
Mark Smith
am 5 Jan. 2020
Many thanks to Ned Flanders and others that have commented here. I have had some correspondence with Mathworks and indicated to them that Matlab should have optimized binaries for AMD cpus. As a lark, I decided to use the bench command in Win 10 and Kubuntu in various configurations to demonstrate the efficacy of having optimized binaries for AMD cpus. I primarily use Win 10 and am a Linux novice. I was able to get Kubuntu 19.10 installed on a separate drive and ran a few bench commands. I have 5 screen shots showing how use of the environmental variable changes performance in both Win 10 and Kubuntu which I was prevented from uploading. I also downloaded the AMD AOCL precompiled Ubuntu binaries and AMD Math Library (LibM) Ubuntu binary and used those with the bench command.
My machine for these tests is a Threadripper 2950x running on Asrock X399 Pro Gaming motherboard with Gigabyte 1080 Ti. For all these tests, the bios was set to defaults with Precision Boost Overdrive not active (3.5 Ghz base clock). I normally run Win 10 with the 2950x at 4.4 Ghz with powerful custom cooling. All tests were run with 64 GB ram.
The simple summary is that Win 10 is not suited for Matlab with a score of ~55 on the bar chart (below the Surface Pro 3). This is improved to ~75 using the Win 10 environmental variable MKL_DEBUG_CPU_TYPE=5. If I perform bench overclocked to 4.4 Ghz with 32 GB ram, the score goes to ~85. Not much jump for possibly running this fine chip at too high a clock.
For Kubuntu with bios default settings, no overclocking and no setting of MKL_DEBUG_CPU_TYPE=5 prior to starting Matlab results in a score of ~65. Adding export MKL_DEBUG_CPU_TYPE=5 prior to starting Matlab results in a score of ~95, thats right ~95. Adding export commands to link the AMD Ubuntu binaries along with MKL_DEBUG_CPU_TYPE=5 results in a score of ~98. With these changes it is the second ranked machine below entry for Win 7 running on Xeon E5-1650 v3 at 3.5 Ghz.
My takeaway is that if Mathworks major market is tied to Win 10, better math binaries are needed. The simple setting of an environmental variable is not sufficient in Win 10. The great benefit obtained in Linux by just setting the environment variable needs to be explained. I would be interested in knowing what is different between Linux and Win 10 that allows the MKL_DEBUG_CPU_TYPE=5 environmental variable to have such a much better effect in Linux. At this point I infer that Microsoft is also in bed with Intel in hampering AMD performance or just ignorant of the effects of its software on math libraries.
I like Matlab, it is powerful and a major tool in the industry. It needs to be better optimized for different cpu configurations.
Tyler Moskov
am 23 Apr. 2020
Could you go into more detail on adding export commands to link the AMD Ubuntu binaries or post a link on how to?
Thank you
Ken M.
am 24 Apr. 2020
@Tyler as of 2020a the MKL_DEBUG_CPU_TYPE=5 workaround should not longer be needed for AMD CPU's
Tyler Moskov
am 24 Apr. 2020
That's what I've heard, but I still have 2019b and want to see if there are any added benified of using AMD's AOCL.
Yavor Dobrev
am 26 Mär. 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
am 15 Mär. 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:
Kategorien
Mehr zu Historical Contests finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
