CUDA:__device__和__global__错误:在"无符号"/"void"之前预期的构造函数、析构函数或类型转换"

CUDA: __device__ and __global__ error: expected constructor, destructor, or type conversion before "unsigned"/"void""

本文关键字:构造函数 析构函数 类型转换 global device 错误 void CUDA 无符号      更新时间:2023-10-16

所以我的问题是:我在mac os x mountain lion上使用Nvidia的insight应用程序来编写CUDA应用程序:源代码是.h/.cu/.cpp组合。

我有一个HelloCUDA.h头文件,声明如下:

//yep, both taken from examples.
__device__ unsigned int bitreverse2(unsigned int number);
__global__ void bitreverse(void *data);

和我有一个HelloCUDA。定义这些方法的Cu文件:

__device__ unsigned int bitreverse3(unsigned int number) {
    //definition
    return number;
}
__global__ void bitreverse4(void *data) {
    //another definition...
    bitreverse3(idata[threadIdx.x]);
}

它工作了,直到我使用eclipse的(insight)新类向导添加了一个新的c++类文件(.h/.cpp)。现在,当我试图构建这个东西:

../src/HelloCUDA.h:21: error: expected constructor, destructor, or type conversion before ‘unsigned’
../src/HelloCUDA.h:23: error: expected constructor, destructor, or type conversion before ‘void’

我检查了项目设置,我认为没有任何变化。

那么,发生了什么?有人能帮我解决这个问题吗?

以上的解决方案对我都没有帮助。只是在文件的顶部导入:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

解决它。(我在VS Studio2019下)

您可能使用"CUDA C Bitreverse Application"模板创建了一个新的CPP文件。该模板是为CUDA C文件。只需删除文件内容并添加您的c++代码即可。