title: CUDA: cudaMemcpy returns cudaErrorInvalidValue for __device__ array
body: <p>When I define an array on the device (that is initialized with a "Hello" string in this example) and try to copy this to the host, I get the error code <code>cudaErrorInvalidValue</code>. However, from inside a kernel, the <code>d_helloStr[]</code> can be accessed. Referring to the CUDA programming guide chapter B.2.1, such a variable should also be accessible through the runtime library. Why does this example code not work? </p>
  
  <pre><code>#include &lt;cuda.h&gt;
  #include &lt;stdio.h&gt;
  
  
  __device__ char d_helloStr[] = {'H','e','l','l','o','\0'};
  
  // Host function
  int
  main(int argc, char** argv)
  {
    cudaError_t err;
    char h_helloStr [sizeof(d_helloStr)];
  
    // copy device string to host string: 
    err = cudaMemcpy(h_helloStr, d_helloStr, sizeof(d_helloStr), cudaMemcpyDeviceToHost);
    printf("err = %d\n", err);
  
    // result string:   
    printf("%s\n", h_helloStr);
  
    return 0;
  }
  </code></pre>