无法使用Xcode构建一个简单的Cuda程序! [英] Can't Build a simple Cuda Program using Xcode !

查看:181
本文介绍了无法使用Xcode构建一个简单的Cuda程序!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 !!!

这是代码:

    #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 >>>();

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

'<'token之前的主表达式!!!!!!

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

推荐答案

您正在使用gcc与Xcode一起编译程序。应该使用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.

这篇关于无法使用Xcode构建一个简单的Cuda程序!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆