I am using CUDA 5.0. I noticed that the compiler will allow me to use host-declared int constants within kernels. However, it refuses to compile any kernels
Adding a const number in the device code is OK, but adding a number stored on the host memory in the device code is NOT.
Every reference of the static const int
in your code can be replaced with the value 3
by the compiler/optimizer when the addr of that variable is never referenced. In this case, it is like #define HST_INT_CONSTANT 3
, and no host memory is allocated for this variable.
But for float
var, the host memory is always allocated even it is of static const float
. Since the kernel can not access the host memory directly, your code with static const float
won't be compiled.
For C/C++, int
can be optimized more aggressively than float
.
You code runs when the comment is ON can be seen as a bug of CUDA C I think. The static const int
is a host side thing, and should not be accessible to the device directly.