Search code examples
pythonnumpylapackblasintel-mkl

How can I link numpy to use MKL as backend?


I have a numpy install and it shows no BLAS backend available:

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

I can do pip install mkl but still the same output as above. How can I link numpy to use MKL as BLAS / LAPACK backend?


Solution

  • You can try using in intel python. Create an environment with intel python and required packages like intel-mkl, intel-numpy etc.

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

    and try importing numpy and running np.show_config()

    Refer : https://pypi.org/project/mkl/ https://pypi.org/project/intel-numpy/

    The better way is to install the Intel base Toolkit and source the variables. Intel mkl and intel python is available with the kit. You just need to source the environment variables

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

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

    You can also try the suggestion provided by Jerome Richard – try setting the LD_LIBRARY_PATH and LD_PRELOAD path to the mkl library .so file. Refer : https://software.intel.com/content/www/us/en/develop/articles/optimizing-without-breaking-a-sweat.html