Ubuntu20.04 Linux 5.4.0-62 安装Cuda10.2
一、安装系统推荐NVIDIA显卡驱动
方法1. 安装系统推荐NVIDIA显卡驱动(通常为最新版本)
- 1.1 查看显卡名称及系统推荐驱动
sudo add-apt-repository ppa:graphics-drivers #添加NVIDA显卡驱动库
sudo apt update
ubuntu-drivers devices #显示可安装驱动
运行结果如下图示:
root@labLab:/home/user1/work# ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0 ==
modalias : pci:v000010DEd00001E04sv00001458sd000037C0bc03sc00i00
vendor : NVIDIA Corporation
model : TU102 [GeForce RTX 2080 Ti]
manual_install: True
driver : nvidia-driver-440-server - distro non-free
driver : nvidia-driver-455 - third-party free
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-460 - third-party free recommended # 系统推荐版本
driver : nvidia-driver-450-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
1.2 运行下示命令安装
# 安装系统推荐版本
sudo ubuntu-drivers autoinstall
or
# 手动指定版本安装
sudo apt install nvidia-driver-455
1.3 重启并查看
# 重启系统
sudo reboot
# 查看GPU信息
nvidia-smi
1.4 实例说明:
# 1.我们选择安装系统推荐版本
sudo ubuntu-drivers autoinstall
# 2.重启系统
sudo reboot
# 3. 查看GPU信息
nvidia-smi
运行结果如下:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32 Driver Version: 460.32 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. |
|===============================+======================+======================|
| 0 GeForce RTX 208... Off | 00000000:01:00.0 Off | N/A |
| 0% 31C P0 71W / 250W | 0MiB / 11016MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce RTX 208... Off | 00000000:02:00.0 Off | N/A |
| 0% 30C P0 22W / 250W | 0MiB / 11019MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
方法2. 手动下载驱动安装。
2.1 查看显卡名称
sudo add-apt-repository ppa:graphics-drivers #添加NVIDA显卡驱动库
sudo apt update
ubuntu-drivers devices #显示可安装驱动
运行结果如下图示:
root@labLab:/home/user1/work# ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.1/0000:02:00.0 ==
modalias : pci:v000010DEd00001E04sv00001458sd000037C0bc03sc00i00
vendor : NVIDIA Corporation
model : TU102 [GeForce RTX 2080 Ti] # 显卡型号
manual_install: True
driver : nvidia-driver-440-server - distro non-free
driver : nvidia-driver-455 - third-party free
driver : nvidia-driver-418-server - distro non-free
driver : nvidia-driver-460 - third-party free recommended
driver : nvidia-driver-450-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
2.2 去nvidia官网下载驱动
nvidia官网:https://www.nvidia.com/Download/index.aspx
点击search
。
点击download
,进行下载页面。
在上图,右键点击download
,选择复制链接地址
。并通过wget
下载驱动。
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/460.32.03/NVIDIA-Linux-x86_64-460.32.03.run
2.3 运行下示命令安装驱动
sh NVIDIA-Linux-x86_64-460.32.03.run
二、安装指定版本(Cuda10.2)驱动
方法3. 安装指定版本的驱动
3.1 进入nvidia官网驱动高级查找:https://www.nvidia.com/Download/Find.aspx?lang=en-us
点击search
找到指定版本的驱动。
3.2 实列说明:
我们想使用CUDA 10.2
,查下表后,故选择440.64
版本的驱动。按照方法二下载驱动、安装、重启即可。
运行结果如下:
# 查看GPU信息
nvidia-smi
# 运行结果
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64 Driver Version: 440.64 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| 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 208... Off | 00000000:01:00.0 Off | N/A |
| 0% 31C P0 71W / 250W | 0MiB / 11016MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce RTX 208... Off | 00000000:02:00.0 Off | N/A |
| 0% 30C P0 22W / 250W | 0MiB / 11019MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
3.3 安装cuda-toolkit-10-2
sudo apt install cuda-toolkit-10-2
安装全部完成,结果如下图示。
# linux系统信息
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-62-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
3 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
1 updates could not be installed automatically. For more details,
see /var/log/unattended-upgrades/unattended-upgrades.log
# nvcc -V
# 运行结果
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
# nvidia-smi
# 运行结果
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64 Driver Version: 440.64 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| 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 208... Off | 00000000:01:00.0 Off | N/A |
| 0% 31C P0 71W / 250W | 0MiB / 11016MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce RTX 208... Off | 00000000:02:00.0 Off | N/A |
| 0% 30C P0 22W / 250W | 0MiB / 11019MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
# 运行程序测试
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64 Driver Version: 440.64 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| 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 208... Off | 00000000:01:00.0 Off | N/A |
| 0% 32C P0 43W / 250W | 0MiB / 11016MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce RTX 208... Off | 00000000:02:00.0 Off | N/A |
| 0% 38C P2 233W / 250W | 9580MiB / 11019MiB | 99% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 1 188850 C python 9569MiB |
+-----------------------------------------------------------------------------+