TensorFlow のコンパイル2017年11月22日 | |
はじめにTensorFlow をソースからコンパイルする バージョン
TensorFlow のインストールTensorFlow のインストール自体は pip でできる。まず、libcupti-dev をインストールする。 $ sudo apt-get install libcupti-dev CPU 版のインストール。 $ pip install tensorflow GPU 版のインストール (CUDA のセットアップは済んでいるものとする)。 $ pip install tensorflow-gpu これだと都合が悪い場合、ソースからコンパイルすることになる。 TensorFlow のコンパイル事前の環境設定Anaconda と CUDA のセットアップが済んでいるものとする。 cuDNN のインストールGPU 対応のために、まず cuDNN をインストールする。こちら からダウンロードできるが、その前に登録が必要である。登録が済んだら、以下のものをダウンロードする。
インストール。 $ sudo dpkg -i libcudnn7*.deb Bazel のインストールTensorFlow のコンパイルには Bazel というものが使われているので、これをインストールする。こちら に従う。 $ 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 TensorFlow のインストールlibcupti-dev をインストールする。 $ sudo apt-get install libcupti-dev TensorFlow のソースコードを取得。 $ cd ~/build $ git clone https://github.com/tensorflow/tensorflow あるいは、こちら から特定のリリースをダウンロードしたほうがよいかも。 コンパイルオプションの設定。 $ cd ~/bulid/tensorflow $ ./configure Please specify the location of python. [Default is /home/xxxx/anaconda3/bin/python]: Found possible Python library paths: /home/xxxx/anaconda3/lib/python3.6/site-package Please input the desired Python library path to use. Default is [/home/xxxx/anaconda3/lib/python3.6/site-packages] Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: jemalloc as malloc support will be enabled for TensorFlow. 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 Amazon S3 File System support? [Y/n]: n No Amazon S3 File System support will be enabled for TensorFlow. Do you wish to build TensorFlow with XLA JIT support? [y/N]: No XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with GDR support? [y/N]: No GDR support will be enabled for TensorFlow. Do you wish to build TensorFlow with VERBS support? [y/N]: No VERBS support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL support? [y/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 the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 9.0 Please specify the location where CUDA 9.0 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 default to cuDNN 6.0]: 7.0.3 Please specify the location where cuDNN 7.0.3 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:/usr 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: 6.1] Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: Configuration finished コンパイル。 $ 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 pip でインストール。 $ pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp36-cp36m-linux_x86_64.whl 確認。 $ cd $ python >>> import tensorflow ※ディレクトリを移動しないとエラーになる。 CPU 版との共存GPU 版だけでなく CPU 版も使いたい場合は、conda で環境を作ってインストールすればよい。 $ conda create -n tensorflow python=3.6 $ source activate tensorflow $ pip install tensorflow $ source deactivate CPU 版を使う時 $ source activate tensorflow 終了 $ source deactivate GPU 版も同様に環境を作ってインストールしてもよい。 | |
| PENGUINITIS | |