Ubuntu 20.04 LTS, CUDA 11.2.0, NVIDIA 455 and libcudnn 8.0.4
https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu
這個方法可以解決很多人在裝Pytorch之前解決CUDA依賴的問題,網上很多文章都沒有下面這句英語,這是問題關鍵。
這個問題的核心在下面這句英語:
I don't recommend installing the NVIDIA drivers that come with CUDA as they do not contain the dkms drivers that carry over into new kernel upgrades.
If you don't have the `graphics-drivers` PPA already setup, add it now to your system and remove any previous NVIDIA drivers.
The Ubuntu repositories now contain the same drivers as thegraphics-drivers
PPA. So feel free to install the460.39
drivers.
sudo apt install nvidia-driver-460
Now, download the CUDA 11.2.0 .run file from NVIDIA:
wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run
I like to make it executable:
chmod +x cuda_11.2.0_460.27.04_linux.run
Now install CUDA:
sudo ./cuda_11.2.0_460.27.04_linux.run
Accept the EULA:
┌──────────────────────────────────────────────────────────────────────────────┐ │ End User License Agreement │ │ -------------------------- │ │ │ │ NVIDIA Software License Agreement and CUDA Supplement to │ │ Software License Agreement. │ │ │ │ │ │ Preface │ │ ------- │ │ │ │ The Software License Agreement in Chapter 1 and the Supplement │ │ in Chapter 2 contain license terms and conditions that govern │ │ the use of NVIDIA software. By accepting this agreement, you │ │ agree to comply with all the terms and conditions applicable │ │ to the product(s) included herein. │ │ │ │ │ │ NVIDIA Driver │ │ │ │ │ │──────────────────────────────────────────────────────────────────────────────│ │ Do you accept the above EULA? (accept/decline/quit): │ │ accept
Unselect the driver by pressing the spacebar while[X] Driver
is highlighted:
┌──────────────────────────────────────────────────────────────────────────────┐
│ CUDA Installer │
│ - [ ] Driver │
│ [ ] 460.27.04 │
│ + [X] CUDA Toolkit 11.2 │
│ [X] CUDA Samples 11.2 │
│ [X] CUDA Demo Suite 11.2 │
│ [X] CUDA Documentation 11.2 │
│ Options │
│ Install │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │
Then press the down arrow toInstall
. PressEnterthen wait for installation to complete.
After the installation is complete add the following to the bottom of your~/.profile
or add it to the/etc/profile.d/cuda.sh
file which you might have to create for all users (global):
# set PATH for cuda 11.2 installation
if [ -d "/usr/local/cuda-11.2/bin/" ]; then
export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi
Install libcudnn8
Add the Repo:
NOTE:The 20.04 repo from NVIDIA does not supply libcudnn but the 18.04 repo does and installs just fine into 20.04.
echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda_learn.list
Install the key:
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
Update the system:
sudo apt update
Install libcudnn 8.0.4:
sudo apt install libcudnn8
I recommend now to reboot the system for the changes to take effect.
After it reboots check the installations:
$ nvidia-smi
Sat Apr 10 15:13:48 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.39 Driver Version: 460.39 CUDA Version: 11.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 GeForce GTX 750 Ti On | 00000000:01:00.0 On | N/A |
| 42% 50C P0 2W / 38W | 153MiB / 2000MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 4976 G /usr/lib/xorg/Xorg 129MiB |
| 0 N/A N/A 5393 G compton 1MiB |
| 0 N/A N/A 672363 G ...AAAAAAAAA= --shared-files 17MiB |
+-----------------------------------------------------------------------------+
~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293
~$ /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
libcudnn_cnn_infer.so.8 -> libcudnn_cnn_infer.so.8.0.4
libcudnn.so.8 -> libcudnn.so.8.0.4
libcudnn_adv_train.so.8 -> libcudnn_adv_train.so.8.0.4
libcudnn_ops_infer.so.8 -> libcudnn_ops_infer.so.8.0.4
libcudnn_cnn_train.so.8 -> libcudnn_cnn_train.so.8.0.4
libcudnn_adv_infer.so.8 -> libcudnn_adv_infer.so.8.0.4
libcudnn_ops_train.so.8 -> libcudnn_ops_train.so.8.0.4