[解决bug]CUDA error: no kernel image is available for execution on the device

我在复现论文的代码时反复出现这个错误,终于在今天被我解决了,特此立帖记录

环境配置:

  • python 3.7.0
  • torch 1.7.0
  • cuda10.1
  • GPU: GeForce 3090*2
  • docker:nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 

出现这个错误“RuntimeError: CUDA error: no kernel image is available for execution on the device”是因为CUDA的版本和Torch版本不一致

进入docker输入以下代码:

>>python ##enter python
>>import torch
>>torch.cuda.is_available() #True
>>a=torch.Tensor([1,2])
>>a=a.cuda()

出现报错:

/root/anaconda3/envs/moreformer/lib/python3.7/site-packages/torch/cuda/__init__.py:104: UserWarning: 
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 sm_75.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

  warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))

这里报错很清楚:,3090显卡所装的cuda版本与当前安装的pytorch版本不适配,或者说目前安装的pytorch不支持3090的算力

在NVIDIA官网:CUDA GPUs - Compute Capability | NVIDIA Developer

可以看到:3090对应的算力是sm_86

解决方案

更新CUDA版本,再匹配对应的Pytorch版本

可以参考下表:

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html

  • 21
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值