Build and install TensorFlow from source with MKL DNN support and AVX enabled

Free book on Binary Tree

Get this book -> Problems on Array: For Interviews and Competitive Programming

Reading time: 15 minutes | Installation time: 20 minutes

In this guide, we will walk you through building and installing TensorFlow from source with support for MKL DNN and with AVX enabled.

Step 1: Clone the source

To get started, you need to clone the source code of TensorFlow:

git clone
cd tensorflow

Step 2: Chose your version

Currently, you are on the development branch. You can, optionally, switch to a release branch such as 1.11:

git checkout r1.11

Step 3: Install Bazel

Follow the following commands one by one to successfully install TensorFlow:

sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
chmod +x
./ --user
export PATH="$PATH:$HOME/bin"
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java8-installer
echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl | sudo apt-key add -
sudo apt-get update && sudo apt-get install bazel

Step 4: Configure the build


Follow the instructions carefully

Step 5: Build the pip wheel file

bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma 
--copt=-mfpmath=both --copt=-msse4.1 --copt=-msse4.2 --config=cuda -k 

Step 6: Build with pip

build_pip_package /tmp/tensorflow_pkg
sudo pip install /tmp/tensorflow_pkg/

You have installed TensorFlow with MKL DNN support and AVX enabled

You have an efficient version of TensorFlow and you can get started by developing models in TensorFlow