How can I make NumPy use OpenBlas in Ubuntu?

a 夏天 提交于 2019-12-07 15:42:43

问题


I have both BLAS and OpenBLAS installed:

$ dpkg -l \*blas\* | grep ^i
ii  libblas-dev                                           1.2.20110419-7                                      amd64        Basic Linear Algebra Subroutines 3, static library
ii  libblas3                                              1.2.20110419-7                                      amd64        Basic Linear Algebra Reference implementations, shared library
ii  libopenblas-base                                      0.2.8-6ubuntu1                                      amd64        Optimized BLAS (linear algebra) library based on GotoBLAS2
ii  libopenblas-dev                                       0.2.8-6ubuntu1                                      amd64        Optimized BLAS (linear algebra) library based on GotoBLAS2

However, NumPy still says that OpenBLAS is not available:

>> np.__config__.show()
blas_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib']
    language = f77
lapack_info:
    libraries = ['lapack']
    library_dirs = ['/usr/lib']
    language = f77
atlas_threads_info:
  NOT AVAILABLE
blas_opt_info:
    libraries = ['blas']
    library_dirs = ['/usr/lib']
    language = f77
    define_macros = [('NO_ATLAS_INFO', 1)]
atlas_blas_threads_info:
  NOT AVAILABLE
openblas_info:
  NOT AVAILABLE
lapack_opt_info:
    libraries = ['lapack', 'blas']
    library_dirs = ['/usr/lib']
    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

How can I fix this?

I don't think I can just uninstall libblas3, beacuse many things depend on it, including libblas-dev, on which even libopenblas-dev depends.

I tried

$ sudo apt-get install --reinstall python-numpy

but this didn't help.

This is especially surprising, because all of the *.so files in numpy link to OpenBLAS:

$ ldd `find /usr/lib/python2.7/dist-packages/numpy -name \*\.so` | grep libblas
        libblas.so.3 => /usr/lib/libblas.so.3 (0x00007fba2ac96000)
        libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f04f7f54000)
        libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f9a941a9000)

$ ls -l /usr/lib/libblas.so.3 /etc/alternatives/libblas.so.3
lrwxrwxrwx 1 root root 35 Oct 22  2014 /etc/alternatives/libblas.so.3 -> /usr/lib/openblas-base/libblas.so.3
lrwxrwxrwx 1 root root 30 Oct  6  2014 /usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3

回答1:


On Ubuntu 16.10 you can just

$ apt install libopenblas-base

and activate your prefered implementation of BLAS using

$ update-alternatives --config libblas.so.3

I did it and ran

import numpy as np
a1 = np.random.rand(10000, 10000)
a2 = np.random.rand(10000, 10000)
np.dot(a1, a2)

with libblas (2m38s, single core load only) and libopenblas (0m18s, multi core load)

EDIT: This was with Python and numpy installed through Ubuntu's official repositories and not with pip.




回答2:


Based on the ldd output, NumPy must already be linked with OpenBLAS. It just doesn't know it, because it's linked via /usr/lib/libblas*, which it sees as generic BLAS.



来源:https://stackoverflow.com/questions/29979539/how-can-i-make-numpy-use-openblas-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!