gpt4 book ai didi

numpy - 如何让 NumPy 在 Ubuntu 中使用 OpenBlas?

转载 作者:行者123 更新时间:2023-12-01 11:33:26 28 4
gpt4 key购买 nike

我同时安装了 BLAS 和 OpenBLAS:

$ 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

但是,NumPy 仍然说 OpenBLAS 不可用:

>> 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

我该如何解决这个问题?

我不认为我可以卸载 libblas3,因为很多东西都依赖于它,包括 libblas-dev,甚至 libopenblas-dev 视情况而定。

我试过了

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

但这没有帮助。

这特别令人惊讶,因为 numpy 中的所有 *.so 文件都链接到 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

最佳答案

在 Ubuntu 16.10 上你可以

$ apt install libopenblas-base

并使用

激活您喜欢的 BLAS 实现
$ update-alternatives --config libblas.so.3

我做到了,跑了

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

使用 libblas(2m38s,仅单核负载)和 libopenblas(0m18s,多核负载)

编辑:这是通过 Ubuntu 的官方存储库安装的 Python 和 numpy,而不是 pip。

关于numpy - 如何让 NumPy 在 Ubuntu 中使用 OpenBlas?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29979539/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com