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

时间:2012-01-25 09:15:34

标签: python numpy scipy lapack blas

我正在建立我的基于blas和lapack的numpy / scipy环境或多或少基于this遍历。

当我完成后,如何检查我的numpy / scipy函数是否确实使用了之前构建的blas / lapack功能?

6 个答案:

答案 0 :(得分:280)

方法numpy.__config__.show()输出有关在构建时收集的链接的信息。我的输出看起来像这样。我认为这意味着我正在使用Mac OS附带的BLAS / LAPACK。

>>>import numpy as np
>>>np.__config__.show()

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

答案 1 :(得分:29)

您要搜索的是: system info

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

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

查看文档以获取更多命令。

答案 2 :(得分:11)

由于它使用动态加载的版本,您可以这样做:

$ ldd anyoftheCmodules.so

anyoftheCmodules.so可以是numpy/core/_dotblas.so,例如libblas.so,链接到{{1}}。

答案 3 :(得分:8)

您可以使用链接加载程序依赖项工具来查看构建的C级钩子组件,并查看它们是否对您选择的blas和lapack具有外部依赖性。我现在不在Linux机器附近,但在OS X机器上,您可以在包含安装的site-packages目录中执行此操作:

$ 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,你应该得到你需要的答案。

答案 4 :(得分:3)

您可以使用show_config()显示BLAS,LAPACK和MKL链接:

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

答案 5 :(得分:0)

如果您安装了anaconda-navigator(对于Linux,Windows或macOS,请访​​问www.anaconda.com/anaconda/install/)-blas,scipy和numpy将全部安装,您可以通过单击左侧的环境选项卡来查看它们导航器主页的页面(按字母顺序查找每个目录)。安装完整的anaconda(而不是miniconda或单个软件包)将负责安装数据科学所需的许多基本软件包。