ubuntu安装cuda和cudnn

ubuntu18.04+cuda11.1+cudnn8

卸载

卸载cuda(根据自己的版本来)

sudo /usr/local/cuda-10.2/bin/cuda-uninstaller

或者

sudo apt-get --purge remove "*cublas*" "*cufft*" "*curand*" "*cusolver*" "*cusparse*" "*npp*" "*nvjpeg*" "cuda*" "nsight*"
sudo apt-get remove cuda
sudo rm -r cuda-11.1

卸载cudnn(根据自己的版本来)

deb安装

sudo apt-get remove libcudnn8-samples
sudo apt-get remove libcudnn8-dev
sudo apt-get remove libcudnn8

通过压缩包安装的cudnn随着cuda卸载

deb版本

安装前卸载之前安装的cuda和cudnn

安装cuda

下载地址

官网命令

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.1.1/local_installers/cuda-repo-ubuntu1804-11-1-local_11.1.1-455.32.00-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-1-local_11.1.1-455.32.00-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

添加环境变量(/etc/profile或者~/.bashrc

vim ~/.bashrc
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

刷新

source ~/.bashrc

验证

nvcc -V

安装cudnn

下载地址

sudo dpkg -i libcudnn8_8.0.2.39-1+cuda10.2_amd64.deb 
sudo dpkg -i libcudnn8-dev_8.0.2.39-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn8-doc_8.0.2.39-1+cuda10.2_amd64.deb

查看版本

cat /usr/include/cudnn_version.h

验证

cp -r /usr/src/cudnn_samples_v8/ $HOME
cd ~/cudnn_samples_v8/mnistCUDNN/
make clean && make
./mnistCUDNN

结果:Test passed!

run版本

安装cuda

sudo chmod a+x cuda_11.0.2_450_51.05_linux.run
sudo ./cuda_11.0.2_450_51.05_linux.run

选项中去掉安装驱动的选项

安装显卡驱动会默认安装对应版本的cuda,此时会提示已经存在cuda。 继续安装

是否接收协议。 接收

出现一系列安装提示。 不安装显卡驱动

是否生成/更新动态链接/usr/local/cuda更新

如果出现动态链接库链接不到的情况,建立软连接

sudo ln -sf /usr/local/cuda-9.0/targets/x86_64-linux/lib/libcudnn.so.7.4.2 /usr/local/cuda-9.0/targets/x86_64-linux/lib/libcudnn.so.7

添加环境变量(/etc/profile或者~/.bashrc

vim ~/.bashrc
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

刷新

source ~/.bashrc

验证

cd /usr/local/cuda/samples/1_Utilities/deviceQuery 
sudo make
./deviceQuery

结果Result = PASS

安装cudnn

使用编译好的压缩包形式

解压对应版本的压缩包

sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

验证&查看版本

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
posted @ 2021-08-30 13:38  xiaowk5516  阅读(2160)  评论(0编辑  收藏  举报