Host float constant usage in a kernel in CUDA

后端 未结 1 1833
误落风尘
误落风尘 2020-12-04 00:14

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

相关标签:
1条回答
  • 2020-12-04 00:58

    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.

    0 讨论(0)
提交回复
热议问题