avoid copying data to/from global memory that is only used internally
If some element of an array that is mapped to private or shared memory
is written by a kernel, then in general, we need to copy this element
back to global memory. However, if all the reads of that array element
occur inside the same kernel, then there is no need to copy the data
back to global memory.
Similarly, any array element read by a kernel is first copied in from
global memory, but there is no need to perform this copying if the
array element was written inside the same kernel.
Only perform the copy-in or copy-out on data elements that may
come in from the outside or that may still be needed later.
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>