I figured out how to build tensorflow from source in centOS. This process does not require any root access and you can do it anywhere. This will save your time and no need to worry much after this.
#What to prepare:
- Java 8
- Bazel
- Tensorflow
- CuDNN and CUDA toolkit (assume you have install them)
#Installation ##Bazel
I am using Bazel 0.3.2 since I found issues with Bazel in master branch.
check your JAVA_HOME since Bazel requires Java 8, you should download and install it first. This tutorial will not cover it.
$ git clone https://github.com/bazelbuild/bazel.git
$ git checkout tags/0.3.2
$ cd bazel
$ ./compile.sh
It takes some time and after you finished, and add the binary path into the PATH variable, in this case
$ /PATH-TO-BAZEL/output/
##TensorFlow
This is the toughest software to build that I ever know (if you don't have any access to admin). You can download Tensorflow from github as mentioned in the website https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html
$ git clone https://github.com/tensorflow/tensorflow
Then, you may need to hack the code before you can start the configuration free from issues. Go to file tensorflow/third_party/gpus/crosstool/CROSSTOOL and update cxx_builtin_include_directory
with
cxx_builtin_include_directory : "/usr/local/cuda/targets/x86_64-linux/include"
Run the configuration
$ ./configure
If you are wonder to use Tensorflow in a GPU with less than 3.5 compute capabilities, you may run this command and type the compute capabilities you desired
TF_UNOFFICIAL_SETTING=1 ./configure
Build with bazel
# Without GPU support
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
# To build with GPU support:
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
# Build whl file
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Install tensorflow
pip install --upgrade /tmp/tensorflow_pkg/<your whl file>.whl
And done!
As of tensorflow 2.0
I noticed that, as someone who came from google, these instructions didn't help except the build statement itself.
If you're someone who doesn't have root access and/or working in a cluster style environment. I'd like to mention these issues which talk about fixes for problems I encountered:
tensorflow/tensorflow#33975
bazelbuild/bazel#4053
I'd also like to respectfully plug my own gist that talks about it as well.