CUDA programs use cudaMemcpy to move data between host memory and device memory. The host and GPU keep separate copies, so input must be copied to the device before a kernel uses it, and results must be copied back for the host to use. section 2.16 section 2.18
Copy in, then copy out
Use destination, source, size, direction—in that order: cudaMemcpy(d_data, h_data, n * sizeof(int), cudaMemcpyHostToDevice); cudaMemcpy(h_data, d_data, n * sizeof(int), cudaMemcpyDeviceToHost); The direction must match the pointers. If it does not, the runtime may return an error and leave the destination unchanged; unchecked, this can look like stale or garbage data. section 2.16 section 2.18 section 2.22
Figure 2.10 Step 4 — Copy Out: bringing the results back to the host. cudaMemcpy transfers the computed results from device to host: the squared values (9, 25, 4, 49) are now back on the CPU, ready to be used.

See the squared results after the device-to-host copy, ready for use on the CPU. section 2.18
