24

The theano installation documentation states, that theano will as a default use the BLAS libraries from numpy, if the "BLAS libraries are available as dynamically-loadable libraries". This seems not to be working on my machine, see error message.

  • How do I find out, if the numpy BLAS libraries are availalbe as dynamically-loadable?
  • How do I recompile the numpy BLAS libraries, if they are not dynamically-loadable?

Please indicate, if you would need more information!

Error message

We did not found a dynamic library into the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library. /usr/bin/ld: cannot find -lblas

Appendix

The theano library needs among other things numpy and a BLAS library. I figured numpy comes with BLAS if you install it with sudo apt-get install python-numpy python-scipy under Ubuntu.

This is the filelisting of /usr/lib64/python2.6/dist-packages/scipy/lib/blas

cblas.so  info.py   __init__.py   scons_support.py   setup.py     
fblas.so  info.pyc  __init__.pyc  scons_support.pyc  setup.pyc  
setupscons.py  test
setupscons.pyc

This is the output of distutils.__config__.show() is as follows

blas_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib64']
    language = f77

lapack_info:
    libraries = ['lapack']
    library_dirs = ['/usr/lib64']
    language = f77

atlas_threads_info:
  NOT AVAILABLE

blas_opt_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib64']
    language = f77
    define_macros = [('NO_ATLAS_INFO', 1)]

atlas_blas_threads_info:
  NOT AVAILABLE

lapack_opt_info:
    libraries = ['lapack', 'blas']
    library_dirs = ['/usr/lib64']
    language = f77
    define_macros = [('NO_ATLAS_INFO', 1)]

atlas_info:
  NOT AVAILABLE

lapack_mkl_info:
  NOT AVAILABLE

blas_mkl_info:
  NOT AVAILABLE

atlas_blas_info:
  NOT AVAILABLE

mkl_info:
  NOT AVAILABLE
Framester
  • 33,341
  • 51
  • 130
  • 192

5 Answers5

14

After downloading the Anaconda distro of python libraries, I just encountered the same issue on Ubuntu 12.04 LTS 64-bit. Pointing Theano to the directory containing libblas.so took care of it.

$ THEANO_FLAGS=blas.ldflags="-L/usr/lib/ -lblas" python rbm.py

stewart
  • 189
  • 1
  • 5
  • 2
    I added to my theanorc : [blas] ldflags=-L/usr/lib/ -lblas . The error disappeared. – user27665 Oct 19 '16 at 14:38
  • Yup, this worked for me, you can just set this env variable in your `.bashrc` file. So that you don't need to type the whole thing every time you run a script. – ramgorur Mar 23 '18 at 20:18
3

With ubuntu, in the package manager, libblas.so comes with the libblas3gf package. If somehow it doesn't create libblas.so, but creates libblas.so.X, manually create a symlink like:

cd /usr/lib64
sudo ln -s libblas.so.3gf libblas.so

NB: This has been working fine for me, but read the comment below though. And keep in mind this package will not be optimized to your specific hardware (read other answers that suggest ATLAS for instance).

tiho
  • 6,655
  • 3
  • 31
  • 31
  • 10
    Wrong. Install the corresponding `-dev` package, here `libblas-dev`. – Dirk Eddelbuettel Sep 16 '11 at 17:08
  • Description of libblas-dev says "Basic Linear Algebra Subroutines 3, static library", and it's the shared library that's needed, not the static one. – tiho Sep 16 '11 at 17:57
  • 2
    Sure, but the static library is irrelevant here. What matters is that one should *never* have putz around with a manual softlink as the `-dev` packages install just those. Nothing specific to BLAS here, all Debian/Ubuntu -dev packages work that way. – Dirk Eddelbuettel Sep 16 '11 at 18:03
  • This also worked for me on CentOS as well, though using the actual `*-devel` libraries does seem to be an easier solution. – turtlemonvh Nov 14 '13 at 18:30
2

In your case you should look in /usr/lib64 and see if libblas, etc. are available as .so or .so.X files.

Recompiling BLAS is not trivial, but you can maybe try installing the relevant ATLAS packages for your distribution.

dwf
  • 3,503
  • 1
  • 20
  • 25
1

If a recent enought version of numpy is installed, theano will work correctly in all case­.

From there, the only reason to care about the blas used is about speed. The default blas is very slow. Many distro compile numpy again this slow blas version.

An easy/fast way to have a faster blas implementation is to install the distro package about atlas and atlas devel. This is an optimized blas implementation.

Newer version of Unbuntu, the installation of atlas in done is such a way that numpy will start using it. So there is no need to change anything on Theano about this. I don't know if other distro do this.

The best way to check the blas that Theano use is fast or not is to time it. To do so, run this under bash:

X=`python -c "import theano;import os.path; print os.path.split(theano.__file__)[0]"`
python ${X}/misc/check_blas.py

Then compare the speed it took to run with some other comparison result printed.

jww
  • 97,681
  • 90
  • 411
  • 885
nouiz
  • 5,071
  • 25
  • 21
1

Your main question is essentially one of whether the distro maintainers have the dependencies installing correctly or not -- and for that I don't have an answer or a solution.

However, I do have a recommendation. ATLAS isn't very hard to get to build. Get the source, unpack, ensure you've satisfied its dependencies, then kick off the configure & make steps. The dependency part is probably the most time consuming manual portion of the process.

Of course, then you have to relink numpy, theano, etc. While I recognize this is a pain (believe me, I went through it for both Theano and Hannes Shulz & Andy Mueller's CSV), the benefit you get is a BLAS tuned to run optimally on your hardware.

Brian Vandenberg
  • 4,011
  • 2
  • 37
  • 53
  • "ATLAS isn't very hard to get to build" -- true, but getting good performance out of it is tricky. – dwf Sep 16 '11 at 22:30
  • @dwf - I tend to disagree there. On my first attempt I only tweaked two primary things: ensuring necessary things were setup properly (dependencies & the like), and making sure it used threaded BLAS/ATLAS. Performance on matrix multiplication tasks was then on-par with Matlab out of the box. – Brian Vandenberg Sep 27 '11 at 17:53
  • I suppose the question is whether MATLAB is a very good benchmark (especially if it was a version prior to their bundling MKL, I don't think it was). I tend to go by the author's bundled benchmarks, and I know that getting close to those on a comparable CPU was a bit tricky. – dwf Nov 17 '11 at 18:46