P.M
July 7, 2011, 11:06am
1
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
#else
typedef double floatdouble
#endif
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?
tera
July 7, 2011, 11:44am
2
Try replacing [font=“Courier New”]CUDACC [/font] with [font=“Courier New”]CUDA_ARCH [/font].
P.M
July 7, 2011, 1:08pm
3
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?
tera
July 7, 2011, 1:33pm
4
[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.
P.M
July 7, 2011, 2:41pm
5
Ok thanks a lot!
But I still wonder in what context one should use CUDACC …?
tera
July 7, 2011, 3:20pm
6
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).