__CUDACC__ Macro in header

Hi all,

I have a struct which is basically a 4x4 matrix and I would like to have double when used on CPU and float on GPU

So what I did is:

#ifdef __CUDACC__

typedef float floatdouble


typedef double floatdouble


struct myVector


   floatdouble m[16];

   // some functions


However, when I use it in a __host, my floatdoubles are float when they should be double.

I tried to look at the temporary .cpp/.gpu files built by nvcc and I find typedef float floatdouble in all of them.

What’s wrong with this piece of code?

Try replacing [font=“Courier New”]CUDACC[/font] with [font=“Courier New”]CUDA_ARCH[/font].

Do you know why CUDACC does not work?

CUDA_ARCH should be equal to the architecture it is compiled for if compiling a __device and be empty when compiling a __host?

[font=“Courier New”]CUDACC[/font] gets defined on both device and host. [font=“Courier New”]CUDA_ARCH[/font] is defined on the device only, just as you wrote.

Ok thanks a lot!
But I still wonder in what context one should use CUDACC …?

I don’t know, I just never use it (but then I isolate my CUDA code into separate files, so I already know they are compiled by a CUDA-capable compiler).