Ubuntu 16.04 lts + CUDA9.0 + cuDNN 7.1.3 Tensorflow1.6 コンパイルまで
Ubuntu14.04 LTS を dist upgrade で、16.04 にしたので、CUDA と cuDNN を入れ直しすことにしました。
NVIDIA Driver を入れ直す
Before installing the CUDA Toolkit on Linux, please ensure that you have the latest NVIDIA driver R390 installed. The latest NVIDIA R390 driver is available at: www.nvidia.com/drivers
を発見。
現在のバージョンを確認。
$ nvidia-smi Tue May 1 21:25:53 2018 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 384.111 Driver Version: 384.111 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 106... Off | 00000000:06:00.0 On | N/A | | 0% 39C P8 9W / 120W | 52MiB / 6071MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1135 G /usr/lib/xorg/Xorg 50MiB | +-----------------------------------------------------------------------------+
とのことなので、Driver を先に入れよう。
$ dpkg -l | grep nvidia $ dpkg -l | grep cuda $ sudo add-apt-repository ppa:graphics-drivers/ppa $ sudo apt-get update $ sudo apt-get install nvidia-390 $ sudo reboot $ nvidia-smi Tue May 1 22:00:43 2018 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 390.48 Driver Version: 390.48 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 106... Off | 00000000:06:00.0 On | N/A | | 0% 43C P0 29W / 120W | 61MiB / 6077MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1049 G /usr/lib/xorg/Xorg 59MiB | +-----------------------------------------------------------------------------+
CUDA インストール
sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
なお、Tensorflow が、 CUDA9.0 を求めてきたので、
$ sudo apt-get install cuda-9-0
となりました。
邪魔していたのを対処
$ sudo aptitude install cuda
path を通す
cuDNN インストール
tensorflow インストール
sudo pip install tensorflow
で、1.8 かなにかが入ったんですが、tensorflow Illegal instruction core dump
でてしまって、困りました。
回避策として、
$ sudo pip install tensorflow-gpu==1.5
となりました。
pipでバイナリをインストールした場合、1.6以降ではAVX がONになっていて、CPU が AVX に対応していないと、エラーに成るようです。
Note: Starting from 1.6 release, our prebuilt binaries will use AVX instructions. Older CPUs may not be able to execute these binaries.
回避策としては、1.5を使用するか、pip ではなく、自分で AVX OFF でコンパイルすることらしいです。
Tensorflow を、コンパイルする
Installing TensorFlow from Sources | TensorFlow
git で取得
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout r1.6
$ ./configure
build
$ bazel build --config=opt --config=cuda //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.8.0-py2-none-any.whl