python2系とpython3系が共存する環境で、pipを使ってtensorflowのgpu版をインストールしようとすると以下のようなエラーがでた。
> sudo pip install tensorflow-gpu Requirement already satisfied (use --upgrade to upgrade): tensorflow-gpu in /usr/local/lib/python2.7/dist-packages Cleaning up...
つまり、python2.7系には入っているというのだ。pythonをインタラクティブモードで起動すると、python3が立ち上がるのに、pipはpython2.7系にパスが通っているのだ。なんとも紛らわしい。そこで、以下の用にpip3というのを使ってインストールしたらうまくいった。
> sudo pip3 install tensorflow-gpu
ただし、cudnn6が入っていないと以下のようなエラーが出るので要注意。
> python >>> import tensorflow .... ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/install_sources#common_installation_problems
以下から、cudnn6 for cuda8をダウンロードしてインストールする。
https://developer.nvidia.com/rdp/cudnn-download
> tar -xvzf cudnn-8.0-linux-x64-v6.0.tgz > cd cuda > sudo cp lib64/* /usr/local/cuda-8.0/lib64 > sudo cp include/* /usr/local/cuda-8.0/include
これで、tensorflowのgpu版を実行することができた。
> python >>> import tensorflow xxxx > nvidia-smi Fri Dec 22 17:36:29 2017 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 375.26 Driver Version: 375.26 | |-------------------------------+----------------------+----------------------+ | 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 980 On | 0000:01:00.0 On | N/A | | 0% 44C P2 49W / 196W | 3749MiB / 4034MiB | 2% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1633 G /usr/bin/X 193MiB | | 0 2520 G compiz 129MiB | | 0 17155 C python 103MiB | | 0 18268 G ...el-token=4488092EE6E496385D63EA4BD9A20859 87MiB | | 0 19862 C python 3231MiB | +-----------------------------------------------------------------------------+