安装cuda和cudnn
原来机器上有安装一个cuda 10.0,想要再安装一个cuda 10.1
安装CUDA
1.首先下载.run文件
https://developer.nvidia.com/cuda-10.1-download-archive-base?target_os=Linux&target_arch=x86_64&target_distro=CentOS&target_version=7&target_type=runfilelocal
2.首先给.run文件执行权限
chmod a+x cuda_10.1.105_418.39_linux.run
3.运行
sh cuda_10.1.105_418.39_linux.run
1)敲accept
2)去掉驱动下载,因为这里我的驱动已经下好
3)yes
4)
需要进行下设置
1》
(base) [root@10_1_5_103 var]# bash -c "echo /usr/local/cuda-10.1/lib64/ > /etc/ld.so.conf.d/cuda.conf" (base) [root@10_1_5_103 var]# ldconfig
2》添加到~/.bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.1/lib64
export PATH=$PATH:/usr/local/cuda-10.1/bin
export CUDA_HOME=/usr/local/cuda-10.1
然后运行source ~/.bashrc
3》同时更改:
# vim /etc/profile
# source /etc/profile
加入:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.1/lib64 export PATH=$PATH:/usr/local/cuda-10.1/bin export CUDA_HOME=/usr/local/cuda-10.1
4》查看cuda版本:
(base) [root@... var]# nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Fri_Feb__8_19:08:17_PST_2019 Cuda compilation tools, release 10.1, V10.1.105
4.测试例子效果:
cd .../NVIDIA_CUDA-10.1_Samples/1_Utilities/bandwidthTest make ./bandwidthTest
返回:
5.查看torch调用的cuda:
>>> import torch
>>> print(torch.version.cuda)
10.0
但是这不说明其使用的真的是这个,查看:
>>> import torch.utils.cpp_extension
>>> torch.utils.cpp_extension.CUDA_HOME
'/usr/local/cuda-10.1'
可见改了
安装cuDNN
打开链接https://developer.nvidia.com/cudnn,需要先注册和填写信息,之后选择对应版本的安装包
1.版本8
1)解压:
tar -zxvf cudnn-10.1-linux-x64-v8.0.5.39.tgz
会在当前文件下生成一个cuda文件夹
2)操作:
sudo cp cuda/include/cudnn.h /usr/local/cuda-10.1/include/ sudo cp cuda/include/cudnn_version.h /usr/local/cuda-10.1/include/ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.1/lib64/ sudo chmod a+r /usr/local/cuda-10.1/include/cudnn.h sudo chmod a+r /usr/local/cuda-10.1/lib64/libcudnn*
3)查看版本:
cat /usr/local/cuda-10.1/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
返回:
#define CUDNN_MAJOR 8 #define CUDNN_MINOR 0 #define CUDNN_PATCHLEVEL 5 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #endif /* CUDNN_VERSION_H */
2.版本7
如果是cudnn7版本的:
1)解压:
tar -zxvf cudnn-10.1-linux-x64-v7.6.5.32.tgz
会在当前文件下生成一个cuda文件夹
2)操作:
sudo cp cuda/include/cudnn.h /usr/local/cuda-10.1/include/ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.1/lib64/ sudo chmod a+r /usr/local/cuda-10.1/include/cudnn.h sudo chmod a+r /usr/local/cuda-10.1/lib64/libcudnn*
3)查看版本:
cat /usr/local/cuda-10.1/include/cudnn.h | grep CUDNN_MAJOR -A 2
返回:
#define CUDNN_MAJOR 7 #define CUDNN_MINOR 6 #define CUDNN_PATCHLEVEL 5 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #include "driver_types.h"