compiling tensorflow AVX FMA

Step 1: Create a virtual environment to do the job

python3 -m venv ./

Create the virtual environment in my target directory. For Python 3, the venv module comes with the standard library installed. The following directory is created with the above command.

In order to use this environment’s packages/resources in isolation, we will need to “activate” it. To do this, just run the following:

source ./bin/activate

I have create my vent in the directory tfavxfma, after activating the venv, what I see is as below:

[email protected] tfavxfma % source ./bin/activate

(tfavxfma) [email protected] tfavxfma % 

Step 2: Download tensorflow and prepare the dependencies

Download tensorflow from GitHub:

git clone

Next navigate into the newly cloned tensorflow code directory and execute execute the checkout command to navigate to the latest branch.

git checkout r2.0

The latest branch of tensorflow is found here.

Next install tensorflow dependencies:

pip3 install -U pip six numpy wheel setuptools mock future

pip3 install -U keras_applications –no-deps 

pip3 install -U keras_preprocessing –no-deps 

Step 3: Download the tensorflow compiling tools

Well, install Xcode and Bazel ( the tool to compile tensorflow)

Next run


Accept the default configurations and specify the python3 to use in the venv setup previously. Once done, execute the following:

bazel build -c opt –copt=-mavx –copt=-mavx2 –copt=-mfma –copt=-msse4.2 //tensorflow/tools/pip_package:build_pip_package

Leave a comment

Your email address will not be published. Required fields are marked *