title: Having problem assigning a device variable in CUDA
body: <p>I'm having trouble trying to assign a value to a device variable and then copying this to a host variable. </p>
  
  <p>I start with d_test and h_test = 0.0. I have a simple kernel to set the device variable, d_test, to 1.0. I then copy this to the host variable h_test and print. The problem is that when I print I get h_test = 0.0. What am I doing wrong? Here's the code:</p>
  
  <pre><code>// -*- mode: C -*-
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;cuda_runtime.h&gt;
  
  // device variable and kernel
  __device__ float d_test;
  __global__ void kernel1(float d_test) { d_test = 1.0; }
  
  
  int main() {
  
    // initialise variables
    float h_test = 0.0;
    cudaMemset(&amp;d_test,0,sizeof(float));
  
    // invoke kernel
    kernel1 &lt;&lt;&lt;1,1&gt;&gt;&gt; (d_test);
  
    // Copy device variable to host and print
    cudaMemcpy(&amp;h_test,&amp;d_test,sizeof(float),cudaMemcpyDeviceToHost);
    printf("%f\n",h_test);  
  
  }
  </code></pre>