How to Switch Between Blas Libraries Without Recompiling Program

Is it possible to switch between BLAS libraries without recompiling program?

Sure, you have to have them installed, and on Ubuntu/Debian issue command

update-alternatives --config libblas.so.3

You'll get numbered list of alternatives and could switch between them easily

Link: https://wiki.debian.org/DebianScience/LinearAlgebraLibraries

Generalizing to multiple BLAS/LAPACK Libraries

Most scientific codes that rely on BLAS/LAPACK calls are implementation-agnostic. They usually require that the library is just linked as appropriate.

You've commented that the function prototypes are the same across implementations. This allows you to just have the prototypes in some myblas.h and mylapack.h headers then link whichever library you'd like to use.

It sounds like your primary concern is the implementation-specific stuff that you've utilized for MKL. The solution is to just not use this stuff. For example, the MKL types like MKL_INT are not special. They are C datatypes that have been defined to allow generalize between LP32/LP64/ILP64 libraries which MKL provides. See this table.

Also, stuff like mkl_malloc isn't special. It was introduced before the C standard had a thread-safe aligned alloc. In fact, that is all mkl_malloc is. So instead, just use aligned_alloc, or if you don't want to commit to C11 use _mm_malloc, memalign, etc...

On the other hand, MKL does provide some useful extensions to BLAS/LAPACK which aren't standardized (like transpositions, for example). However, this type of stuff is usually easy to implement with a special case BLAS/LAPACK call or easy enough to implement by yourself. MKL also has internal threading if you choose to use it, however, many BLAS/LAPACK libraries offer this.

what is high performance version of LAPACK and BLAS?

There are plenty of good implementations to pick from:

  1. Intel MKL is likely the best on Intel machines. It's not free though, so that may be a problem.
  2. According to their benchmark, OpenBLAS compares quite well with Intel MKL and is free
  3. Eigen is also an option and has a largish (albeit old) benchmark showing good performance on small matrices (though it's not technically a drop-in BLAS library)
  4. ATLAS, OSKI, POSKI are examples of auto-tuned kernels which will claim to work on many architectures

Generally, it is quite hard to pick one of these without benchmarking because:

  1. some implementations work better on different types of matrices. For example Eigen works better on matrices with small rank (100s)
  2. some are optimised for specific architectures (e.g. Intel's)
  3. in some cases the multithreading of the BLAS library may conflict with a multithreaded application (e.g. OpenBLAS)
  4. developer's benchmarks may tend to emphasise cases which work better on their implementation.

I would suggest pick one or two of these libraries that apply for your use case and benchmark them for your particular application on your particular (or similar) machine. This is quite easy to do even after compiling your code.



Related Topics



Leave a reply



Submit