win11安装cudatoolkit11.1与cudnn8.0.

1. 软硬件资源
- win 11 32内存
- 显卡 RTX 2080Ti ,驱动版本号:516.59
- python 3.8.10
- torch 1.8.0 框架
- cudatoolkit 11.1
- cudnn 8.0.4
2. 查看适用cuda版本
2.1 查看本机的cuda算力
安装之前先进入官网查看自己的显卡能不能用,可以去https://developer.nvidia.com/cuda-gpus查看支持cuda的显卡,

发现自已的显卡支持算力是 7.5
2.2 查看支撑CUDA的最大版本
nvidia-smi

如红色标记,,本机配置最大版本可以安装到11.7,所以CUDA version11.7以下都可以安装。
2.3 CUDA驱动和CUDA Toolkit对应版本
表一:CUDA驱动及CUDA Toolkit最高对应版本

最新可查阅官方文档
注:驱动是向下兼容的,其决定了可安装的CUDA Toolkit的最高版本。
cuDNN与CUDA
官网:https://developer.nvidia.com/rdp/cudnn-archive
cuDNN | CUDA |
---|---|
8.1.0 | 11.2、11.1、11.0、10.2 |
8.0.5 | 11.1、11.0、10.2、10.1 |
8.0.4 | 11.1、11.0、10.2、10.1 |
8.0.3 | 11.0、10.2、10.1 |
8.0.2 | 11.0、10.2、10.1 |
8.0.1 | 11.0、10.2 |
7.6.5 | 10.2、10.1、10.0、9.2、9.0 |
7.6.4 | 10.1、10.0、9.2、9.0 |
7.6.3 | 10.1、10.0、9.2、9.0 |
7.6.2 | 10.1、10.0、9.2、9.0 |
7.6.1 | 10.1、10.0、9.2、9.0 |
7.6.0 | 10.1、10.0、9.2、9.0 |
7.5.1 | 10.1、10.0、9.2、9.0 |
7.5.0 | 10.1、10.0、9.2、9.0 |
7.4.2 | 10.0、9.2、9.0 |
7.4.1 | 10.0、9.2、9.0 |
7.4.0 | 10.0、9.2、9.0 |
7.3.0 | 10.0、9.0 |
7.2.1 | 9.2 |
2.4 CUDA Toolkit版本与PyTorch对应版本
表二:CUDA Toolkit版本及可用PyTorch对应关系(参考官网)
CUDAToolkit版本 | 可用PyTorch版本 |
---|---|
7.5 | 0.4.1 ,0.3.0, 0.2.0,0.1.12-0.1.6 |
8.0 | 1.1.0,1.0.0 ,0.4.1 |
9.0 | 1.1.0,1.0.1, 1.0.0,0.4.1 |
9.2 | 1.7.1,1.7.0,1.6.0,1.5.1,1.5.0,1.4.0,1.2.0,0.4.1 |
10.0 | 1.2.0,1.1.0,1.0.1 ,1.0.0 |
10.1 | 1.7.1,1.7.0,1.6.0,1.5.1,1.5.0, 1.4.0,1.3.0 |
10.2 | 1.7.1,1.7.0,1.6.0,1.5.1,1.5.0 |
11.0 | 1.7.1,1.7.0 |
11.1 | 1.8.0,1.8.1,1.9.0,1.9.1,1.10.0,1.10.1 |
注:虽有的卡驱动更新至较新版本,且CUDA Toolkit及PyTorch也可对应更新至新版本。但有的对应安装包无法使用,有可能是由于卡太旧的原因。
2.5 选定版本
选择:本次决定安装 version 11.1。
3. cuda安装
3.1 cuda和cudnn下载
3.1.1 cuda下载
在nvidia官网下载cuda版本11.1.1,并安装
地址为https://developer.nvidia.com/cuda-toolkit-archive。建议采用runfile(local)方式下载安装。


[图片上传失败...(image-db05d0-1657798556437)]
3.1.2 cudnn下载
从nvidia官网下载cudnn8.0
https://developer.nvidia.com/rdp/cudnn-archive

3.2 cuda安装
安装exe软件包,下一步,走起!
1. 先安装VS2019(很重要)
2. cuda的驱动也要安装,我这里提前安装好啦
安装具体也可参考cuda和VS的安装


下载完打开安装程序,安装路径选择自定义,自定义选项,选择cuda 打勾,然后一路下一步安装完成



安装cuda时,只选中CUDA(但是里面有一个VS没有选择,其余都选择啦),其余未选中,然后默认安装。
安装完成后出现一些log信息,这些信息不影响,毕竟我已经提前安装VS2019啦。
Installed:
- Nsight for Visual Studio 2019
- Nsight Monitor
Not Installed:
- Nsight for Visual Studio 2017
Reason: VS2017 was not found
- Nsight for Visual Studio 2015
Reason: VS2015 was not found
- Integrated Graphics Frame Debugger and Profiler
Reason: see https://developer.nvidia.com/nsight-vstools
- Integrated CUDA Profilers
Reason: see https://developer.nvidia.com/nsight-vstools
3.3 配置环境变量
根据上面的步骤,安装完后,去配置环境变量,发现环境配置自动完成啦,如果没有配置完成,请自我配置即可。
检查图中有两个环境变量

配置 Path

3.4 cuda - 验证安装
如下所示,表示 cuda安装成功

3.5 cudnn神经网络加速库安装


把下载的cudnn解压出来,cuda目录里文件(bin,include,lib,NVIDIA_SLA_cuDNN_Support.txt)拷贝到文件内(.\CUDA\v11.1)
添加cuda11.1的lib库环境变量,复制这个路径(C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64)到环境变量里

结果如上面3.3 配置环境变量那一块。
至些cuda,cudnn配置完成
4. pytorch 1.8.0 安装
由于以前安装过CPU版本的pytorch,先卸载,后安装GPU版本的torch
PyTorch官网信息:
Linux and Windows
# RocM 4.0.1 (Linux only)
pip install torch -f https://download.pytorch.org/whl/rocm4.0.1/torch_stable.html
pip install ninja
pip install 'git+https://github.com/pytorch/vision.git@v0.9.0'
# CUDA 11.1 - 采用这个
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
# CPU only
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

验证
安装后,使用代码验证是否能调用
import torch
print(torch.__version__ )# 查看pytorch版本
print(torch.cuda.is_available()) # 判断pytorch是否支持GPU加速
print(torch.version.cuda) # 查看CUDA版本
print(torch.backends.cudnn.version()) # 查看cuDNN版本
print(torch.cuda.get_device_name()) # 查看显卡类型,设备索引默认从0开始
结果如下:

如果输出为True则表示GPU版本的pytorch安装成功!终于成功啦。
5. tensorflow-gpu 安装

上表没有涵盖cuda11.1
有的人说:cuda11.1 适配 tensorflow-gpu 2.5.0 keras 2.4.3
tensorflow-gpu 2.6.0
tensorflow 2.5.1
5.1 查看CPU/ GPU信息
- 安装 tensorflow-gpu 2.5.0
输入以下命令:
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
或者:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
可以看到:


可以使用的是: "/device:CPU:0"******,********"/device:GPU:0"**
5.2 测试GPU调用
安装完毕之后:
python
import tensorflow as tf
print(tf.test.is_gpu_available())
如果输出为True则表示GPU版本的tensorflow安装成功,附上成功截图一张。
