title: CUDA GPU cudaMemcpy very slow returning from device to host
body: <p>Currently I’m working with CNN related project, the goal to implement YOLO convolutional neural network in real-time using GPU and I faced certain problem. Overall, the all calculations of CNN layers on GPU runs fast (~15 ms), however I didn’t find the way how to be fast when copying final results back to CPU memory. cudaMemcpy takes about 55 seconds!!! even when copying single float variable:</p>
  <p><code>cudaMemcpy(var1, var, sizeof(float), cudaMemcpyDeviceToHost);</code></p>
  <p>I have tried to use page-locked memory:</p>
  <p><code>float* var1;</code>
  <code>cudaHostAlloc((void**)&amp;var1, sizeof(float),0);</code></p>
  <p><code>cudaStream_t mystream1;</code>
  <code>cudaStreamCreate(&amp;mystream1);</code>
  <code>cudaMemcpyAsync(var1, var, sizeof(float), cudaMemcpyDeviceToHost, mystream1);</code></p>
  <p>now it runs fast, but returns wrong result. If I add:</p>
  <p><code>cudaStreamSynchronize(mystream1);</code></p>
  <p>the result is correct, but the copying time is about 55 seconds again. I’m new in GPU programming and it would be great if you provide some suggestions or examples how to be fast returning from the device to host.</p>