安装显卡驱动、CUDA及cudnn

  • 显卡驱动
  • 自行下载安装
  • Software & Updates安装
  • 使用命令安行安装
  • Ubuntu22.04系统安装CUDA
  • 一、CUDA 是什么
  • 先查看有没有安装CUDA 在终端输入命令
  • 修改环境变量
  • Ubuntu22.04安装cuDNN
  • 参考文献


显卡驱动

自行下载安装

查看显卡型号命令:

lspci | grep -i vga
 
#----output------
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1f06 (rev a1)

可以看到,查看到的显卡型号名称是一个十六进制数字代码。

接下来将得到的十六进制数字代码,带入网址中查询具体显卡型号。

The PCI ID Repository可以按照十六进制数字代码找到相应的显卡型号。

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_CUDA

得到结果如下:

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_linux_02


然后登录英伟达官网官网驱动|英伟达

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_linux_03

然后安装

例如

sudo ./NVIDIA-Linux-x86_64-515.57.run

Software & Updates安装

打开Software & Updates点击Additional Drivers,会依据显示进行推荐

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_CUDA_04

使用命令安行安装

先运行

sudo ubuntu-drivers devices

得到如下结果

WARNING:root:_pkg_get_support nvidia-driver-390: package has invalid Support Legacyheader, cannot determine support level
== /sys/devices/pci0000:00/0000:00:03.0/0000:04:00.0 ==
modalias : pci:v000010DEd000011B4sv000010DEsd00001096bc03sc00i00
vendor   : NVIDIA Corporation
model    : GK104GL [Quadro K4200]
driver   : nvidia-340 - distro non-free
driver   : nvidia-driver-418-server - distro non-free
driver   : nvidia-driver-390 - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-470 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

按照推荐进行安装

sudo apt install nvidia-driver-470

Ubuntu22.04系统安装CUDA

一、CUDA 是什么

cuda是Compute Unified Device Architecture的缩写。中文叫统一计算架构。是为了让Nvidia GPU(可以通俗理解成显卡,但是与显卡有不同)可以完成通用计算任务的一种集成技术。我们通常可以使用的cuda框架有c,c++,fortran,python,java的,可以为数据大吞吐量的工作提供很好的加速功能。

先查看有没有安装CUDA 在终端输入命令

nvcc -V 
#或者
nvcc --version

显示

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_ubuntu22 安装 ceres_05


否则,需要安装cuda,查看有没有安装显卡驱动

查看Driver对应的CUDA version

终端输入nvidia-smi,显示

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_linux_06


这里的Driver version为当前显卡驱动的版本,CUDA Version为可支持的最高版本的cuda到cuda-toolki-archive,下载对应的cuda

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_ubuntu_07

选择了对应的属性之后,在终端依次输入Installation Instructions的指令

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_linux_08

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

如果安装cuda过程中出现

Failed to verify gcc version

那么很有可能你的gcc版本太高,例如:cuda 10.1要求gcc版本是7.3.0,但是ubuntu 20.04/linux mint 20默认gcc版本为9.3.0,所以可以增加参数安装--override

这时候因为前面步骤已经安装了Driver,这里会提示Existing package manager installation of the driver found. It is strongly recommended that you remove this before continuing.,我们选择continue即可,然后出现下面这样的界面,enter一下把Driver取消

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_ubuntu22 安装 ceres_09


安装过程结束后,显示下面界面

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_运维_10

修改环境变量

vim ~/.bashrc

在最后输入:

export PATH="/usr/local/cuda-10.2/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH"

注意根据自己的cuda版本进行修改

接着source ~/.bashrc一下

最后再输入nvcc -V或者nvcc --version,显示

ubuntu22 安装 ceres ubuntu22 安装 intel 显卡驱动_ubuntu22 安装 ceres_05


表示安装成功