NVIDIA显卡驱动-CUDA-CUDNN安装

NVIDIA显卡驱动-CUDA-CUDNN安装

查看显卡型号

方法一
lspci | grep -i vga查看 一个十六进制数字代码,在 http://pci-ids.ucw.cz/mods/PC/10de?action=help?help=pci 上搜索即可获取显卡型号

方法二
如果无法获取十六进制数字代码,则lspci | grep -i nvidia

驱动安装

驱动下载 link: https://www.nvidia.cn/Download/index.aspx#

卸载驱动

cd /usr/bin
./nvidia-uninstall
sudo apt-get --purge remove "*nvidia*"
sudo apt autoremove

# To remove CUDA Toolkit:
sudo apt-get --purge remove "*cublas*" "cuda*"

禁用nouveau

安装nvidia显卡驱动首先需要禁用nouveau,不然会碰到冲突的问题,导致无法安装nvidia显卡驱动

/etc/modprobe.d/blacklist.conf末尾添加

blacklist nouveau
options nouveau modeset=0

更新系统修改

sudo update-initramfs -u
sudo rmmod nouveau

输入指令后重启系统(一定要重启),确保到位

验证nouveau是否已禁用

lsmod | grep nouveau

下载驱动文件并指令安装

关闭图形界面(不执行后面会出错)

sudo service lightdm stop

安装依赖

sudo apt install build-essential
# 该命令将安装一堆新包,包括gcc,g ++和make。

安装

sudo chmod  a+x NVIDIA-Linux-x86_64-396.18.run
sudo ./NVIDIA-Linux-x86_64-396.18.run -no-x-check -no-nouveau-check -no-opengl-files

#The distribution-provided pre-install script failed! Are you sure you want to continue? 
#选择 yes 继续。

#Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later?  
#选择 No 继续。

#Install 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? Any pre-existing x confile will be backed up. 
#选择 Yes 继续

安装CUDA和cuDNN

安装CUDA

link: https://developer.nvidia.com/cuda-toolkit-archive

$ sudo chmod +x cuda_{xx.x.xxx_xxx.xx}_linux.run
$ sudo sh cuda_10.2.89_440.33.01_linux.run
Do you accept the previously read EULA?
accept/decline/quit: accept

#是否安装显卡驱动,选择否
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 {xxx.xx}?
(y)es/(n)o/(q)uit: n

#是否安装cuda
Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

#输入cuda的安装路径,默认
Enter Toolkit Location
[ default is /usr/local/cuda-10.0 ]: 

#是否建立/usr/local/cuda -> /usr/local/cuda-10.x的软连接
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

#是否安装CUDA示例
Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: n

增加环境变量

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin

查看cuda版本

$ nvcc -V

安装cuDNN

link: https://developer.nvidia.com/rdp/cudnn-archive

$ tar -zxvf cudnn-{CUDA version i.e. 10.0}-linux-x64-v7.6.5.32.tgz
sudo cp cuda/include/cudnn* /usr/local/cuda/include
sudo cp -d cuda/lib64/libcudnn* /usr/local/cuda/lib64

查看cuDNN版本

$ vim /usr/local/cuda/include/cudnn_version.h

驱动掉了怎么处理

如果出现因为更新了系统内核导致的驱动掉了有两种解决方法:

  • 可以卸载驱动,再次编译安装
  • 也可以通过dkms的方法
sudo apt-get install dkms
ls -l /usr/src/
sudo dkms install -m nvidia -v 470.103.01
posted @ 2022-09-16 18:12  nanmi  阅读(127)  评论(0编辑  收藏  举报