Install TensorFlow source code in Ubuntu 15.04
This article describes how to install TensorFlow source code. The installed system is Ubuntu 15.04.
Obtain TensorFlow source code
1 |
git clone --recurse-submodules https: //github .com /tensorflow/tensorflow |
Use--recurse-submodules
To obtain the protobuf library files that TensorFlow depends on.
Install Bazel
Follow the instructions below to install the bazel dependency. Bazel installation file:
JDK1.8 is required by default for bazel. If you use JDK1.7, download the corresponding installation package.
Install other Dependencies required by Bazel:
1 |
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip |
Run the following command to install Bazel:
12 |
chmod +x PATH_TO_INSTALL.SH . /PATH_TO_INSTALL .SH --user |
Remember to replace PATH_TO_INSTALL.SH with your downloaded Bazel installation file name, for example:
1 |
. /bazel-0 .1.4-installer-linux-x86_64.sh --user |
Install other Dependencies
1 |
sudo apt-get install python-numpy swig python-dev |
Configure and install
Runconfigure
Script. This script requires you to enter the installation path of the python interpreter and allow you to choose to install the CUDA library.
If CUDA is not installed, this step mainly locates the header files of python and numpy:
12 |
. /configure Please specify the location of python. [Default is /usr/bin/python ]: |
To install CUDA, you must specify the CUDA installation location in addition to python:
12345678910111213141516 |
. /configure Please specify the location of python. [Default is /usr/bin/python ]: Do you wish to build TensorFlow with GPU support? [y /N ] y GPU support will be enabled for TensorFlow Please specify the location where CUDA 7.0 toolkit is installed. Refer to README.md for more details. [default is: /usr/local/cuda ]: /usr/local/cuda Please specify the location where the cuDNN v2 library is installed. Refer to README.md for more details. [default is: /usr/local/cuda ]: /usr/local/cuda Setting up Cuda include Setting up Cuda lib64 Setting up Cuda bin Setting up Cuda nvvm Configuration finished |
Build Tensorflow that supports GPU
Run the following command in the root directory of tensorflow:
$ bazel build -c opt --config=cuda --spawn_strategy=standalone //tensorflow/cc:tutorials_example_trainer$ bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu# Lots of output. This tutorial iteratively calculates the major eigenvalue of# a 2x2 matrix, on GPU. The last few lines look like this.000009/000005 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000006/000001 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]000009/000009 lambda = 2.000000 x = [0.894427 -0.447214] y = [1.788854 -0.894427]
Note that "-- config = cuda" is needed to enable the GPU support.