RuntimeError: CUDA error: no kernel image is available for execution on the device报错分析与解决

1.问题分析

2.torch、torchvision、cuda之间的对应关系

3.重装torch、torchvision、cuda

4.检测torch、cuda、cudnn安装是否成功


1.问题分析

3090显卡在使用cuda == 10.2,torch == 1.9.0,torchvision == 0.10.0时,报错提示:

【1】NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70.

【2】RuntimeError: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.

翻译一下【1】:RTX 3090的算力是8.6,但是当前的PyTorch依赖的CUDA版本支持的算力只有3.7、5.0、6.0、7.0、7.5。

由于cuda版本是直接对应电脑显卡的,因此上面表面上是说pytorch版本不对应,但实际上是pytorch依赖的cuda版本的问题。

而根据对应的算力关系,算力为8.x的显卡使用的cuda版本应该 >= 11.0。因此需要重新安装cuda和对应cuda可用版本的pytorch。

2.torch、torchvision、cuda之间的对应关系

三者的对应关系可以参考这个。下面是常见版本的对应关系图:

 【注】cuda是向下兼容的,因此可以选择 >= 项目要求版本的cuda。但是也不建议直接上最新版,因为可能找不到最新版cuda对应的pytorch。

3.重装torch、torchvision、cuda

  • 打开终端,激活需要修改的虚拟环境
conda activate 虚拟环境名
  • 卸载原本的torch和torchvision
pip uninstall torch
pip uninstall torchvision
  • 重新安装 torch、torchvision、cuda

安装方法参考这个。该方法超级好用,可以一次性安装好cuda(包含cudnn)、torch、torchvision。我下载的是cuda == 11.1,torch == 1.9.0,torchvision == 0.10.0,参考指令如下:

pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

4.检测torch、cuda、cudnn安装是否成功

  • 激活虚拟环境后进入python
conda activate 虚拟环境名
python
  • 导入torch,并查看torch版本 
import torch
print(torch.__version__)    # 如果显示版本号,则安装成功
  • 检查cuda是否安装成功
print(torch.version.cuda)        # 如果显示版本号,则说明成功
  • 检查cudnn是否安装成功
print(torch.backends.cudnn.version())    # 如果显示版本号,则说明成功
  • 检查cuda和GPU是否匹配
torch.cuda.is_available()    # 如果显示True,则说明cuda和GPU是匹配的

  • 18
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值