Can I switch between BLAS libraries without recompiling the program?

For example, can I Atlas , OpenBlas , MKL installed on my Ubuntu 14.04 at the same time and switch between them without recompiling Caffe

+7
c ++ linux blas caffe openblas
source share
3 answers

Of course you have to install them, but in the Ubuntu / Debian team

update-alternatives --config libblas.so.3 

You will receive a numbered list of alternatives and you can easily switch between them.

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

+6
source share

Yes, you can. You just need to use dynamic linking of libraries. libblas.so.3 is a soft connection to /etc/alternatives/libblas.so.3 Which in turn indicates the implementation of the BLAS library

For example, if you install Atlas ( sudo apt-get install libatlas3-base ):

 /usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3 /etc/alternatives/libblas.so.3 -> /usr/lib/atlas-base/atlas/libblas.so.3 

and after installing Openblas ( sudo apt-get install libopenblas-base ):

 /usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3 /etc/alternatives/libblas.so.3 -> /usr/lib/openblas-base/libblas.so.3 

Of course, you can use your own soft link to build your library.

+5
source share

You can also do this without changing the system settings, for example, adding the library you want to use to the environment variables LD_PRELOAD or LD_LIBRARY_PATH . The first library on this path will be the one used to resolve characters.

For example, you can run with

 LD_PRELOAD=/path/to/blas/lib.so ./my_executable_using_caffe 

You can see that this approach would be extremely useful as part of a benchmarking script for different implementations, as it does not affect the benchmarking environment. For example (in bash):

 my_libraries=/path/to/blas1.so /path/to/blas2.so for lib in $my_libraries do LD_PRELOAD=${lib} ./my_executable_using_caffe done 

This dynamic linking approach applies to any other shared library your program is compiled with.

+5
source share

All Articles