cuda.c: extract out copy_array_{to,from}_device