1

这就是问题所在...对于学校项目,我需要使用 CUDA C 编写并行应用程序。即使是最简单的示例也无法编译。我正在使用 Windows7 和 MS Visual Studio。代码取自书中:CUDA by example。通用 GPU 计算简介。

#include<iostream>
#include<cuda.h>

using namespace std;

__global__ void kernel(void){
}

int main(){
kernel<<<1, 1>>>();
cout << "Hello world" << endl;
return 0;
}

以下是错误:

1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(10): error C2059: syntax error : '<'

我是否需要将 nvcc.exe 设置为默认编译器而不是 cl.exe?如果是这样,该怎么做?任何帮助深表感谢!

4

1 回答 1

3

CUDA 代码需要写在一个.cu文件中并用NVCC编译器编译。您看到上述错误是因为您已将代码写入.cor.cpp文件并尝试使用 C++ 编译器(Visual C++ 编译器)对其进行编译。

您选择了正确的书来学习 CUDA。但是,您并没有遵循书中给出的所有步骤。请查看书中编译的详细信息:-)

于 2012-03-29T11:59:50.983 回答