last element of array


Anyone knows how can I just copy the last element of an array from GPU to CPU?


You can do pointer arithmetic on device pointers from the host (just don’t dereference them!), so this is totally valid:

cudaMemcpy(h_array, d_array + n - 1, sizeof(float), cudaMemcpyDeviceToHost)

where n is the number of entries in your array, and I’ve assumed it is an array of floats.

Thanks a lot