Question about cudaMemcpy


I have 2 device arrays (array1 and array2). Array2 is 10 times bigger than array1.

Now I want to copy array1 10 times into the array2. Is this by this method


for(int i = 0; i < 10; i ++){

					cudaMemcpy(&array2[i*size], array1, size, cudaMemcpyDeviceToDevice);



(size is the size of array1)

No, you can’t do that because you are dereferencing a device pointer on the host, which is illegal. But you can do device pointer arithmetic, so something like this:

size_t size = nelements * sizeof(type); // where nelements is the number of values of type to copy

for(int i = 0; i < 10; i ++){

    cudaMemcpy(array2 + (i*nelements), array1, size, cudaMemcpyDeviceToDevice);


should work.

Thank you very much. I think it works now, tests are not over yet, but it looks promising.
EDIT: Works :)