由于项目开发中需要使用版本8的cudnn,目前系统配置是版本7,因此需要更新cudnn
当前系统配置:
操作系统:Ubuntu 18.04
cuda版本:cuda10.2
cudnn版本:cudnn7.3.1
cuda查看
nvcc -V
cudnn查看
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
如果以压缩包的形式安装,则删除以下两个文件夹中cudnn文件:
sudo rm -rf /usr/local/cuda/include/cudnn.h
sudo rm -rf /usr/local/cuda/lib64/libcudnn*
如果以deb的形式安装,则删除以下内容
sudo rm -rf /usr/local/cuda/targets/x86_64-linux/include/cudnn.h
sudo rm -rf /usr/lib/x86_64-linux-gnu/libcudnn*
sudo rm -rf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn*
sudo rm -rf /usr/share/doc/libcudnn*
sudo rm -rf /var/lib/dpkg/info/libcudnn*
sudo rm -rf /usr/share/lintian/overrides/libcudnn*
有时候安装
登录nvidia官网下载,链接如下:cuDNN Download | NVIDIA Developer页面截图如下,
勾选I agree选项,会出现下图内容,点击红框内选项,即可根据自己需要选择合适的版本。
根据环境cuda版本和个人需要,我选择版本如下:
安装有两种方法:
1)选择上图中红色框一个压缩包文件下载解压
2)选择上图中蓝色框三个文件下载解压
我使用第一种方法安装,解压后里面是名为cuda的文件夹
cd cuda 进入该文件夹,输入如下命令,将文件复制到系统cuda文件夹内
sudo cp include/cudnn.h /usr/local/cuda/include/
sudo cp include/cudnn_version.h /usr/local/cuda/include/
sudo cp lib64/lib* /usr/local/cuda/lib64/
注意这里版本7和版本8不同,版本8信息在cudnn_version.h中,若想用命令查看版本,需要复制该文件。而版本7在cudnn.h中,注意复制时候
然后建立软链接
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.8.0.4
sudo ln -sf libcudnn.so.8.0.4 libcudnn.so.8
sudo ln -sf libcudnn.so.8 libcudnn.so
sudo ldconfig
此时安装成功,然后输出版本查看命令
cat /usr/local/cuda/include/cudnn-version.h | grep CUDNN_MAJOR -A 2
输出正确版本信息则安装成功
root@ubuntu:~# cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 0
#define CUDNN_PATCHLEVEL 4
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#endif /* CUDNN_VERSION_H */
步骤4输入sudo ldconfig 可能会报以下错误
root@ubuntu:/usr/local/cuda/lib64# sudo ldconfig
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 is not a symbolic link
解决方法:建立软链接即可,cuda-10.2替换为自己的版本
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
sudo ln -sf /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.4 /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
更换cudnn版本后,以前配置的虚拟环境可能失效,无法调用cudnn 需要重新配置