CUDA Device-to-Device Copy
Problem Statement
Copy one device array into another with a kernel: dst = src. Both buffers already live on the GPU — no host involvement during the copy.
Background
Allocate the source with cuda.to_device and an empty destination with cuda.device_array. The kernel reads src and writes dst, both device pointers.
Your Task
Implement copy_kernel and run(n=1024) returning whether dst exactly equals src.
How it is tested
Your solution must define a top-level function run(...) that allocates the inputs, copies them to the GPU, launches your @cuda.jit kernel, and returns a Python bool from np.allclose(gpu_result, reference). The grader prints run(...); the expected output is True.
Example
n = 1024
True
- The input value
n = 1024determines the size of the source and destination arrays. - The
copy_kernelfunction is launched, which reads from the source arraysrcand writes to the destination arraydston the GPU, effectively performing the operationdst = src. - The
runfunction allocates the source and destination arrays, launches the kernel, and then compares the resultingdstarray with the originalsrcarray usingnp.allclose. - The comparison checks for exact equality between
dstandsrc, and since the kernel correctly copies the source array to the destination array, the result isTrue.
Constraints
- src is a device array, dst a separate device array
- dst[i] = src[i]
- Bounds-check the global index