LoginSignup
6
15

More than 5 years have passed since last update.

Jetson TX2にTensorFlowをインストールした

Posted at

Jetson TX2にTensorFlowをインストールした

GWが暇だったので、おもちゃとしてNVIDIAが出していてるJetson TX2を購入した。
結論から言うとTensorFlowのインストールにつまづき過ぎてGWは終わってしまった。。。
本当は自分のノートPCとの性能比較したかったのだが、苦労したので備忘録として残す。

事前準備

届いたばかりのTX2にはCUDAなどのライブラリがインストールされていないので、JetPack 3.0インストールガイドに従ってインストールする。
自分の場合は、一度目でL4Tのインストールはできたが何故かライブラリはインストールできなかったので、もう一度ライブラリはインストールを実行した。

TensorFlowのインストール

公式に公開されているバイナリにTX2向けのものを自前でビルドする必要がある。
Googleで検索すると真っ先に出てきたのがhttps://github.com/jetsonhacks/installTensorFlowTX2だが、実行してみてもビルドエラーとなりインストールできなかった。
Bazelのインストールまでは問題なかったのでそこまでは参考にできる。

では、どうしたか?

色々、ビルドエラーについて検索したが、明確な解決方法は見つからなかった。
結局は下記サイトを参考にインストールすることでTensorFlowを使用できる状態になった。
How to install TensorFlow on the NVIDIA Jetson TX2?

手順

依存ライブラリ及びBazelのインストール

TensorFlowのビルドに必要なビルドツールとビルドするのに必要な依存ライブラリをインストールする必要がある。
これについては、自分はhttps://github.com/jetsonhacks/installTensorFlowTX2installPrerequisites.shを使用して行った。

TensorFlowのビルド

これについては上記で紹介した手順書通りに行えば良い。
最初にリポジトリを落としてくる。自分は最新版が良かったのでリポジトリのブランチはv1.0.1から変更した。

$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ git checkout v1.1.0

次にtensorflow/stream_executor/cuda/cuda_gpu_executor.ccファイルに変更を加える。
具体的にはTryToReadNumaNode関数の最初の行に下記を追記して即終了するように変更する。

  LOG(INFO) << "ARM has no NUMA node, hardcoding to return zero";
  return 0;

その後も手順書通りに実行していけば良い。
説明は省く。

$ sudo cp /usr/include/cudnn.h /usr/lib/aarch64-linux-gnu/include/cudnn.h
$ ./configure
$ nvidia@tegra-ubuntu:~/tensorflow$ ./configure 
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7
Please specify optimization flags to use during compilation [Default is -march=native]: 
Do you wish to use jemalloc as the malloc implementation? (Linux only) [Y/n] y
jemalloc enabled on Linux
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] n
No Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] y
XLA JIT support will be enabled for TensorFlow
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/local/lib/python2.7/dist-packages]

Using python library path: /usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with OpenCL support? [y/N] n
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc 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]: 
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 
Please specify the location where cuDNN  library is installed. Refer to README.md for more details. [Default is /usr/local/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.
Extracting Bazel installation...
.......................
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
.......................
INFO: All external dependencies fetched successfully.
Configuration finished
$ bazel build -c opt --local_resources 3072,4.0,1.0 --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

これで、/tmp/tensorflow_pkgにインストール用のバイナリが作成されているはずなので、下記コマンドにてインストールすれば完了。

$ sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp27-cp27mu-linux_aarch64.whl

ただし、自分の場合は、localeがサポートされてないよというエラーが出たので、事前に下記コマンドを実行することで回避した。

$ export LC_ALL="en_US.UTF-8"
$ export LC_CTYPE="en_US.UTF-8"
$ sudo dpkg-reconfigure locales

次回こそはベンチマークをとりたい。。。

6
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
15