Linux 如何确保 numpy BLAS 库可用作可动态加载的库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6789368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make sure the numpy BLAS libraries are available as dynamically-loadable libraries?
提问by Framester
The theano installation documentationstates, that theanowill 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.
该theano安装文档状态,即theano将作为默认使用BLAS库从numpy的,如果“BLAS库可为动态加载库”。这似乎不适用于我的机器,请参阅错误消息。
- 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?
- 我如何确定 numpy BLAS 库是否可以动态加载?
- 如果 numpy BLAS 库不可动态加载,我该如何重新编译它们?
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
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 theanolibrary 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.
该theano除其他事项外库的需求与NumPy和BLAS库。如果你sudo apt-get install python-numpy python-scipy
在 Ubuntu 下安装它,我认为 numpy 带有 BLAS 。
This is the filelisting of /usr/lib64/python2.6/dist-packages/scipy/lib/blas
这是文件列表 /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
这是输出distutils.__config__.show()
如下
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
回答by dwf
In your case you should look in /usr/lib64
and see if libblas
, etc. are available as .so
or .so.X
files.
在你的情况,你应该照照/usr/lib64
,看看是否libblas
等可作为.so
或.so.X
文件。
Recompiling BLAS is not trivial, but you can maybe try installing the relevant ATLAS packages for your distribution.
重新编译 BLAS 并非易事,但您可以尝试为您的发行版安装相关的 ATLAS 包。
回答by tiho
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:
对于 ubuntu,在包管理器中,libblas.so 附带了 libblas3gf 包。如果不知何故它不创建 libblas.so,而是创建 libblas.so.X,请手动创建一个符号链接,如:
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).
注意:这对我来说效果很好,但请阅读下面的评论。请记住,此软件包不会针对您的特定硬件进行优化(例如,请阅读其他建议使用 ATLAS 的答案)。
回答by nouiz
If a recent enought version of numpy is installed, theano will work correctly in all case-.
如果安装了最新的 numpy 版本,theano 将在所有情况下正常工作-。
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.
从那里开始,关心使用的 blas 的唯一原因是速度。默认的 blas 非常慢。许多发行版再次编译 numpy 这个缓慢的 blas 版本。
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.
实现更快 blas 的一种简单/快速的方法是安装有关 atlas 和 atlas devel 的发行版软件包。这是一个优化的 blas 实现。
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.
较新版本的 Unbuntu,在安装完图集后,numpy 将开始使用它。因此,无需在 Theano 上对此进行任何更改。我不知道其他发行版是否这样做。
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:
检查 Theano 使用的 blas 是否快的最好方法是计时。为此,请在 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.
然后将运行速度与打印的其他一些比较结果进行比较。
回答by Brian Vandenberg
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 manualportion of the process.
不过,我有一个建议。ATLAS 并不难构建。获取源代码,解压缩,确保您已满足其依赖项,然后开始配置和制作步骤。依赖部分可能是流程中最耗时的手动部分。
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.
当然,然后你必须重新链接 numpy、theano 等。虽然我认识到这是一个痛苦(相信我,我为 Theano 和 Hannes Shulz & Andy Mueller 的 CSV 都经历了它),你得到的好处是 BLAS 调整到在您的硬件上以最佳方式运行。
回答by stewart
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.
下载了 python 库的 Anaconda 发行版后,我刚刚在 Ubuntu 12.04 LTS 64 位上遇到了同样的问题。将 Theano 指向包含 libblas.so 的目录就解决了这个问题。
$ THEANO_FLAGS=blas.ldflags="-L/usr/lib/ -lblas" python rbm.py
$ THEANO_FLAGS=blas.ldflags="-L/usr/lib/ -lblas" python rbm.py