0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

最新の Cuda + CuDNN を Ubuntu 18.04へインストールする@2020年春版

0
Posted at

はじめに

昨年、「最新の cuda + cudnn + cupy を Ubuntu 18.04 へインストールする@2019年春版 」という記事を執筆したのですが、今年も Google Colaboratory では物足りず、本格的なGPUサーバーを使うための環境構築をしました。

その時の作業記録を忘備録として残しておきます。

やりたいこと

  • Tensorflow 2.2を使える環境をubuntuで作ります。(Chainerの更新が止まったので、仕方ないね)
  • インストール対象は Ubuntu 18.04です。(cudaが20.04にまだ対応していないっぽいので、仕方ないね)

なお、TensorflownのGPUサポートを参考にしています。他のライブラリでも似たような手順で問題ないと思いますが、ご了承ください。

インストール環境

マシン: GCP Computer Engine (Google提供のクラウドの仮想マシン)
CPU, メモリ: n1-standard-2(vCPU x 2、メモリ 7.5 GB)
OS: Ubuntu 18.04
GPU: NVIDIA Tesla K80

実際の手順

cuda、ドライバ、各種ライブラリのバージョンに注意しましょう。当然ですが、互換性がないとエラーを吐かれます。
投稿時点では以下のコマンドを実行しましたが、それぞれ必要なバージョンを指定してDLしてください。


# cuda関連のインストール
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.2.89-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo dpkg -i cuda-repo-ubuntu1804_10.2.89-1_amd64.deb
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update

# ドライバのインストール
sudo apt-get install --no-install-recommends nvidia-driver-430

# cuda関連のパスを追加 .bashrcなどの設定ファイルに書き込む
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

この時点で1回リブートする。再起動後、nvidia-smi を叩き、正しく動くか確認する


# その他tensorflowで使うライブラリのインストール
sudo apt-get install --no-install-recommends cuda-10-2 libcudnn7 libcudnn7-dev
sudo apt-get install --no-install-recommends libnvinfer6 libnvinfer-dev libnvinfer-plugin6

# tensorflowのインストール
pip install tensorflow

動作確認

import tensorflow as tf
tf.__version__
> '2.2.0'


from tensorflow.python.client import device_lib
device_lib.list_local_devices()

> '''
[name: "/device:CPU:0"
 device_type: "CPU"
 memory_limit: 268435456
 locality {
 }
 incarnation: 3998521659132627640,
 name: "/device:XLA_CPU:0"
 device_type: "XLA_CPU"
 memory_limit: 17179869184
 locality {
 }
 incarnation: 4355352578664011114
 physical_device_desc: "device: XLA_CPU device",
 name: "/device:XLA_GPU:0"
 device_type: "XLA_GPU"
 memory_limit: 17179869184
 locality {
 }
 incarnation: 5803845507802816222
 physical_device_desc: "device: XLA_GPU device"]
'''

TensorflorでGPUを認識しました。おわり

余談

実はGCPにはGoogleで準備されているGPU用のセットアップがあり、仮想マシン作成時に利用すれば上記のような面倒な手順を踏む必要はありません。便利な世の中になったもんだなぁ〜

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?