Functions that will be run on the GPU need the qualifier __device__. I'm currently writing a general set of mathematical functions, which can be used on the GPU as well as on the CPU. I think it's not very nice to qualify all those functions as __device__ since they might also be included into other programs where no CUDA is present at all. Is there a way to leave out the __device__?
Asked
Active
Viewed 121 times
0
2 Answers
2
You can just compile with -D__device__="" when building for a non-CUDA target, or perhaps use a more general-purpose macro which can be defined as __device__ when compiling for CUDA.
Paul R
- 208,748
- 37
- 389
- 560
1
#ifndef __CUDACC__
#define __device__
#endif
Or similar. Of course, you would need similar guards to deal with includes and functions that don't make sense in a non-CUDA setting.