问题描述
在pycharm调试程序是出现以下错误:
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.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
问题分析
在网上查找的解决方案都说的是电脑显卡、cuda、torch之间的版本不匹配,于是我查看我所配置的cuda、torch版本和显卡算力。
cuda是10.2 ,torch是 1.9.0,显卡算力3.5。cuda与torch之间是匹配的,那就是显卡算力的问题。
在试过网上很多的方法之后发现还是没法解决问题,一直看到这篇博客:【深度学习】 为Tesla K40c(显卡算力小于3.5)安装pytorch(要求显卡算力3.7以上)笔记_found gpu0 nvidia geforce gt 730 which is of cuda -CSDN博客
才知道现在官网的pytorch支持的最低算力是3.7的,所以使用直接安装的torch就会出现上面说的那个报错。
解决方法
根据上面这篇博客里的链接:https://blog.nelsonliu.me/2020/10/13/newer-pytorch-binaries-for-older-gpus/,下载这位大佬专门为old gpu编译的pytorch。注意,要下载与自己cuda版本匹配的pytorch。