LoginSignup
25
23

More than 3 years have passed since last update.

Nvidia-Driver インストール 完全マニュアル(2020年9月11日時点 Ubuntu 18.04対応)

Last updated at Posted at 2020-09-14

目次
1. Nvidia Driver関連を安全に導入するための3つのコツ
2. 導入前の準備
3. Nvidia-Driverのインストール
4. Cudaのインストール
5. CuDNNのインストール
6. 想定されるエラー集


この投稿は個人ブログとのクロス投稿になります。

1. Nvidia Driverを安全に導入するための3つのコツ

  • Nvidia-Driverをインストール後に、必ず再起動をすること
  • cudaをインストールする際には,cudaのバージョンを指定してインストールすることsudo apt-get -y install cuda-**-*
  • TensorflowまたはKerasを使用される方はTensorflow GPUの公式ドキュメントを参照し、cuDNNとcuda, Tensorflow-gpuのバージョンを合わせること

2. 導入前の準備

まず、はじめにnvidia, cuda関連のライブラリがインストールされているかを確認します。


$ dpkg -l | grep nvidia
$ dpkg -l | grep cuda

そして、それらをまず削除し、依存関係のないクリーンな状態にします。


$ sudo apt remove --purge "nvidia-*" -y && sudo apt autoremove
$ sudo apt remove --purge "cuda-*" -y && sudo apt autoremove
$ sudo apt remove --purge "libcudnn*" -y && sudo apt autoremove
$ sudo apt remove --purge "libnvidia-*" -y && sudo apt autoremove

3. Nvidia-Driverのインストール

現在お使いのUbuntu OSに最適なNvidia-Driverを以下のコマンドで見つけます。


$ sudo ubuntu-drivers devices
$ sudo apt install nvidia-driver-***

上記のコマンドで推奨されていたのは440(2020年9月15日時点)でしたが, 同時期に同じVersionのUbuntu OSでGoogle Colab で450が採用されていたため、450を採用しました。

(以下のrebootがコツの1つ目です。)


$ reboot
$ nvidia-smi

注意 : nvidia-smiにおける Driver VersionCUDA Versionは全く当てになりません。信用できるのは、nvidia-smiのバージョンのみです。


4. Cudaのインスール

- バージョンをチェックします

ここからcudaのバイナリファイルをインストールします。
注意1 : Linux, X86_64, Ubuntu, 18.04, deb(network)を選択
注意2 : 指示の最終行のsudo apt-get install cudaは誤りです。
注意3 : 最新のTensorflowでさえcuda10.2はまだサポートしていないため、10.1をインストールすることを推薦します (参照元
間違い


sudo apt-get -y install cuda

正解


sudo apt-get -y install cuda-**-*

このコマンドsudo apt-get -y install cudaは自動的に最新のcudaをダウンロードするように設定されているので要注意です。

5. CuDNNのインストール

ここからCuDNNをダウンロード可能です
ダウンロード前に必ずNvidia開発者アカウントへの登録が必須です。
注意 : これら3つのファイルが必要です。(licudnn7_7**.deb, libcudnn7-dev_**.deb, libcudnn7-doc_**.deb)


$ sudo dpkg -i libcudnn7_**.deb
$ sudo dpkg -i libcudnn7-dev_**.deb
$ sudo dpkg -i libcudnn7-doc_**.deb

6. 想定されるエラー集

- $ nvidia-smiのコマンドが存在しないと言われる

PCを再起動してください。(nvidia-driverをインストール後)


$ sudo reboot

- $ sudo apt install --fix-brokenの際にエラーのループが生じる

vidia-driver-440をインストール後に cuda10.2をインストールしようとしたところ、cuda10.2がnvidia-driver-450と依存関係があり、ループが生じた


$ sudo apt install --fix-broken

Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 cuda-drivers : Depends: cuda-drivers-450 (= 450.36.06-1) but it is not going to be installed
 libnvidia-decode-450 : Depends: libnvidia-compute-450 (= 450.36.06-0ubuntu1) but it is not going to be installed
 nvidia-compute-utils-450 : Depends: libnvidia-compute-450 but it is not going to be installed
 nvidia-driver-450 : Depends: libnvidia-compute-450 (= 450.36.06-0ubuntu1) but it is not going to be installed
                     Recommends: libnvidia-compute-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
                     Recommends: libnvidia-decode-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
                     Recommends: libnvidia-encode-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
                     Recommends: libnvidia-ifr1-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
                     Recommends: libnvidia-fbc1-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
                     Recommends: libnvidia-gl-450:i386 (= 450.36.06-0ubuntu1) but it is not installable
 nvidia-utils-450 : Depends: libnvidia-compute-450 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

解答


sudo apt-get -o Dpkg::Options::="--force-overwrite" install --fix-broken -y

nvidia-driverのバージョン

- 使用しているPC

> GeForce RTX 2080-Ti
> > OS : Ubuntu 18.04.4 LTS (Bionic Beaver)
> Nvidia-Driver : 450
> Cuda : 10.1
> CuDNN : 7.6.3.30-1+cuda10.1
> Python : 3.7.5
> PyTorch : 1.5.1+cu1
> Torchvision : 0.6.1+cu1
> Tensorflow : 2.2.0

- Google Colab

> Version of nvidia-driver in pre-installed Google-Colab is 450 on 2020/09/11
> >OS              : Ubuntu 18.04.3 LTS (Bionic Beaver)
> Nvidia-Driver   : 450
> Cuda            : 10.1
> CuDNN           : 7.65.32-1+cuda10.1
> Python : 3.6.9
> PyTorch         : 1.5.1+cu101
> Torchvision     : 0.6.1+cu101
> Tensorflow : 2.2.0

- 上記の確認方法

$ cat /etc/os-release ## Only works on Ubuntu OS
$ dpkg -l | grep nvidia
$ dpkg -l | grep cuda
$ dpkg -l | grep libcudnn
$ print(torch.__version__)
$ print(torchvision.__version__)
$ print(tensorflow.__version__)
$ ! python --version

まとめ

Nvidia-Driverのメモ書きを少し丁寧にまとめました。環境を再現することは研究を再実験する上でのスタートとなるので、
Google Colabでも推奨されているように、Tensorflow, Cuda, CuDNNのバージョンを必ずJupter NotebookやColab Notebookに記載することが後からコードを見た人が再現するために重要だと再認識させられました。
皆様もぜひ参考にしていただければと思います。

25
23
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
25
23