安装

资源包下载

根据NVIDIA GPU Driver Version,在官网寻找合适的CUDA版本:Release Notes :: CUDA Toolkit Documentation

CUDA Toolkit下载地址:CUDA Toolkit 11.2 Downloads | NVIDIA Developer

cuDNN下载地址:官方cuDNN下载

CUDA Toolkit Toolkit Driver Version
Linux x86_64 Driver Version Windows x86_64 Driver Version
CUDA 11.8 GA >=520.61.05 >=522.06
CUDA 11.7 Update 1 >=515.48.07 >=516.31
CUDA 11.7 GA >=515.43.04 >=516.01
CUDA 11.6 Update 2 >=510.47.03 >=511.65
CUDA 11.6 Update 1 >=510.47.03 >=511.65
CUDA 11.6 GA >=510.39.01 >=511.23
CUDA 11.5 Update 2 >=495.29.05 >=496.13
CUDA 11.5 Update 1 >=495.29.05 >=496.13
CUDA 11.5 GA >=495.29.05 >=496.04
CUDA 11.4 Update 4 >=470.82.01 >=472.50
CUDA 11.4 Update 3 >=470.82.01 >=472.50
CUDA 11.4 Update 2 >=470.57.02 >=471.41
CUDA 11.4 Update 1 >=470.57.02 >=471.41
CUDA 11.4.0 GA >=470.42.01 >=471.11
CUDA 11.3.1 Update 1 >=465.19.01 >=465.89
CUDA 11.3.0 GA >=465.19.01 >=465.89
CUDA 11.2.2 Update 2 >=460.32.03 >=461.33
CUDA 11.2.1 Update 1 >=460.32.03 >=461.09
CUDA 11.2.0 GA >=460.27.03 >=460.82
CUDA 11.1.1 Update 1 >=455.32 >=456.81
CUDA 11.1 GA >=455.23 >=456.38
CUDA 11.0.3 Update 1 >= 450.51.06 >= 451.82
CUDA 11.0.2 GA >= 450.51.05 >= 451.48
CUDA 11.0.1 RC >= 450.36.06 >= 451.22
CUDA 10.2.89 >= 440.33 >= 441.22
CUDA 10.1 (10.1.105 general release, and updates) >= 418.39 >= 418.96
CUDA 10.0.130 >= 410.48 >= 411.31
CUDA 9.2 (9.2.148 Update 1) >= 396.37 >= 398.26
CUDA 9.2 (9.2.88) >= 396.26 >= 397.44
CUDA 9.1 (9.1.85) >= 390.46 >= 391.29
CUDA 9.0 (9.0.76) >= 384.81 >= 385.54
CUDA 8.0 (8.0.61 GA2) >= 375.26 >= 376.51
CUDA 8.0 (8.0.44) >= 367.48 >= 369.30
CUDA 7.5 (7.5.16) >= 352.31 >= 353.66
CUDA 7.0 (7.0.28) >= 346.46 >= 347.62

环境配置

1
2
# 安装依赖
yum install kernel-devel-$(uname -r) gcc dkms -y

安装CUDA

1
2
3
$ wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run

$ sudo sh cuda_11.2.0_460.27.04_linux.run

输入accept,接受User License。

若已安装GPU Driver,则需要取消Driver安装流程。

安装完成。

添加环境变量至/etc/profile,并更新当前环境变量信息:source /etc/profile

1
2
export PATH=/usr/local/cuda-11.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH

安装cuDNN

cuDNN官方下载需要开发者账号,这里可以从百度网盘下载,资源链接:cudnn-11.2-linux-x64-v8.1.0.77,提取码:hq5x

1
2
3
4
5
6
7
8
9
10
11
12
13
# 转换格式
cp cudnn-11.2-linux-x64-v8.1.0.77.solitairetheme8 cudnn-11.2-linux-x64-v8.1.0.77.tgz

# 解压至当前目录
tar zxvf cudnn-11.2-linux-x64-v8.1.0.77.tgz

# 拷贝
cd cuda
cp ./include/cudnn.h /usr/local/cuda-11.2/include
cp ./lib64/libcudnn* /usr/local/cuda-11.2/lib64

# 赋权
chmod a+r /usr/local/cuda-11.2/include/cudnn.h /xxx/xxx/cuda-11.2/lib64/libcudnn*

功能验证

查看版本信息

1
2
3
4
5
6
[root@k104 renyb]# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0

测试CUDA用例

进入测试用例目录:/root/NVIDIA_CUDA-11.2_Samples/1_Utilities/deviceQuery,编译后运行./deviceQuery

PS:编译需要c++环境,安装c++:yum install -y gcc-c++

参考文档