TensorFlow is a widespread software library for numerical computation using data flow graphs. It is very
common on machine learning and deep neural networks projects. Therefore, today we are going to see how
to install it on POWER with CPU only configuration.Before installing TensorFlow, there are a couple of details
we have to pay attention to: 1. Due to Bazel, one of TF dependencies, the operating system must be Ubuntu
14.04 or Ubuntu 16.04. 2. We are going to use Python 2.7, since TF doesn’t seem to be supported by Python
3.5 on POWER.
Tensorflow Dependencies
You can use the commands below to solve most of the dependencies:
apt-get update apt-get install python-numpy python-dev python-pip python-wheel
Bazel installation
Bazel is one of the TF dependencies, but its installation is less intuitive than the others due to its community
not officially supporting POWER architecture. That said, we must compile it from the Source. First of all, we
need to install its own dependencies by the following commands:
apt-get update sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk sudo update-alternatives --config java sudo update-alternatives --config javac apt-get install unzip build-essential python openjdk-8-jdk protobuf-compiler zip g++ zlib1g-dev
It is also important to add enviroment variables on .bashrc for JDK.
vim ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
end
source ~/.bashrc
For compiling Bazel, we are going to download and unpack its distribution archive (the zip file from the
release page https://github.com/bazelbuild/bazel/releases. The .sh is not compatible with ppc64le) and
compile it.
mkdir bazel cd bazel wget -c https://github.com/bazelbuild/bazel/releases/download/0.11.1/bazel-0.11.1- dist.zip #if you want to download other version of bazel, this link must be switched by the one you are intenting to use. unzip bazel-0.11.1-dist.zip ./compile.sh
As we can see, this tutorial was tested with bazel 0.11.1, but feel free to try other version and see if it works
properly.
Also, if you are having any trouble about lack of resources, you can take a look on ‘Build issues and Support
Websites’ to see if there’s any link that could help you. Anticipating: if you don’t have memory enough and
your Bazel can’t complete the compile step, you might have a problem with the garbage collector of JAVA
(and there’s a link which explains how to deal with it).
if has this error,please add PATH in ~/.bashrc
WARNING: /tmp/bazel_MbgK8C8W/out/external/bazel_tools/WORKSPACE:1: Workspace name in
/tmp/bazel_MbgK8C8W/out/external/bazel_tools/WORKSPACE (@io_bazel) does not match the name given
in the repository’s definition (@bazel_tools); this will cause a build error in future versions
vim ~/.bashrc export BAZEL_HOME=/opt/src/packages/bazel/output export PATH=$BAZEL_HOME/bazel:$BAZEL_HOME:$PATH
Installing Tensorflow
Since we are going to use the current version of TF, we need to clone it from the official GitHub and execute
the configuration script.
git clone https://github.com/tensorflow/tensorflow cd ~/tensorflow ./configure
On this step, we have to specify the pathname of all relevant TF dependencies and other build configuration
options. On most of them we can use the answers suggested on each question. Here, I will show how it was
done for this tutorial. (Yours might be a little different, depending on the pathnames)
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7 Found possible Python library paths: /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages Please input the desired Python library path to use. Default is [/usr/lib/python2.7/dist-packages]: /usr/lib/python2.7/dist-packages Using python library path: /usr/local/lib/python2.7/dist-packages #Y/N Answers given: All of them as suggested in each question. Please specify optimization flags to use during compilation when bazel option "-- config=opt" is specified [Default is -march=native]: -mcpu=native Configuration finished
To build and install libtensorflow
bazel build –config=monolithic //tensorflow/tools/lib_package:libtensorflow
opencv tensorflow jpeg error
bazel build –config=opt //tensorflow/tools/lib_package:libtensorflow
To build and install TF, we use:
bazel build --config=monolithic --copt="-mcpu=native" --jobs 1 --local_resources 2048,0.5,1.0 //tensorflow/tools/pip_package:build_pip_package bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg #creates the pip package pip install /tmp/tensorflow_pkg/tensorflow-1.5.0rc0-cp27-cp27mu-linux_ppc64le.whl #installs the pip package. This name depends on your operating system, Python version and CPU only vs. GPU support. Therefore, check it out its name before this step.
By this moment, your TF must be working. Remember not to import it into its own directory: you have to
chance directory before executing Python.
Leave a Reply
You must be logged in to post a comment.