Build TensorFlow from source

Building TensorFlow from source

Building TensorFlow from source is recommended by Google for maximum performance, especially when running in CPU mode - on some systems, the difference can be substantial. It will also be required for Mac OS X GPU support for TensorFlow versions later than 1.1. This document describes how to do so.

Step 1: Build libtensorflow

To build libtensorflow for TensorFlow.jl, follow the official instructions for building tensorFLow from source, except for a few minor modifications so as to build the library rather than the client.

Running bazel build will produce the libtensorflow.so binary needed by TensorFlow.jl - there is no need to build the Python package or run anything else. You may place the binary wherever is convenient.

Step 2: Install the TensorFlow binary

We must now tell TensorFlow.jl to load the custom binary. There are a number of ways to do so.

Step 3: Check that the custom binary is loaded

After running using TensorFlow, it should no longer complain that TensorFlow wasn't compiled with the necessary instructions. Try generating two random matrices and multiplying them together. You can time the computation with @time run(sess, x), which should be much faster.

Tips & known issues