Memory Allocation on GPU When to allocate memory on GPU and when to copy the data to & fro


If the data is defined on the main(Host) program, is it required to copy the data from host to device? If its required to copy, then is memory allocation on GPU a must?

Example: I've an array with 10 (i.e. a[10]) elements initialized to 1,2,3 .. 10( a[0]..a[9]) on the host code. 

The kernel call is:

addarr<<<N,1>>> (a);

As we are passing the base address of the array "a", is it still required to allocate memory on gpu and copy the contents?

Thanks in advance

Yes. See CUDA reference, please.


Zero-copy memory is also an (advanced) option for seldom-accessed data: Host memory accessible by device, allocated via cudaHostAlloc().