900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 解决CUDA error: no kernel image is available for execution on the device

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

时间:2022-05-02 16:45:26

相关推荐

解决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 /whl/torch_stable.html

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

torch==1.8.1+cu111torchaudio==0.8.1torchvision==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.1+cu111一起卸载# 我点了确定,貌似这个命令把cudatoolkit也一并卸载了

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

pip install torch==1.8.0 cudatoolkit==11.1

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

import torchtorch.cuda.is_available()# 返回True 接着用下列代码进一步测试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 /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_0torchaudio==0.8.0 torchvision==0.9.0

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

测试成功!!cuda已经可用了!!

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。