我正在尝试使用cuda创建我的第一个程序。 所以我把这个简单的HelloWorld与各种网页的指导。一个简单的C++ Hello World与cuda
#include <cstdlib>
#include <cstdio>
#include <cuda.h>
using namespace std;
__global__ void mykernel(void) {
}
int main(void) {
mykernel<<<1,1>>>();
printf("CPU Hello World!\n");
return 0;
}
但我得到这样的输出:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/hellowordcuda
make[2]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/hellowordcuda.o.d"
g++ -c -g -I/usr/local/cuda-7.5/include -MMD -MP -MF "build/Debug/GNU-Linux-x86/hellowordcuda.o.d" -o build/Debug/GNU-Linux-x86/hellowordcuda.o hellowordcuda.cpp
hellowordcuda.cpp:19:1: error: ‘__global__’ does not name a type
__global__ void mykernel(void) {
^
hellowordcuda.cpp: In function ‘int main()’:
hellowordcuda.cpp:24:1: error: ‘mykernel’ was not declared in this scope
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:11: error: expected primary-expression before ‘<’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:17: error: expected primary-expression before ‘>’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:19: error: expected primary-expression before ‘)’ token
mykernel<<<1,1>>>();
^
make[2]: *** [build/Debug/GNU-Linux-x86/hellowordcuda.o] Error 1
make[2]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make: *** [.build-impl] Error 2
我制作一个问题这么简单抱歉,但我就是没有找到这方面的任何答复。
非常感谢,任何帮助将不胜感激!
我只在大学使用C++,所以如果这是一个愚蠢的问题,请原谅我。那是什么__global__关键字?只是说void mykernel()也会让你的方法成为全局的。 __global__看起来像是python的东西 – NSNoob
@NSNoob它是CUDA的一部分。 – Angew
哦,好吧谢谢Angew! – NSNoob