In a .cu file I've tried the following in the global scope (i.e. not in a function):
__device__ static const double cdInf = HUGE_VAL / 4;
And got nvcc error:
error : dynamic initialization is not supported for __device__, __constant__ and __shared__ variables.
How to define a C++ const/constexpr on the device, if that's possible?
NOTE1: #define
is out of question not only for aesthetic reasons, but also because in practice the expression is more complex and involves an internal data type, not just double. So calling the constructor each time in each CUDA thread would be too expensive.
NOTE2: I doubt the performance of __constant__
because it's not a compile-time constant, but rather like a variable written with cudaMemcpyToSymbol
.