首页 > 系统相关 >Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6

Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6

时间:2022-12-04 10:05:39浏览次数:78  
标签:non Ubuntu22.04 sudo driver Cuda11.8 nvidia cudnn8.6 安装 distro


Ubuntu22.04+Nvidia驱动+Cuda11.8


Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6_linux

一、准备环境

  • ubuntu 22.04
  • nvidia显卡 这里使用的是RTX3060
  • 已安装Python3.10

二、安装pip3

# 安装
sudo apt install python3-pip
# 升级
sudo pip3 install --upgrade pip
# 如果要卸载,使用命令:
sudo apt-get remove python3-pip

三、Nvidia驱动安装

1. 禁用 Nouveau驱动

sudo vim /etc/modprobe.d/blacklist-nouveau.conf

2、添加两行语句:

blacklist nouveau
options nouveau modeset=0

3、更新initramfs

sudo update-initramfs -u

4、重启

reboot

5、验证,终端输入语句,

lsmod | grep nouveau
# 没有输出说明操作成功

2. 确定要安装的驱动版本

cat /proc/driver/nvidia/version

3. 两种安装方式

(1)自动安装驱动

# 查找可选择安装的版本自动安装
sudo ubuntu-drivers autoinstall

(2)指定驱动安装

# 列出设备,显示的model是显卡型号,driver是可选的驱动
ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002504sv00001458sd00004072bc03sc00i00
vendor : NVIDIA Corporation
model : GA106 [GeForce RTX 3060 Lite Hash Rate]
manual_install: True
driver : nvidia-driver-470-server - distro non-free
driver : nvidia-driver-515-server - distro non-free
driver : nvidia-driver-510-server - distro non-free
driver : nvidia-driver-470 - distro non-free
driver : nvidia-driver-510 - distro non-free
driver : nvidia-driver-520 - distro non-free
driver : nvidia-driver-515-open - distro non-free
driver : nvidia-driver-520-open - distro non-free recommended
driver : nvidia-driver-515 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin

# 安装其中 recommended 一个驱动
sudo apt install nvidia-driver-520-open
sudo reboot

如果出现 : ​​Failed to initialize NVML: Driver/library version mismatch​​​,则可能是版本不对。
我这很不幸地出现 : ​​​no devices were found​​,最后使用下面方式安装成功。

(3)到官网下载驱动安装

​https://www.nvidia.com/Download/index.aspx?lang=en-us​

# 查看显卡型号
lspci -vnn | grep VGA
# 卸载旧驱动
sudo apt-get remove --purge nvidia*
# 给run文件可执行权限
sudo chmod a+x NVIDIA-Linux-x86_64-515.86.01.run
# 安装
sudo ./NVIDIA-Linux-x86_64-440.64.run -no-x-check -no-nouveau-check -no-opengl-files
# -no-x-check:安装驱动时关闭X服务
# -no-nouveau-check:安装驱动时禁用nouveau
# -no-opengl-files:只安装驱动文件,不安装OpenGL文件

提示: ​​Would you like to register the kernel module sources with DKMS? ​​​ 选择No
提示: ​​​Nvidia's 32-bit compatibility libraries?​​​ 选择No
提示: ​​​Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x?​​ 选择Yes

安装完重新启动电脑。

二、安装Cuda

1. 下载Cuda

​https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu​​​ 我这里下载的是Cuda11.8:
Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6_linux_02

需要注意的是,之前已经安装过显卡驱动程序,在提问是否安装显卡驱动时选择no
其他 选择默认路径或者yes即可。

2. 如果之前已经安装了Cuda,则卸载掉。

sudo /usr/local/cuda-11.8/bin/uninstall_cuda_8.0.pl
sudo rm -rf /usr/local/cuda-8.0

3. 安装

chomd +x cuda_11.8.0_520.61.05_linux.run
sudo ./cuda_11.8.0_520.61.05_linux.run

三、安装cuDNN

​https://developer.nvidia.com/rdp/cudnn-download​​ 这里下载 deb 格式,安装:

sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.0_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2204-8.6.0.163/cudnn-local-FAED14DD-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get install libcudnn8=8.6.0.163-1+cuda11.8 # 这里输入到=按tab补全即可,安装运行库
sudo apt-get install libcudnn8-dev=8.6.0.163-1+cuda11.8 # 通过tab自动补全,安装developer 库
sudo apt-get install libcudnn8-samples=8.6.0.163-1+cuda11.8 # 通过tab自动补全,安装示例和文档

测试:

cp -r /usr/src/cudnn_samples_v8/ $HOME 
cd ~/cudnn_samples_v8/mnistCUDNN/
make clean && make
# 如果提示下面截图中的错误,就执行下面语句安装freeimage3库
sudo apt-get install libfreeimage3 libfreeimage-dev

Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6_python_03

运行测试:

./mnistCUDNN

Ubuntu22.04+Nvidia驱动+Cuda11.8+cudnn8.6_bc_04


标签:non,Ubuntu22.04,sudo,driver,Cuda11.8,nvidia,cudnn8.6,安装,distro
From: https://blog.51cto.com/u_4029519/5909904

相关文章