前言
用deb方式安装的cuda,进行卸载。我目前是卸载10.1,安装10.2或者11.6。
CUDA与显卡型号是对应的,若显卡升级了,那CUDA也要跟着升级,不然无法适配显卡,找不到设备。
- RTX2060s/RTX2070s 可以对用CUDA11.6,cudnn8.4.0, Driver Version 510
- RTX3050 用CUDA11.6就不行了。先安装software&update中适配的驱动,然后在完善相关的CUDA和CUDNN
显卡基本信息
一、卸载
参考的方法完全卸载cuda
- 参考problem-while-installing-cuda-toolkit-in-ubuntu-18-04
- 1.1 首先关闭使用NVIDIA的驱动程序
You have to uninstall any nvidia driver before running sudo apt install -y cuda To do so, got to "Software & Updates" -> "Additional drivers" -> Using X.Org X (nouveou)
- 1.2 清除cuda,另外
sudo apt clean sudo apt update sudo apt purge nvidia-* sudo apt autoremove
旧方法(2023.11.15推荐),先使用sudo apt-get --purge remove,再逐个文件夹删除,也清除得很彻底
第一步
sudo apt-get --purge remove cuda
# 自动删除一些没有依赖的cuda文件(此处注意不要删掉ros相关,以及内核文件相关,要么就不执行这一句,避免误删)
# 我尝试了下,果然把ros相关的也删除了,不过roscore还能用,关键是我希望把cuda安装好,ros之类可以重新装
sudo apt autoremove
# 删除cuda-10.1/11.6文件夹
sudo rm -rf /usr/local/cuda
sudo rm -rf /usr/local/cuda-*
# 查看关联文件,逐个删除
sudo find / -name cuda-*
# 尤其注意如下几个文件位置
sudo rm -rf /var/cuda*
sudo rm -rf /var/cudnn*
sudo rm -rf /usr/share/doc/cuda*
sudo rm -rf /usr/share/doc/cudnn*
sudo rm /etc/apt/sources.list.d/cuda*
sudo rm /etc/apt/sources.list.d/cudnn*
sudo rm /usr/lib/pkgconfig/cuda*
# 自动删除
sudo apt-get autoclean
# 注意
如果使用上面`sudo rm /etc/apt/sources.list.d/cuda*`会让`sudo apt update`时找不到cuda的源。需要逐个移除
sudo dpkg -l cuda # tab一下
sudo dpkg -P cuda # tab一下
# 删除cuDNN
sudo apt-get --purge remove libcudnn8
cd /usr/local/include/
sudo rm cudnn.h
cd /usr/local/lib/
sudo rm libcudnn.*
# 删除TensorRT
sudo apt-get --purge remove nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.1.3.4-ga-20200617
sudo rm /etc/apt/sources.list.d/nv-tensorrt-cuda10.2-trt7.1.3.4-ga-20200617.list.save
# 配置文件
cd /etc/ld.so.conf.d/
# 看下哪些和cuda有关?都删掉
sudo rm /etc/ld.so.conf.d/cuda-10-1.conf
# 旧的更新地址
sudo rm /etc/apt/sources.list.d/cuda-10-1-local-10.1.243-418.87.00.list.save
# 旧的dpkg信息
sudo rm /var/lib/dpkg/info/cuda-*
二、安装
先用这个选定显卡驱动,然后让它自动安装显卡驱动
接下来再进入官网,按照最新的安装命令,这里是cuda历史版本
https://developer.nvidia.com/cuda-toolkit-archive
下面是针对ubuntu18的,如果是20.04,则参考官网
2. 下载cuda-10.2
# 网址
[cuda-10.2 official link]](https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=deblocal)
# 按照官网指令执行
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
# 安装补丁
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local_10.2.1-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local_10.2.2-1_amd64.deb
2.下载cuda-11-6
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu1804-11-6-local_11.6.0-510.39.01-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-6-local_11.6.0-510.39.01-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-6-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
- 下载cudnn-7.6.5 (对应cuda-10-2)
# 网址
https://developer.nvidia.com/rdp/cudnn-archive
# 找到这三个文件
# 包含了某些深度学习应用
# cuDNN Runtime Library for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
# 包含了在Ubuntu系统上开发深度学习时所需的cuDNN头文件
# cuDNN Developer Library for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb
# 包含了cuDNN例程和相关文档
# cuDNN Code Samples and User Guide for Ubuntu18.04 (Deb)
sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb
3.下载cudnn-8.4.0(对应cuda-11-6)文章来源:https://www.toymoban.com/news/detail-415280.html
# 网址
https://developer.nvidia.com/rdp/cudnn-archive
# 点击下载,只有一个文件
https://developer.nvidia.com/compute/cudnn/secure/8.4.0/local_installers/11.6/cudnn-local-repo-ubuntu1804-8.4.0.27_1.0-1_amd64.deb
# 安装
sudo dpkg -i cudnn-local-repo-ubuntu1804-8.4.0.27_1.0-1_amd64.deb
# 更新一下
sudo apt-get update
# 安装依赖
sudo apt-get install libcudnn8=8.4.0.27-1+cuda11.6
sudo apt-get install libcudnn8-dev=8.4.0.27-1+cuda11.6
sudo apt-get install libcudnn8-samples=8.4.0.27-1+cuda11.6
注意: cudnn-8.5.0对应cuda-11-7
3.1 验证安装文章来源地址https://www.toymoban.com/news/detail-415280.html
cp -r /usr/src/cudnn_samples_v8/ $HOME
cd $HOME/cudnn_samples_v8/mnistCUDNN
make clean && make
./mnistCUDNN
- 配置环境变量
# 配置环境变量
sudo gedit ~/.zshrc
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# 更新环境变量
source ~/.zshrc
# 查看cuda是否安装成功
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
# 显示
Wed Jan 4 11:06:49 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 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 207... On | 00000000:01:00.0 On | N/A |
| 40% 24C P8 24W / 215W | 532MiB / 7979MiB | 1% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1102 G /usr/lib/xorg/Xorg 56MiB |
| 0 1159 G /usr/bin/gnome-shell 49MiB |
| 0 2326 G /usr/lib/xorg/Xorg 259MiB |
| 0 2481 G /usr/bin/gnome-shell 156MiB |
| 0 2525 G /opt/teamviewer/tv_bin/TeamViewer 2MiB |
| 0 2938 G gnome-control-center 2MiB |
+-----------------------------------------------------------------------------+
参考
- 参考该教程花花少年
- 参考problem-while-installing-cuda-toolkit-in-ubuntu-18-04
到了这里,关于cuda卸载与安装的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!