When I try to define a constant in terms of another constant, both stored in device constant memory, as in:
__device__ __constant__ float x=0.1;
__device__ __constant__ float y=2*x;
I get the error:
error: can’t generate code for non empty constructors or destructors on device
Any hints ?
__constant__is not the same asconst. In particular, a__constant__object can be modified from the host. So the compiler cannot apply compile time evaluation. A__constant__object cannot be written from within the device code at runtime, so runtime initialization is also not possible. In addition, there is no init routine for the device that could perform such an initialization prior to the actual kernel code commencing execution. The error message produced by the compiler seems to allude to that last fact.You could use defined constants, for example: