Triton Row Cumulative Sum
Problem Statement
Compute the inclusive prefix sum (cumulative sum) along each row of a (M, N) tensor using tl.cumsum. Each row fits in one block.
Background
tl.cumsum(x, axis=0) returns the running sum along the block axis. Pad invalid lanes with 0 so they don't affect earlier prefixes, and mask them out on store.
Your Task
Implement cumsum_kernel and run(M=64, N=300) comparing to torch.cumsum(x, dim=1).
How it is tested
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.
Example
M = 64, N = 300
True
- The input values
M = 64andN = 300define the size of the tensor, with 64 rows and 300 columns. - The
cumsum_kernelfunction computes the cumulative sum along each row usingtl.cumsum, padding invalid lanes with 0 and masking them out on store. - The result from
cumsum_kernelis compared to the result fromtorch.cumsum(x, dim=1)usingtorch.allclose, which checks if the two tensors are element-wise equal within a tolerance. - Since the implementation of
cumsum_kernelis correct and matches the result fromtorch.cumsum, the output ofrun(M=64, N=300)isTrue, indicating that the two results are identical.
Constraints
- Use tl.cumsum(row, axis=0)
- Pad invalid lanes with other=0.0 and mask the store
- One program per row