On http://docs.nvidia.com/cuda/cuda-c-programming-guide/#device-variable-qualifier it says that a device qualifyer variable has the “lifetime of an application”. Does this mean the kernel? If there are several kernels, how can CUDA know which variable belongs to which kernel?
If i declare a device variable like so:
void someHOSTfunction() {
device int var;
// Launch kernel etc…
}
Is “var” still global in the sense that it is still accessible from a kernel launched from a different function, even though it is “local” on the stack of someHOSTfunction() and gets scoped (?) when someHOSTfunction() returns? Does it make any difference to write it like this:
device int var;
void someHOSTfunction() {
// Launch kernel etc…
}
Now var is a global variable. But that means it is also accessible from other translation units. This probably won’t work to prevent that:
static device int var;
void someHOSTfunction() {
// Launch kernel etc…
}
What would be the apropriate way of doing it?