0

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__?

Paul R
  • 202,568
  • 34
  • 375
  • 539
Michael
  • 6,995
  • 6
  • 37
  • 74

2 Answers2

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
  • 202,568
  • 34
  • 375
  • 539
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.