a very simple problem

I am just starting (like today) to program in CUDA. So i copied the makefile off one of the SDK examples and renamed some variables to make it make my own file.

The problem is that i cant get the compiler to recognise the built in variable threadIdx. I have a very simple program and i am using the command make emu=1 so that i can have printf statements in there.

Here is my code

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <math.h>

// includes, project

#include <cufft.h>

#include <cutil.h>

void some(){

        int test = threadIdx.x;

        printf("%i\n",test);

}

int main(int argc, char** argv)

{

        some();

   CUT_EXIT(argc, argv);

}

and the compiler error message i get is:

-bash-3.2$ make emu=1

dave1.cu: In function 'void some()':

dave1.cu:13: error: 'threadIdx' was not declared in this scope

make: *** [obj/emurelease/dave1.cu_o] Error 255

-bash-3.2$

What am i doing wrong?

Your function some() is not a kernal function.

The nvcc compiler only compiles the kernal code declared with the global keyword. The rest of the code is compiled by the cl.exe compliler of visual Studio.

Since the normal compiler does not know about the built in threadIdx.x varialble you are getting a compile error.

Hope this helps :)