所以我的问题是:我在 mac os x mountain lion 上使用 Nvidia 的 nsight 应用程序编写 CUDA 应用程序:源代码是 .h/.cu/.cpp 混合。
我有一个包含以下声明的 HelloCUDA.h header :
//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 (nsight) 的新类向导添加了一个新的 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下)
关于c++ - CUDA: __device__ and __global__ error: expected constructor, destructor, or type conversion before "unsigned"/"void"”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550031/