title: CUDA host and device using same __constant__ memory
body: <p>I have device/host function that uses constant memory. It runs OK on device, but on host it seems like this memory remains uninitialized.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  
  const __constant__ double vals[2] = { 0.0, 1000.0 };
  
  __device__ __host__ double f(size_t i)
  {
      return vals[i];
  }
  
  __global__ void kern()
  {
      printf("vals[%d] = %lf\n", threadIdx.x, vals[threadIdx.x]);
  }
  
  int main() {
      std::cerr &lt;&lt; f(0) &lt;&lt; " " &lt;&lt; f(1) &lt;&lt; std::endl;
      kern&lt;&lt;&lt;1, 2&gt;&gt;&gt;();
      cudaThreadSynchronize();
  }
  </code></pre>
  
  <p>This prints (requires CC 2.0 or above)</p>
  
  <pre><code>0 0
  vals[0] = 0.000000
  vals[1] = 1000.000000
  </code></pre>
  
  <p>What is the problem and how can I get both device and host memory constants initialized simultaneously?</p>