我如何 link numpy 使用 MKL 作为后端?

How can I link numpy to use MKL as backend?

我有一个 numpy 安装,它显示没有可用的 BLAS 后端:

(pyrepoux) bash-4.2$ python
Python 3.7.3 | packaged by conda-forge | (default, Dec  6 2019, 08:54:18) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.show_config()
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]

我可以 pip install mkl 但输出结果与上面相同。我如何 link numpy 将 MKL 用作 BLAS / LAPACK 后端?

您可以尝试在 intel python 中使用。使用 intel python 和所需的包(如 intel-mkl、intel-numpy 等)创建环境

conda create -n <env-name> intelpython3_full python=3.7.3
conda activate <env_name>
pip install mkl
pip install intel-numpy

并尝试导入 numpy 和 运行 np.show_config()

参考:https://pypi.org/project/mkl/ https://pypi.org/project/intel-numpy/

更好的方法是安装英特尔基础工具包并获取变量。 Intel mkl 和 intel python 随套件提供。您只需要获取环境变量

source <basekit-installation-directory>/setvars.sh

安装指南:https://software.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top.html

您也可以尝试 Jerome Richard 提供的建议——尝试将 LD_LIBRARY_PATH 和 LD_PRELOAD 路径设置为 mkl 库 .so 文件。 参考:https://software.intel.com/content/www/us/en/develop/articles/optimizing-without-breaking-a-sweat.html