According to CUDA C++ Programming Guide
- The type signature of the following entities shall not depend on whether
__CUDA_ARCH__
is defined or not, or on a particular value of__CUDA_ARCH__
:
__global__
functions and function templates__device__
and__constant__
variables- textures and surfaces
- If a
__global__
function template is instantiated and launched from the host, then the function template must be instantiated with the same template arguments irrespective of whether__CUDA_ARCH__
is defined and regardless of the value of__CUDA_ARCH__
.
I have two questions:
-
Does the second point only apply to
__global__
functions? Thus, it is allowed to instantiate__device__
functions with values dependent on__CUDA_ARCH__
? -
Is it allowed to make a
__global__
or__device__
function dependent on__CUDA_ARCH__
in anif constexpr
clause? E.g. like in the following coda
#ifdef __CUDA_ARCH__
static constexpr bool cudaarch = true;
#else
static constexpr bool cudaarch = false;
#endif
__device__ void func() {
if constexpr ( cudaarch ) {
/* code */
} else {
/* code */
}
}