views:

72

answers:

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

A: 

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.

Archie
Thanks for your answer
Lamiaa Basyoni
I tried to compile the .cu file running the command ./nvcc in the terminal but I got the following : cc1plus: fatal error: opening output file helloWorld.cu.cpp: Permission deniedcompilation terminated !!!!!
Lamiaa Basyoni
You should not do it in directory where nvcc is installed (/usr/local/cuda/bin is read-only for non-root user). Change your $PATH to point to /usr/local/cuda/bin instead and compile from your private directory.
Archie