title: how to change the __device__ variable in global and device functions in CUDA?
body: <p>The procedure describe as follows:</p>
  
  <pre><code>#include &lt;cuda.h&gt; 
  #include &lt;cutil_math&gt;  
  #include &lt;cuda_runtime.h&gt;  
  #include &lt;iostream&gt;
  
  struct testtype  
  {
      float x;  
      int y;  
      char z;  
  };
  
   __device__   testtype* gpu_config;
  
  __global__
  void test()
  {
      gpu_config-&gt;y = 3.0;
  };
  
  int main(void)  
  {  
  testtype cpu_config;
  
  cpu_config.x = 1;
  cpu_config.y = 2.0f;
  cpu_config.z = 'A';
  
  testtype val ;
  
  if (cudaMalloc((void**) &amp;gpu_config, sizeof(testtype)) != cudaSuccess)
  {
      return -1;
  }
  
  cudaMemcpy(gpu_config, &amp;cpu_config, sizeof(testtype), cudaMemcpyHostToDevice);
  
  test&lt;&lt;&lt;1,1,0&gt;&gt;&gt;();
  
  cudaMemcpy(&amp;val, gpu_config, sizeof(testtype), cudaMemcpyDeviceToHost);
  
  std::cout &lt;&lt; val.y &lt;&lt; std::endl;
  }   
  </code></pre>
  
  <p>when I delete   test&lt;&lt;&lt;1,1,0>>>();  val is changed the same with gpu_config. but when has test&lt;&lt;&lt;1,1,0>>>();,  the val.y is not equal to 3.0 .   it means that the global function test not change the value of val.     I want to know how to change the <strong>_<em>device</em>_</strong> variable the value through the global functions.  </p>