Different Code for Host and Device

Hi,

is it somehow possible to define different code for the host and the device in a host device function?

Here’s an example:

__host__ __device__ int test()

{

#ifdef HOST

return 0;

#else

return 1;

#endif

}

I know, this function is somewhat stupid. It is only used to explain, what I would like to do.

As far as I know, there are no such macros defined by the nvcc compiler.

The following version will also not work:

__host__ int test() { return 0; }

__device__ int test() { return 1; }

The compiler will say, that this is a redefinition of the function.

Any ideas?

Regards,

porst17

#ifdef CUDA_ARCH
// cuda code
#else
//host code
#endif

programming guide p. 102

Sometimes it’s just that easy.

Thanks,
porst17

Sometimes it’s just that easy.

Thanks,
porst17