PIXELBANKv9.1.0
Menu

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:

Input:
n = 1024
Output:
True
Reasoning:
  • The input value n = 1024 determines the size of the source and destination arrays.
  • The copy_kernel function is launched, which reads from the source array src and writes to the destination array dst on the GPU, effectively performing the operation dst = src.
  • The run function allocates the source and destination arrays, launches the kernel, and then compares the resulting dst array with the original src array using np.allclose.
  • The comparison checks for exact equality between dst and src, and since the kernel correctly copies the source array to the destination array, the result is True.

Constraints:

  • src is a device array, dst a separate device array
  • dst[i] = src[i]
  • Bounds-check the global index
๐Ÿ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
CUDA Device-to-Device Copy - Easy | PixelBank