LoginSignup
73
63

More than 5 years have passed since last update.

mkl numpyのインストール方法

Last updated at Posted at 2015-09-10

Intel製の高性能行列ライブラリ、Math Kernel Library (mkl)がフリーで公開されるようになりました。これをnumpyから使えるようにする方法を解説します。対象はLinuxです(自分はUbuntu 14.04)。

MKLのインストール

以下のサイトの、”click here now to register and download” をクリック。
https://software.intel.com/en-us/articles/free_mkl
名前、メールアドレス、会社名などを入力。レジストレーションのメールが来るので、そこをたどるとダウンロードできる。Mac版はない。およそ1GBある。インストール時に必要な、レジストレーションキーがあるのでメモっておく。
自分がダウンロードしたのは、l_mkl_11.3.0.109.tgz

ダウンロードしたファイルを展開。中にinstall.shがあるので実行。インストール先は、デフォルトでは /opt/intel 、途中でレジストレーションキーの入力を促されるので入力。(

対話形式を使わない場合は、解凍したディレクトリにある、silent.cfgファイルの以下の部分を修正。

ACCEPT_EULA=accept
ACTIVATION_SERIAL_NUMBER=XXXX-XXXXXXXX
ACTIVATION_TYPE=serial_number

install.sh -s silent.cfgを実行すると、コマンドラインのみでインストールできる。

/opt/intel/mkl/lib/intel64LD_LIBRARY_PATHを通しておく。

numpyのインストール

numpyインストール時の設定は、~/.numpy-site.cfgを見に行く。このファイルのテンプレートは、ソースの中にある。
https://github.com/numpy/numpy/blob/master/site.cfg.example
ファイルを改変して、ホームディレクトリにおいておく。内容は、以下のようにしておく。

[mkl]
library_dirs = /opt/intel/mkl/lib/intel64/
include_dirs = /opt/intel/mkl/include
mkl_libs = mkl_rt
lapack_libs =

詳細は、下記サイトを参照。
https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl

この状態で、pip install --no-binary :all: numpyすると、勝手にmklを使ったnumpyがインストールされる。もともとnumpyが入っている場合は、一度アンインストールしておくこと。

動作確認

numpy.show_config() を見ると、どの行列ライブラリを使っているか確認できる。Chainerをexampleなどを実行した感じだと、OpenBLASに比べて、1.5倍速程度で動いているようだ。

$ python
>>> import numpy
>>> numpy.show_config()
lapack_opt_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/mkl/lib/intel64/']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/mkl/include']
blas_opt_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/mkl/lib/intel64/']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/mkl/include']
openblas_lapack_info:
  NOT AVAILABLE
lapack_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/mkl/lib/intel64/']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/mkl/include']
blas_mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/mkl/lib/intel64/']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/mkl/include']
mkl_info:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/mkl/lib/intel64/']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/mkl/include']
73
63
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
73
63