How to make sure the numpy BLAS libraries are available as dynamically-loadable libraries?
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_mac开发者_运维技巧ros = [('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
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
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).
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.
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.
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.
精彩评论