Recommended make config for USE_BLAS


#1

I was going through the docs for R for an upcoming update and noticed a sort of arbitrary usage of USE_BLAS=openblas and a note that you could use MKL or ATLAS.

“MXNet uses BLAS library for accelerated numerical computations on CPU machine. There are several flavors of BLAS libraries - OpenBLAS, ATLAS and MKL. In this step we install OpenBLAS. You can choose to install ATLAS or MKL.”

I just added USE_BLAS=openblas to an Ubuntu setup script, and I’m left wondering if that’s the right choice.

What’s is the recommendation for the best performance now?

What are the tradeoffs between each one of these BLAS libraries?


#2

AFAIK, openblas is a better option and faster (in general) than atlas. You can use MKL if your intel chips support it. In MXNet, MKL support is still experimental. Openblas is a safer option overall.


#3

Thanks for the clarification!


#4

Do I need to install LAPACK even if I am using MKL?

Install instructions say:
“You can explore and use more compilation options in make/config.mk”

Is there a set of compilation flags that are recommended for good performance when using on CPU machine or GPU machine or according to architecture etc.?

Thanks


#5

Here is some explanation regarding the BLAS libs. As far as I know MXNet supports following libraries:

  • Atlas
  • OpenBLAS
  • MKL (MKL, MKLML, MKLDNN)
  • Apple Accelerate

Currently there is some confusion about lapack - it checks only for a liblapack.so library regardless of what BLAS library is set and fails silently if it can not find it.

liblapack.so exists indeed for Atlas as a separate library and can be used with it. For OpenBLAS there is no separate lapack library, but the current build script can be tricked by making a symlink to the main library (some ubuntu installations already do that). Apple Accelerate does contain lapack functionality within the framework but the current build script will switch it off (since it’s looking for liblapack.so).

With MKL libraries it’s complicated.

  • MKL is a full library, containing all the functionality. It is free under community support licensing (https://software.intel.com/en-us/articles/free-mkl) but needs to be installed and downloaded manually.

  • MKLML is a subset of MKL. It contains smaller number of functions to reduce the size of the download and reduce the number of dynamic libraries user needs. It can be downloaded automatically by the cmake script, although currently it’s messed up with MKLDNN

  • MKLDNN is a separate open-source library and that can be built completely standalone. But it does support linking with MKLML or full MKL for additional performance. MKLDNN is part of MXNet as a git subrepo and can be built together with MXNet.

Getting lapack functionality with MKL is a challenging task and as of know I haven’t figured out the right way how to link it properly.

Summarizing:

Use MKL (MKLML) as default on intel processors
You can use Accelerate on MAC’s (maybe the performance will be better)
OpenBLAS if you are cross compiling (RPi, Jetson) or on not intel chip (MKL might be better anyway though)
Atlas can be tried instead of OpenBLAS but I don’t know whether it has any advantages

The current build issues with cmake are being worked on and you can track the progress here: https://github.com/apache/incubator-mxnet/pull/11148


#6

Update: Intel documentation provides info that mklml is actually required as libraries and other components that are required to develop Intel MKL-DNN enabled applications. The good news is that we can actually download both MKLDNN and the required MKLML libraries from the mkldnn releases page. This is done by one of the cmake scripts.


#7

Another update: lapack should be available in all cases if you need it and it’s possible:


Also the default order of checking math libraries should be now from most promising to usual.