OpenNMT Forum

Installing Intel MKL to speed up Torch for Intel CPU

for cpu translate mode, use Intel® MKL can expect at least a 2x speedup when using MKL with multiple threads.

#download mkl from

tar -zxf l_mkl_2017.0.098.tgz
sudo ./

#enter serial number of mkl.
#default install path at: /opt/intel

export CMAKE_INCLUDE_PATH=$CMAKE_INCLUDE_PATH:/opt/intel/mkl/include
export CMAKE_LIBRARY_PATH=$CMAKE_INCLUDE_PATH:/opt/intel/mkl/lib/intel64:/opt/intel/mkl/compiler/lib/intel64
#Also, you need to source the file like this:
source /opt/intel/mkl/bin/ intel64

###Install Intel version torch

git clone ./torch

cd torch; 
bash install-deps;

###You can test that all libraries are installed properly by running:

cd torch
ldd ./install/lib/lua/5.2/ =>  (0x00007fff613ff000) => /yfsys/work/torch/install/lib/ (0x00007f81b1667000) => /lib/x86_64-linux-gnu/ (0x00007f81b1353000) => /usr/lib/x86_64-linux-gnu/ (0x00007f81b1125000) => /lib/x86_64-linux-gnu/ (0x00007f81b0f08000) => /lib/x86_64-linux-gnu/ (0x00007f81b0b49000) => /opt/intel/mkl/lib/intel64/ (0x00007f81b0034000) => /opt/intel/mkl/lib/intel64/ (0x00007f81aee68000) => /opt/intel/mkl/lib/intel64/ (0x00007f81ad378000) => /lib/x86_64-linux-gnu/ (0x00007f81ad170000)
    /lib64/ (0x00007f81b1ea2000) => /lib/x86_64-linux-gnu/ (0x00007f81acf6b000)

you should use OMP_NUM_THREADS environment variable to control the number of threads.

more detail:


Hi, I tried it, following what you write, but now I come up with a funny problem, in last step,

ldd ./install/lib/lua/5.2/

my output is => (0x00007ffc39ad5000) => /home/huqiu/torch/install/lib/ (0x00007f12abf13000) => /lib/x86_64-linux-gnu/ (0x00007f12abbea000) => /usr/lib/x86_64-linux-gnu/ (0x00007f12ab9c8000) => /lib/x86_64-linux-gnu/ (0x00007f12ab7aa000) => /lib/x86_64-linux-gnu/ (0x00007f12ab3e1000) => /opt/intel/mkl/lib/intel64/ (0x00007f12aa9aa000) => /opt/intel/mkl/lib/intel64/ (0x00007f12a9788000) => /opt/intel/mkl/lib/intel64/ (0x00007f12a7c95000) => /lib/x86_64-linux-gnu/ (0x00007f12a7a8d000)
/lib64/ (0x000055c50b3ac000) => /lib/x86_64-linux-gnu/ (0x00007f12a7888000)

that is to say, there is no " => /opt/intel/mkl/lib/intel64/ (0x00007f5914566000)"
but I have “ => /lib/x86_64-linux-gnu/ (0x00007f12a7a8d000)”,

I wonder why ? and how I can do to tackle it, can you give me some insights or help me ? Thank you in advance.:slight_smile:

I think that your installation is correct, in the last version of MKL, my system ld is same as yours:

ldd ./install/lib/lua/5.2/ => (0x00007fff613ff000) => /yfsys/work/torch/install/lib/ (0x00007f81b1667000) => /lib/x86_64-linux-gnu/ (0x00007f81b1353000) => /usr/lib/x86_64-linux-gnu/ (0x00007f81b1125000) => /lib/x86_64-linux-gnu/ (0x00007f81b0f08000) => /lib/x86_64-linux-gnu/ (0x00007f81b0b49000) => /opt/intel/mkl/lib/intel64/ (0x00007f81b0034000) => /opt/intel/mkl/lib/intel64/ (0x00007f81aee68000) => /opt/intel/mkl/lib/intel64/ (0x00007f81ad378000) => /lib/x86_64-linux-gnu/ (0x00007f81ad170000)
/lib64/ (0x00007f81b1ea2000) => /lib/x86_64-linux-gnu/ (0x00007f81acf6b000)

you mean, this info indicates that our torch now is running on MKL instead of OpenBLAS ?

if yes, why a same lua program cost more time than running on OpenBLAS ? it is normal ?

please see more detail:

I do confirm that my tests are also slower with the MKL+intel torch version vs the standard config.

Surprising but even with multithread = 8 it’s slow.