Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make use of intel-mkl with tensorflow

I've seen a lot of documentation about making using of a CPU with tensorflow, however, I don't have a GPU. What I do have is a fairly capable CPU and a holing 5GB of intel math kernel, which, I hope, might help me speed up tensorflow a fair bit.

Does anyone know how I can "make" tensorflow use the intel-mlk ?

like image 943
George H Avatar asked Sep 25 '16 07:09

George H


People also ask

Does TensorFlow use MKL?

At pretty much each new release of TensorFlow, the MKL build is broken on various platforms and it requires some gymnastics on our side to get it work again (if we are even able to). We did not investigated much on the reasons why but performances with MKL were many times worst than without it.

Is Intel MKL free for commercial use?

Intel Math Kernel Library (MKL) Intel MKL is free to use in any commercial and academic purposes.

Can TensorFlow run on Intel CPU?

Tensorflow uses CUDA which means only NVIDIA GPUs are supported. For OpenCL support, you can track the progress here. BTW, Intel/AMD CPUs are supported.

How do you load a MKL?

To load the default MKL, run the following command: module load mkl . To load a particular version, use module load mkl/version . For example, use module load mkl/11.3. 3 to load MKL version 11.3.


2 Answers

Build TensorFlow 1.2 from source and during the configuration step enable the support of MKL.

Note for Mac users

As of Dec. 2017, MKL only works on Linux. See https://tensorflow.org/performance/performance_guide#optimizing_for_‌​cpu

Note: MKL was added as of TensorFlow 1.2 and currently only works on Linux. It also does not work when also using --config=cuda.

like image 182
gizzmole Avatar answered Sep 29 '22 08:09

gizzmole


Since tensorflow uses Eigen, try to use an MKL enabled version of Eigen as described here:

  1. define the EIGEN_USE_MKL_ALL macro before including any Eigen's header
  2. link your program to MKL libraries (see the MKL linking advisor)
  3. on a 64bits system, you must use the LP64 interface (not the ILP64 one)

So one way to do it is to follow the above steps to modify the source of tensorflow, recompile and install on your machine. While you're at it you should also try the Intel compiler, which might provide a decent performance boost by itself, if you set the correct flags: -O3 -xHost -ipo.

like image 24
paul-g Avatar answered Sep 29 '22 09:09

paul-g