Loading...
Copy a 1D tensor into an output buffer using a Triton kernel, correctly handling a length that is not a multiple of BLOCK_SIZE.
The final block usually has lanes past the end of the tensor. mask = offsets < n ensures those lanes are not loaded or stored, preventing out-of-bounds memory access.
Implement copy_kernel and run(n=1000) (deliberately non-power-of-two) that returns whether the copy is exact.
Your solution must define a top-level function run(...) that allocates inputs on the GPU, launches your Triton kernel, and returns a boolean from torch.allclose(triton_out, torch_reference, ...). The grader prints run(...); the expected output is True.
n = 1000
True
n = 1000 is used to allocate a 1D tensor of length 1000 on the GPU.copy_kernel function is launched with this tensor, using a BLOCK_SIZE that does not divide 1000 evenly, resulting in a final block with lanes past the end of the tensor.mask = offsets < n, ensuring that only valid lanes are loaded and stored.torch.allclose, which checks for element-wise equality within a tolerance, resulting in the output True if the copy is exact.