pandazx's blog

データ分析など雑多な技術ブログ

EC2のGPUインスタンスにTensorflowインストール

追記

NVIDIA AMIではうまく行かなかったので、まっさらなUbuntuを元に以下を参考にコマンドをコピペすれば出来る。

AWSインスタンス上にTensorFlow:GPGPU環境を作成する | テクノスデータサイエンス・マーケティング株式会社

一部、違うのは、ビルドツールBazelのバージョンは最新をインストールすること。じゃないと、エラーになる。 (ブログでは0.1.1だが、最新は0.2.1) あとは、cuDNNのインストールは上記ブログよりは下記のようなネットワークインストールの方が個人的には好き。

TensorFlow (GPU版) を Ubuntu にインストールしてみた - Qiita

以下はうまくいかなかった時の作業ログ。

前提

TensorFlowのパッケージビルド

git clone --recurse-submodules https://github.com/tensorflow/tensorflow
TF_UNOFFICIAL_SETTING=1 ./configure
Please specify the location of python. [Default is /usr/bin/python]: 
Do you wish to build TensorFlow with GPU support? [y/N] y
GPU support will be enabled for TensorFlow
Please specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]: 
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 
Please specify the location where CUDA  toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /opt/nvidia/cuda 
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 2
Please specify the location where cuDNN 2 library is installed. Refer to README.md for more details. [Default is /opt/nvidia/cuda]: 
Invalid path to cuDNN 2 toolkit. Neither of the following two files can be found:
/opt/nvidia/cuda/lib64/libcudnn.so.2
/opt/nvidia/cuda/libcudnn.so.2
.2
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 6.5
Please specify the location where cuDNN 6.5 library is installed. Refer to README.md for more details. [Default is /opt/nvidia/cuda]: 
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Setting up Cuda include
Setting up Cuda lib64
Setting up Cuda bin
Setting up Cuda nvvm
Configuration finished

ビルドエラー1

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
Extracting Bazel installation...
........
INFO: Found 1 target...
ERROR: /home/ec2-user/.cache/bazel/_bazel_ec2-user/0ff5a3f6434c30269b5495d73aade5d5/external/re2/BUILD:9:1: C++ compilation of rule '@re2//:re2' failed: crosstool_wrapper_driver_is_not_gcc failed: error executing command third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -fPIE -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object ... (remaining 36 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 127.
/usr/bin/env: python2: No such file or directory
Target //tensorflow/cc:tutorials_example_trainer failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 15.320s, Critical Path: 3.85s

python2を使おうとしてエラーになるので、python27のシンボリックリンクを作成

sudo ln /usr/bin/python27 -s /usr/bin/python2

ビルドエラー2

ERROR: /home/ec2-user/tensorflow/tensorflow/core/kernels/BUILD:1121:1: output 'tensorflow/core/kernels/_objs/depth_space_ops_gpu/tensorflow/core/kernels/depthtospace_op_gpu.cu.o' was not created.
ERROR: /home/ec2-user/tensorflow/tensorflow/core/kernels/BUILD:1121:1: not all outputs were created.
Target //tensorflow/cc:tutorials_example_trainer failed to build

これの理由が不明。Bazelのバージョン問題? 追記では、最新の0.2.1でうまくいったので、よくわからない。