17
$\begingroup$

I personally do not have an AMD CPU but since they are literally becoming quite hot these days, I thought whether the following fix (as proposed here: https://www.reddit.com/r/matlab/comments/dxn38s/howto_force_matlab_to_use_a_fast_codepath_on_amd/) would bypass the Intel CPU check. Perhaps this could allow the AVX2 instruction set to be used for AMD CPUs. So, anyone with an AMD CPU can check whether the fix works !

Create and save a batch (.bat) file as shown below (this is for windows only, check the link above for Linux). Make sure Mathematica folder is in your environment variables.

@echo off
set MKL_DEBUG_CPU_TYPE = 5
Mathematica.exe

Run the batch file to launch Mathematica and execute some code that relies on MKL (a lot of Mathematica functions for numerics rely on it). Compare the execution speed of the code now by launching Mathematica normally (i.e. without batch file).

Do you note any differences?

$\endgroup$
16
$\begingroup$

You may notice some improvement depending on your CPU and which parts of MKL are being heavily used by your code.

On average, the speedup I observed in testing with a slightly older, middle of the lineup CPU (Ryzen 7 1700) was about 15%.

Note that this is an unofficial backdoor, presumably intended for debugging. It is not supported by Intel or by Wolfram Research, so any problems that you may encounter are at your own risk.

Furthermore, this setting no longer has any effect as of MKL 2020 update 1.

$\endgroup$
5
  • 1
    $\begingroup$ many thanks for providing an answer. Do you think Mathematica could be run faster on AMD for upcoming Mathematica versions. That is, if such a bypass exist for newer MKL updates. $\endgroup$ – Ali Hashmi May 13 '20 at 13:47
  • 2
    $\begingroup$ Doesn't exist to my knowledge, but regardless, any questions about the MKL performance on specific CPUs are best directed to the library vendor. $\endgroup$ – ilian May 13 '20 at 14:30
  • $\begingroup$ It would be interesting to see if there's any speedup with KVM-enabled QEMU to which you pass -cpu Haswell or newer arch with this MKL 2020 update. This should make the cpuid instruction give Intel-like output, and the question then becomes whether virtualization overhead beats the optimizations of MKL. $\endgroup$ – Ruslan May 14 '20 at 13:33
  • $\begingroup$ @ilian If AMD releases its own optimized libraries for Ryzen processors, do you imagine Wolfram would use those? Many folks (like me) want to know if Wolfram is making a sincere effort to optimize performance on the newer AMD hardware that has been coming out. $\endgroup$ – Todd Allen May 14 '20 at 17:54
  • $\begingroup$ If there is a library outperforming MKL (on any hardware) I see no reason not consider it. $\endgroup$ – ilian May 14 '20 at 18:37
3
$\begingroup$

Yes, I used this command in Linux(amd ryzen 5 3600): export MKL_DEBUG_CPU_TYPE=5.

This is my results before:

    {"MachineName" -> "kobra", "System" -> "Linux x86 (64-bit)", 
     "BenchmarkName" -> "WolframMark", "FullVersionNumber" -> "11.3.0", 
     "Date" -> "December 5, 2020", "BenchmarkResult" -> 3.067, "TotalTime" -> 4.513, "Results" -> {{"Data Fitting", 0.211}, {"Digits of Pi", 0.199}, 
       {"Discrete Fourier Transform", 0.195}, {"Eigenvalues of a Matrix", 0.372}, 
       {"Elementary Functions", 0.221}, {"Gamma Function", 0.278}, 
       {"Large Integer Multiplication", 0.279}, {"Matrix Arithmetic", 0.096}, 
       {"Matrix Multiplication", 0.447}, {"Matrix Transpose", 0.418}, 
       {"Numerical Integration", 0.364}, {"Polynomial Expansion", 0.056}, 
       {"Random Number Sort", 0.722}, {"Singular Value Decomposition", 0.307}, 
       {"Solving a Linear System", 0.348}}}

and after:

{"MachineName" -> "kobra", "System" -> "Linux x86 (64-bit)", 
 "BenchmarkName" -> "WolframMark", "FullVersionNumber" -> "11.3.0", 
 "Date" -> "December 5, 2020", "BenchmarkResult" -> 3.694, "TotalTime" -> 3.747, 
 "Results" -> {{"Data Fitting", 0.211}, {"Digits of Pi", 0.197}, 
   {"Discrete Fourier Transform", 0.192}, {"Eigenvalues of a Matrix", 0.268}, 
   {"Elementary Functions", 0.218}, {"Gamma Function", 0.273}, 
   {"Large Integer Multiplication", 0.278}, {"Matrix Arithmetic", 0.1}, 
   {"Matrix Multiplication", 0.121}, {"Matrix Transpose", 0.429}, 
   {"Numerical Integration", 0.328}, {"Polynomial Expansion", 0.061}, 
   {"Random Number Sort", 0.732}, {"Singular Value Decomposition", 0.156}, 
   {"Solving a Linear System", 0.183}}}

As you can see, the result is much better 3 vs 3.7. Especially, it is noticable in the operations with matrices(Matrix multiplication gains in 4 times!).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.