I am trying to compile a .cu file which includes a .cuh file with a templated device function using nvcc. That same .cuh file is also included from a .cpp, so I am trying to prevent the templated device function to be visible from the .cpp side. To do so I am using
foo.cuh
#if defined(__CUDA__) && defined(__CUDA_ARCH__)
template <typename T>
__device__ void foo(){...}
#endif
However, when I try to use the device function from a kernel, it says the function doesn't exist while compiling the .cu. The .cu compiles fine if I remove the __CUDA__
check, but in that case it fails later, when compiling the .cpp file.
Am I missing something in the check?