title: How to asynchronously copy memory from the host to the device using thrust and CUDA streams
body: <p>I would like to copy memory from the host to the device using thrust as in</p>
  
  <pre><code>thrust::host_vector&lt;float&gt; h_vec(1 &lt;&lt; 28);
  thrust::device_vector&lt;float&gt; d_vec(1 &lt;&lt; 28);
  thrust::copy(h_vec.begin(), h_vec.end(), d_vec.begin());
  </code></pre>
  
  <p>using CUDA streams analogously to how you would copy memory from the device to the device using streams:</p>
  
  <pre><code>cudaStream_t s;
  cudaStreamCreate(&amp;s);
  
  thrust::device_vector&lt;float&gt; d_vec1(1 &lt;&lt; 28), d_vec2(1 &lt;&lt; 28);
  thrust::copy(thrust::cuda::par.on(s), d_vec1.begin(), d_vec1.end(), d_vec2.begin());
  
  cudaStreamSynchronize(s);
  cudaStreamDestroy(s);
  </code></pre>
  
  <p>The problem is that I can't set the execution policy to CUDA to specify the stream when copying from the host to the device, because, in that case, thrust would assume that both vectors are stored on the device. Is there a way to get around this problem? I'm using the latest thrust version from github (it says 1.8 in the version.h file).</p>