【发布时间】:2020-11-04 03:14:06
【问题描述】:
操作系统:CentOS 7 Cuda 工具包版本:11.0
Nvidia 驱动程序和 GPU 信息:
NVIDIA-SMI 450.51.05
驱动程序版本:450.51.05
CUDA 版本:11.0
显卡:Quadro M2000M
screenshot of nvidia-smi details
我对 cuda 编程非常陌生,因此非常感谢任何指导。我有一个非常简单的 cuda c++ 程序,它计算 GPU 上统一内存中两个数组的总和。但是,由于 cudaErrorNoKernelImageForDevice 错误,内核似乎无法启动。代码如下:
using namespace std;
#include <iostream>
#include <math.h>
#include <cuda_runtime_api.h>
__global__
void add(int n, float *x, float*y){
for (int i = 0; i < n; i++)
y[i] = x[i] + y[i];
}
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
int N = 1<<20;
float *x, *y;
cudaMallocManaged((void**)&x, N*sizeof(float));
cudaMallocManaged((void**)&y, N*sizeof(float));
for(int i = 0; i < N; i++){
x[i] = 1.0f;
y[i] = 2.0f;
}
add<<<1, 1>>>(N, x, y);
cudaGetLastError();
/**
* This indicates that there is no kernel image available that is suitable
* for the device. This can occur when a user specifies code generation
* options for a particular CUDA source file that do not include the
* corresponding device configuration.
*
* cudaErrorNoKernelImageForDevice = 209,
*/
cudaDeviceSynchronize();
float maxError = 0.0f;
for (int i = 0; i < N; i++){
maxError = fmax(maxError, fabs(y[i]-3.0f));
}
cudaFree(x);
cudaFree(y);
return 0;
}
【问题讨论】:
-
这是您如何编译代码的问题。您是如何编译代码的(即您使用什么命令来编译它,究竟是什么?)您的 Quadro M2000M 是一款 maxwell 设备,计算能力为 5.0,因此您需要编译以获得正确的计算能力。在你的编译命令中像
-arch=sm_50这样的东西。如果您有-arch=sm_60之类的内容,则可以解释为什么会出现此故障。 -
注意by default,CUDA 11.0 编译为默认架构
sm_52,所以如果你没有在命令行提供任何架构开关,也会导致此类问题。 -
@RobertCrovella 我正在使用 Eclipse IDE,编译器命令在构建文件时输出如下: /usr/local/cuda-11.0/bin/nvcc --device-debug -- debug -gencode arch=compute_52,code=sm_52 -gencode arch=compute_52,code=compute_52 -ccbin g++ -c -o "src/barracuda.o" "../src/barracuda.cu"
-
这就是问题所在。编译命令行中的所有
_52都不适合您的 GPU。当您设置项目(或在项目属性中)以更改您正在编译的体系结构时,IDE 有一个选择。你想要_50而不是_52。 -
@RobertCrovella 好的,鉴于我的 GPU 具有 5.0 的计算能力,我应该使用 -arch=sm_XX 的架构进行编译,其中 XX 代表我的计算能力?在这种情况下,XX = 50?我会试试看。
标签: c++ cuda gpu nvidia cuda-gdb