Ubuntu 16.04 + CUDA 9.1 + cuDNN 7.0.5 + Tensorflow 1.4.0
Tensorflow をインストールしたので、その備忘録。
環境
CUDA 9.1
CUDA install
$ sudo dpkg -i cuda-repo-ubuntu1604_9-1-local_9.1.85-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cudaCUDA PATH
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CPATH=/usr/local/cuda/include:$CPATH
cuDNN 7.0.5
cuDNN install
$ sudo dpkg -i libcudnn7_7.0.5.15-1_cuda9.1_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.0.5.15_cuda9.1_amd64.deb
$ sudo dpkg -i libcudnn7-doc_7.0.5.15_cuda9.1_amd64.debcuDNN sample
$ cp -r /usr/src/cudnn_samples_v7/ $HOME
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
$ make clean && make
$ ./mnistCUDNN
Bazel 0.9.0
- Bazel install
$ sudo apt-get install openjdk-8-jdk
$ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
$ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
$ sudo apt-get update && sudo apt-get install bazel
$ sudo apt-get upgrade bazel
Tensolflow
まずは必要なパッケージを一応インストール
$ sudo apt-get install python-numpy python-dev python-pip python-wheel
$ sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel
$ sudo apt-get install libcupti-dev
math_functions.hpp error
Tensorflowのbuild中にmath_function.hppがないってエラーが出たので対応。"cuda/include/crt"の中まで見にいってくれていないようなので、include用のファイル作成$ sudo cp -a /usr/local/cuda/include/crt/math_functions.hpp /usr/local/cuda/include/
$ sudo vim /usr/local/cuda/include/math_functions.hpp
中身を全部消して、以下を追加#include "crt/math_functions.hpp"
Tensorflow install
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ ./configure
configureは自分の環境にあったものに設定
$ bazel build -c opt --copt=-mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl
で、インストールできているか確認
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a + b)
42
>>> sess.close()