无法使用 Xcode 构建简单的 Cuda 程序!

发布于 2024-09-25 10:44:25 字数 1013 浏览 1 评论 0原文

我在 Mac OS 10.6 上使用 Xcode 3.2 为 CUDA 构建一个非常简单的 HelloWorld 程序 但它无法建立..任何想法!

这是代码:

    #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUDA/CUDA.h>

__device__ char napis_device[14];

__global__ void helloWorldOnDevice(void){
 napis_device[0]='H';
 napis_device[1]='e';
 napis_device[2]='l';
 napis_device[3]='l';
 napis_device[4]='o';
 napis_device[5]=' ';
 napis_device[6]='W';
 napis_device[7]='o';
 napis_device[8]='r';
 napis_device[9]='l';
 napis_device[10]='d';
 napis_device[11]='\n';

}



int main (int argc, char * const argv[]) {
    helloWorldOnDevice<<<1,1>>> ();
 cudaThreadSynchronize();
 char napis_host[14];
 const char *symbol="napis device";
 cudaMemcpyFromSymbol (napis_host, symbol, sizeof(char)*13, 0, cudaMemcpyDeviceToHost);

     return 0;
}

错误出现在这一行 helloWorldOnDevice<<<1,1>>>>> ();

'<' 之前应有主要表达式令牌!!!!!!

I'm using Xcode 3.2 on Mac OS 10.6 to build a very simple HelloWorld program for CUDA
but it fails to build .. any ideas !!!

this is the code :

    #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUDA/CUDA.h>

__device__ char napis_device[14];

__global__ void helloWorldOnDevice(void){
 napis_device[0]='H';
 napis_device[1]='e';
 napis_device[2]='l';
 napis_device[3]='l';
 napis_device[4]='o';
 napis_device[5]=' ';
 napis_device[6]='W';
 napis_device[7]='o';
 napis_device[8]='r';
 napis_device[9]='l';
 napis_device[10]='d';
 napis_device[11]='\n';

}



int main (int argc, char * const argv[]) {
    helloWorldOnDevice<<<1,1>>> ();
 cudaThreadSynchronize();
 char napis_host[14];
 const char *symbol="napis device";
 cudaMemcpyFromSymbol (napis_host, symbol, sizeof(char)*13, 0, cudaMemcpyDeviceToHost);

     return 0;
}

The error appears at this line
helloWorldOnDevice<<<1,1>>> ();

Expected primary-expression before '<' token !!!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2024-10-02 10:44:25

您正在使用 Xcode 附带的 gcc 来编译您的程序。应该使用 nvcc 编译器来编译 CUDA 代码。通常我会使用 Makefile 告诉 *.cu 由 nvcc 编译,*.cpp 由 gcc 编译,然后将生成的对象链接到可执行文件。

You're compiling your program with gcc coming with Xcode. Should use nvcc compiler instead to compile CUDA code. Normally I would use a Makefile to tell that *.cu to be compiled by nvcc and *.cpp by gcc, then link produced objects to an executable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文