如何在 NumPy 和 SciPy 中检查 BLAS/LAPACK 链接?

我正在基于 blas 和 lapack 或多或少基于 这个构建我的 numpy/scipy 环境。

完成之后,如何检查 numpy/spyy 函数是否真的使用了之前构建的 blas/lapack 功能?

89170 次浏览

您可以使用链接加载器依赖项工具来查看构建的 C 级钩子组件,并查看它们是否对您选择的 blas 和 lapack 具有外部依赖项。我现在不在 linux 机器附近,但是在 OS X 机器上,你可以在站点包目录下安装:

$ otool -L numpy/core/_dotblas.so
numpy/core/_dotblas.so:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 268.0.1)


$ otool -L scipy/linalg/flapack.so
scipy/linalg/flapack.so (architecture i386):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 242.0.0)
scipy/linalg/flapack.so (architecture ppc):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)


$ otool -L scipy/linalg/fblas.so
scipy/linalg/fblas.so (architecture i386):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 242.0.0)
scipy/linalg/fblas.so (architecture ppc):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)

在 gnu/Linux 系统上用 ldd代替 otool,您应该会得到所需的答案。

你要寻找的是: 系统信息

我用 atlas 编译了 numpy/scipy,我可以用以下方法检查:

import numpy.distutils.system_info as sysinfo
sysinfo.get_info('atlas')

有关更多命令,请查看文档。

方法 numpy.show_config()(或 numpy.__config__.show())输出在构建时收集的关于链接的信息。我的输出是这样的。我想这意味着我正在使用随 Mac OS 附带的 BLAS/LAPACK。

>>> import numpy as np
>>> np.show_config()


lapack_opt_info:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
extra_compile_args = ['-msse3']
define_macros = [('NO_ATLAS_INFO', 3)]
blas_opt_info:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
define_macros = [('NO_ATLAS_INFO', 3)]

你可使用 show_config():

import numpy as np
np.show_config()

对我来说,输出是:

mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
blas_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
blas_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
lapack_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
lapack_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']

如果你安装了 anaconda-导航器(在 linux,Windows 或 macOS 的 www.anaconda.com/anaconda/install/)-blas,scypy 和 numpy 都会被安装,你可以通过点击导航器主页左侧的“环境”选项卡来查看它们(按 alpha 顺序查找每个目录)。安装完整的蟒蛇(相对于 miniconda 或单独的软件包而言)将负责安装数据科学所需的许多基本软件包。