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

1. 电脑配置

GPU 3080 算力8.6
CUDA 11.1
CUDNN 8.2.0
conda 4.9.2
python 3.8.5

2. 问题描述

首先在pytroch官网根据电脑相应配置使用pip命令

pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

安装torch、torchaudio、torchvision以及cudatoolkit,版本如下:

torch==1.8.1+cu111
torchaudio==0.8.1
torchvision==0.9.1+cu111

当时未测试cuda是否可用,疏忽了!!!大家安装完之后一定要先测试cuda在当前环境下是否可用,再去用在自己的脚本上,免得出问题之后不知道具体是什么问题!
——————————————————————————————————
我直接用在了mmdetection给的第一个实例代码上,报错如下:

ibtorch_cuda_cu.so: cannot open shared object file: No such file or directory

网上搜索说可能是pytorch版本过高,当时还是没有检查cuda是否可用,愚蠢!!
于是直接卸载了torch,由于用的pip命令安装,卸载命令如下:

pip uninstall torch

于是我又重新安装torch1.8.0版本以及cudatoolkit11.1

pip install torch==1.8.0 cudatoolkit==11.1

安装成功后,用以下代码测试cuda是否可用:

import torch
torch.cuda.is_available()

torch.zeros(1).cuda()

开始报错,如下:

GeForce RTX 3080 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.

If you want to use the GeForce RTX 3080 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

RuntimeError: CUDA error: no kernel image is available for execution on the device

大概意思就是说当前GPU的算力与当前版本的Pytorch依赖的CUDA算力不匹配(3080算力为8.6,而当前版本的pytorch依赖的CUDA算力仅支持3.7,5.0,6.0,7.0)
——————————————————————————————————
参考:低版本GPU可在相对高的CUDA版本下运行,例如:算力为8.0的GPU可在算力为8.6的CUAD版本下运行,而相反则不行。同理算力8.x的显卡不可以在支持最高算力7.x的CUDA版本下运行。
因此应该尽量安装更高版本的CUDA,但是让我疑问的是我都装了几乎最新版本,还不支持?
——————————————————————————————————
于是去网上搜集目前torch、cuda相关适配信息,详见博客
——————————————————————————————————
下一步全部卸载重装

conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

装好之后的情况如下:

pytorch==1.8.0       py3.8_cuda11.1_cudnn8.0.5_0
torchaudio==0.8.0
torchvision==0.9.0

再次测试上述命令测试cuda是否可用

解决CUDA error: no kernel image is available for execution on the device
测试成功!!cuda已经可用了!!

总结:只有cuda11.1才支持算力为8.6的GPU,大家不要装错了!!!!当然,如果装低版本的pytorch应该也可以、低版本的cudatoolkit应该也可以? 具体我没试过,有空新建一个环境试一下!还有就是一定要知道自己GPU的算力,NVIDIA算力可在此处 查看

Original: https://blog.csdn.net/HPGaa/article/details/117230868
Author: 图灵机学长
Title: 解决CUDA error: no kernel image is available for execution on the device

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/707577/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球