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

标签 c++ cuda compiler-errors syntax-error nsight

所以我的问题是:我在 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/

相关文章:

c++ - 使用 mex : Matlab crashes 将大矩阵从 Matlab 传递到 C

cuda - 设备带宽的含义

cuda - 从 device_vector 中删除元素

c++ - 尝试使用命名空间中的函数时出现错误 LNK2019

c++ - 调试 Visual Studio 链接器

c++ - 将 c++98 代码升级到 c++11

c++ - 为什么这个虚拟析构函数在 C++ 中不起作用?

在 __device__ 函数中创建太多 double 时 Cuda 内核未启动

compiler-errors - Sqoop2 : Compile fails: missing org.apache.sqoop:sqoop-core:test-jar:tests:2.0.0-SNAPSHOT

c++ - C++错误,编译器无法识别字符串::push_back [closed]