const handling by the compiler questions

question for nvidia developpers:

do you think it’s better to use #defines or const for fixed values definitions? does nvcc do anything useful with the const keyword, or is it better for the preprocessor to hand him fixed values.

– a subquestion of this is, in the code I’ve seen
const int tid = threadIdx.x;

wouldn’t threadIdx.x be computed at runtime and thus, how does the compiler use the const keyword to optimize it? or does the compiler statically replace the value for each thread since it knows the number of threads? (same for blockIdx.x)

A const modifier in device code does not seem to do anything. The .ptx code is identical to the non-const version. I haven’t done extensive tests though, so it might help the nvopencc optimizer in some situations. Given the problems the nvcc toolchain currently has with respect to mem types (dropped shared attribs etc), I am tempted to say const is currently useless in device code.

Peter