LoginSignup
8
13

More than 3 years have passed since last update.

Ubuntu 18.04 GeForce RTX 2080 GPU Deep Learning

Last updated at Posted at 2019-03-16
  • Ubuntu 18.04
  • GeForce RTX 2080

の構成で GPU を動作させるための設定手順。

まだ書きかけだがその内ちゃんと書き直すかも。

Disable Secure boot

今ではもうしなくてよい項目

sudo apt install mokutil -y
sudo mokutil --disable-validation

Change Secure boot state を選んで、パスワードを入力した後 YES を選択して再起動する。すると解像度が適切なものになった。

dmesg | grep secure
[    0.000000] secureboot: Secure boot disabled

Secure boot が無効になったことが確認できた。

Disable nouveau

今ではもうしなくてよい項目

$ lsmod | grep -i nouveau
nouveau              1716224  0
i2c_algo_bit           16384  1 nouveau
ttm                   106496  1 nouveau
drm_kms_helper        172032  1 nouveau
mxm_wmi                16384  1 nouveau
drm                   401408  3 drm_kms_helper,ttm,nouveau
wmi                    24576  4 intel_wmi_thunderbolt,wmi_bmof,mxm_wmi,nouveau
video                  45056  1 nouveau
sudo nano /etc/modprobe.d/blacklist-nvidia-nouveau.conf
blacklist nouveau
options nouveau modeset=0
sudo update-initramfs -u

Reboot してはいけない。

Enter CUI mode

自分の環境だと Ctrl + Alt + F3 で CUI mode に入り Ctrl + Alt + F2 で GUI mode に戻れた。

Install NVIDIA Driver

Install driver

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
ubuntu-drivers devices
sudo apt install nvidia-driver-440
sudo reboot
$ nvidia-smi
Tue Jan 29 13:34:45 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.78       Driver Version: 410.78       CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 2080    Off  | 00000000:01:00.0  On |                  N/A |
| 24%   32C    P8    14W / 215W |    337MiB /  7949MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1780      G   /usr/lib/xorg/Xorg                            18MiB |
|    0      1838      G   /usr/bin/gnome-shell                          57MiB |
|    0      2475      G   /usr/lib/xorg/Xorg                           116MiB |
|    0      2616      G   /usr/bin/gnome-shell                          84MiB |
|    0      3539      G   ...uest-channel-token=16844326574801113722    58MiB |
+-----------------------------------------------------------------------------+

CUDA と cuDNN はインストールしない

conda もしくは nvidia-docker に管理を任せるので CUDA や cuDNN のインストールはしない。

Install conda

conda を使いたい人はこちら。

$ wget "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
$ sh Miniconda3-latest-Linux-x86_64.sh
$ conda -V
conda 4.5.12

nvidia-docker

nvidia-docker を使いたい人はこちら。

Install nvidia-docker

NVIDIA/nvidia-docker: Build and run Docker containers leveraging NVIDIA GPUs

上記を参考にして nvidia-container-toolkit をインストールする。

Rootless Docker

Rootless Docker を利用している場合は上のリンク先のような対応が必要。

sudo vim /etc/nvidia-container-runtime/config.toml

具体的には上記ファイルを以下のように書き換える。

- #no-cgroups = false
+ no-cgroups = true

マシンを再起動した後などに、以下のように言われた場合は systemctl --user start docker を実行すると良い。

Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?

ログインの度に上記コマンドを実行しなければならない状態を解決するには sudo loginctl enable-linger username を実行しておくと良いかもしれない。

GPU の動作確認

nvidia-docker の場合は以下のようにしてコンテナを起動する。

docker run -it --gpus all nvidia/cuda:10.0-devel-ubuntu18.04 bash

Docker 19.03 より --gpus all が利用できる。

PyTorch

python3 を実行してインタラクティブモードで確認する。

>>> import torch 
>>> print(torch.cuda.is_available())
True
>>> torch.cuda.get_device_name(0)
'GeForce RTX 2080'

TensorFlow and Keras

python3 を実行してインタラクティブモードで確認する。

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

上記を実行すると以下のように利用できるデバイスの一覧を確認できる。

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 9038648218982750694
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 2090976096258654801
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 9284591186135588828
physical_device_desc: "device: XLA_CPU device"
]

MNIST

TBW

8
13
2

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
8
13