安装CUDA、CUDNN
安装CUDA、CUDNN
可以去英伟达官网下载、安装最新的的版本,也可以根据自己需求去CUDA历史版本、CUDNN历史版本下载自己需要的版本。附送CUDA、CUDNN与tensorflow版本对应关系。
1、安装CUDA
1.1 下载cuda
(python-3.7) root@7a927d2dc743:~# wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
(python-3.7) root@7a927d2dc743:~# ll -d cuda_10.2.89_440.33.01_linux.run
-rw-r--r-- 1 root root 2645419389 Nov 13 2019 cuda_10.2.89_440.33.01_linux.run
1.2 安装cuda
(python-3.7) root@7a927d2dc743:~# sh cuda_10.2.89_440.33.01_linux.run --silent --toolkit --samples --librarypath=/usr/local/cuda-10.2
1.3 检查安装的版本
(python-3.7) root@7a927d2dc743:~# ln -s /usr/local/cuda/bin/nvcc /usr/bin/nvcc-python-3.7
(python-3.7) root@7a927d2dc743:~# which nvcc-python-3.7
/usr/bin/nvcc-python-3.7
(python-3.7) root@7a927d2dc743:~# nvcc-python-3.7 -V
nvcc-python-3: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
1.4 添加环境变量
#添加环境变量到 ~/.bashrc 文件的末尾
(python-3.7) root@7a927d2dc743:~# vim ~/.bashrc
(python-3.7) root@7a927d2dc743:~# tail -3 ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
#激活环境变量
(python-3.7) root@7a927d2dc743:~# source ~/.bashrc
1.5 测试 CUDA Toolkit 以验证是否安装成功
#Result = PASS则安装成功
(python-3.7) root@7a927d2dc743:~# cd /usr/local/cuda/extras/demo_suite/
(python-3.7) root@7a927d2dc743:/usr/local/cuda/extras/demo_suite# ./deviceQuery
......
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.6, CUDA Runtime Version = 10.2, NumDevs = 4, Device0 = NVIDIA GeForce RTX 2080 Ti, Device1 = NVIDIA GeForce RTX 2080 Ti, Device2 = NVIDIA GeForce RTX 2080 Ti, Device3 = NVIDIA GeForce RTX 2080 Ti
Result = PASS
2、安装CUDNN
2.1 下载cudnn
(python-3.7) root@7a927d2dc743:~# ll -d cudnn-10.2-linux-x64-v7.6.5.32.tgz
-rw-r--r-- 1 root root 548210361 Mar 29 09:54 cudnn-10.2-linux-x64-v7.6.5.32.tgz
#解压缩
(python-3.7) root@7a927d2dc743:~# tar xf cudnn-10.2-linux-x64-v7.6.5.32.tgz
(python-3.7) root@7a927d2dc743:~# ll -d cuda
drwxr-xr-x 4 root root 70 Mar 29 09:55 cuda/
2.2 安装cudnn
#把相应的文件,复制到指定目录即可
(python-3.7) root@7a927d2dc743:~# cp cuda/include/cudnn* /usr/local/cuda/include/
(python-3.7) root@7a927d2dc743:~# cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
#添加权限
(python-3.7) root@7a927d2dc743:~# chmod a+r /usr/local/cuda/include/cudnn* /usr/local/cuda/lib64/libcudnn*