Ubuntu20にCUDAインストール
OSを更新したので、機械学習向けにGPUのセットアップをしたのでその備忘録。
PC/ソフトウェアスペック
OS: Ubuntu 20.04 LTS
GPU: GeForce RTX 2070 SUPER
python: 3.8.10
pip: 20.0.2
CUDAインストール
下記サイトから12.2をダウンロード。
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
インストール後、Pathを設定。
export PATH=/usr/local/cuda/bin:${PATH}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:${LD_LIBRARY_PATH}
NVCCでバージョンを確認。
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:16:58_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0
GPUドライバも同時にインストールされる。
Software & UpdatesのAdditional Driversタブからインストールされたドライバを確認できる。
nvidia-smiコマンドでGPUの状態が確認できる。
$ nvidia-smi
Fri Jul 7 16:40:03 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.54.03 Driver Version: 535.54.03 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 2070 ... On | 00000000:01:00.0 On | N/A |
| 24% 37C P8 12W / 215W | 493MiB / 8192MiB | 16% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 946 G /usr/lib/xorg/Xorg 66MiB |
| 0 N/A N/A 1471 G /usr/lib/xorg/Xorg 138MiB |
| 0 N/A N/A 1601 G /usr/bin/gnome-shell 170MiB |
| 0 N/A N/A 3865 G ...71687434,9221152478920077697,262144 108MiB |
+---------------------------------------------------------------------------------------+
cuDNNをインストール
該当するバージョンをダウンロード。今回はLocal Installer for Ubuntu20.04 x86_64 (Deb)を選択。
https://developer.nvidia.com/rdp/cudnn-download
Enable the local repository.
$ sudo dpkg -i cudnn-local-repo-ubuntu2004-8.9.2.26_1.0-1_amd64.deb
Import the CUDA GPG key.
$ sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/
$ sudo apt-get update
Install the runtime library.
$ sudo apt-get install libcudnn8=8.9.2.26-1+cuda12.1
Install the developer library.
$ sudo apt-get install libcudnn8-dev=8.9.2.26-1+cuda12.1
Install the code samples.
$ sudo apt-get install libcudnn8-samples=8.9.2.26-1+cuda12.1
下記を実行して問題なく動けばOK。
$ cp -r /usr/src/cudnn_samples_v8 .
$ cd cudnn_samples_v8/RNN
$ make
$ ./RNN
Executing: RNN
seqLength = 20
numLayers = 2
hiddenSize = 512
inputSize = 512
miniBatch = 64
dropout = 0.000000
direction = CUDNN_UNIDIRECTIONAL
mode = CUDNN_RNN_RELU
algo = CUDNN_RNN_ALGO_STANDARD
precision = CUDNN_DATA_FLOAT
Forward: 145 GFLOPS
Backward: 301 GFLOPS, (191 GFLOPS), (709 GFLOPS)
y checksum 1.315793E+06 hy checksum 1.315212E+05
dx checksum 6.676003E+01 dhx checksum 6.425073E+01
dw checksum 1.453766E+09
Output saved to result.txt
参考URL:
この記事が気に入ったらサポートをしてみませんか?