title: Scope of __device__ qualifier
body: <p>On <a href="http://docs.nvidia.com/cuda/cuda-c-programming-guide/#device-variable-qualifier" rel="nofollow">http://docs.nvidia.com/cuda/cuda-c-programming-guide/#device-variable-qualifier</a> it says that a __device_ qualifier 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?</p>
  
  <p>If i declare a __device_ variable like so: </p>
  
  <pre><code>void someHOSTfunction() {
     __device__ int var;
     // Launch kernel etc...
  }
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>__device__ int var;
  void someHOSTfunction() {
     // Launch kernel etc...
  }
  </code></pre>
  
  <p>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: </p>
  
  <pre><code>static __device__ int var;
  void someHOSTfunction() {
     // Launch kernel etc...
  }
  </code></pre>
  
  <p>What would be the appropriate way of doing it?</p>