Ubuntu22.04安装CUDA和cuDNN

1. 安装显卡驱动

 获取显卡和驱动信息

ubuntu-drivers devices

 安装N卡驱动

sudo apt install nvidia-driver-*

重启,测试是否安装成功

nvidia-smi

2. 安装CUDA

访问官网,选择deb或runfile安装,比如,deb安装:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

配置环境变量

nano ~/.bashrc
export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH

执行

source ~/.bashrc

验证是否安装成功

nvcc -V

3. 安装cuDNN

访问官网,下载相应压缩文件,按照如下命令安装:

tar -xvf cudnn-linux-x86_64-8.9.1.23_cuda11-archive.tar.xz
sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda-11.8/include
sudo cp -P cudnn-*-archive/lib/libcudnn* /usr/local/cuda-11.8/lib64
sudo chmod a+r /usr/local/cuda-11.8/include/cudnn*.h /usr/local/cuda-11.8/lib64/libcudnn*

验证是否安装成功 

cat /usr/local/cuda-11.8/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

4. 更换cuDNN版本

删除已安装的cuDNN版本

sudo rm -rf /usr/local/cuda-11.8/include/cudnn.h
sudo rm -rf /usr/local/cuda-11.8/lib64/libcudnn*

更新软链接

cd /usr/local/cuda-11.8/lib64/
sudo chmod +r libcudnn.so.8.9.1
sudo ln -sf libcudnn.so.8.9.1 libcudnn.so.8
sudo ln -sf libcudnn.so.8 libcudnn.so
sudo ln -sf libcudnn_adv_train.so.8.9.1 libcudnn_adv_train.so.8
sudo ln -sf libcudnn_adv_infer.so.8.9.1 libcudnn_adv_infer.so.8
sudo ln -sf libcudnn_ops_train.so.8.9.1 libcudnn_ops_train.so.8
sudo ln -sf libcudnn_ops_infer.so.8.9.1 libcudnn_ops_infer.so.8
sudo ln -sf libcudnn_cnn_infer.so.8.9.1 libcudnn_cnn_infer.so.8
sudo ln -sf libcudnn_cnn_train.so.8.9.1 libcudnn_cnn_train.so.8
sudo ldconfig  # 检查是否存在可共享的动态链接库

检查版本

cat /usr/local/cuda-11.8/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

5. 其他安装方式指南 

Ubuntu PPA源-CSDN博客

【精选】ubuntu2004安装cuda11.7+cuDNN8.6 deb版本-CSDN博客

Ubuntu Server 20.04 系统安装(四):深度学习 GPU 环境配置(CUDA Toolkit 11.7+cuDNN v8.4.1)【重启生效】【安装后默认安装了gnome,需手动删掉】_u013250861的博客-CSDN博客

你可能感兴趣的:(Ubuntu,ubuntu,linux)