简体   繁体   English

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

[英]How to check BLAS/LAPACK linkage in NumPy and SciPy?

I am builing my numpy/scipy environment based on blas and lapack more or less based on this walk through.我正在构建基于 blas 和 lapack 的 numpy/scipy 环境,或多或少基于演练。

When I am done, how can I check, that my numpy/scipy functions really do use the previously built blas/lapack functionalities?完成后,如何检查我的 numpy/scipy 函数是否确实使用了以前构建的 blas/lapack 功能?

The method numpy.show_config() (or numpy.__config__.show() ) outputs information about linkage gathered at build time.方法numpy.show_config() (或numpy.__config__.show() )输出有关在构建时收集的链接的信息。 My output looks like this.我的输出看起来像这样。 I think it means I am using the BLAS/LAPACK that ships with Mac OS.我认为这意味着我正在使用 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)]

What you are searching for is this: system info您要搜索的是: 系统信息

I compiled numpy/scipy with atlas and i can check this with:我用 atlas 编译了 numpy/scipy,我可以用以下方法检查:

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

Check the documentation for more commands.查看文档以获取更多命令。

As it uses the dynamically loaded versions, you can just do this: 由于它使用动态加载的版本,您可以这样做:

$ ldd anyoftheCmodules.so

where anyoftheCmodules.so could be, for example, numpy/core/_dotblas.so , which links to libblas.so . 其中anyoftheCmodules.so可以是,例如, numpy/core/_dotblas.so ,它链接到libblas.so

You can use the link loader dependency tool to look at the C level hook components of your build and see whether they have external dependencies on your blas and lapack of choice.您可以使用链接加载器依赖工具查看构建的 C 级钩子组件,并查看它们是否对您选择的 blas 和 lapack 具有外部依赖关系。 I am not near a linux box right now, but on an OS X machine you can do this inside the site-packages directory which holds the installations:我现在不在 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)

substitute ldd in place of otool on a gnu/Linux system and you should get the answers you need.在 gnu/Linux 系统上用ldd代替otool ,你应该会得到你需要的答案。

You can display BLAS, LAPACK, MKL linkage using show_config() :您可以使用show_config()显示 BLAS、LAPACK、MKL 链接:

import numpy as np
np.show_config()

Which for me gives output:这对我来说给出了输出:

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

If you installed anaconda-navigator (at www.anaconda.com/anaconda/install/ for linux, Windows or macOS) - blas, scipy and numpy will all be installed and you can see them by clicking environments tab on left side of navigator home page (look for each directory in alpha order).如果您安装了 anaconda-navigator(在 www.anaconda.com/anaconda/install/ for linux、Windows 或 macOS) - blas、scipy 和 numpy 都将被安装,您可以通过单击导航器主页左侧的环境选项卡来查看它们页面(按 alpha 顺序查找每个目录)。 Installing full anaconda (as opposed to miniconda or individual packages) will take care of installing many of the essential packages needed for data science.安装完整的 anaconda(而不是 miniconda 或单个包)将负责安装数据科学所需的许多基本包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM