Implement a 1D sum reduction in Triton. For a float tensor x of length N, write the scalar sum into out[0]:
out[0]=i=0∑N−1x[i]This is the canonical Triton reduction. Each program covers one tile, reduces its lanes in registers, and combines partial sums across programs with a single atomic add on out[0]. Because atomics accumulate, the host must zero out before launch.
Input: x = [1.0, 2.0, 3.0, 4.0]
Output: [10.0]
Input: x = [0.0, -1.0, 2.5, 1.5, -3.0]
Output: [0.0]
Each program reduces its lanes with tl.sum along the tile axis. The masked tail must load other=0.0 so it does not poison the partial.
Combine partials with \texttt{tl.atomic_add} to a single-element output. One atomic per program is far cheaper than one atomic per lane.
Remember to call out.zero_() in the launcher before the kernel; atomics accumulate into whatever value is already there.
torch.float32 on cuda and contiguous; output has shape (1,).atol=1e-2, rtol=1e-2 to absorb float32 accumulation drift.Accepts: array
Submit a correct solution to see your kernel performance.
Implement a 1D sum reduction in Triton. For a float tensor x of length N, write the scalar sum into out[0]:
out[0]=i=0∑N−1x[i]This is the canonical Triton reduction. Each program covers one tile, reduces its lanes in registers, and combines partial sums across programs with a single atomic add on out[0]. Because atomics accumulate, the host must zero out before launch.
Input: x = [1.0, 2.0, 3.0, 4.0]
Output: [10.0]
Input: x = [0.0, -1.0, 2.5, 1.5, -3.0]
Output: [0.0]
Each program reduces its lanes with tl.sum along the tile axis. The masked tail must load other=0.0 so it does not poison the partial.
Combine partials with \texttt{tl.atomic_add} to a single-element output. One atomic per program is far cheaper than one atomic per lane.
Remember to call out.zero_() in the launcher before the kernel; atomics accumulate into whatever value is already there.
torch.float32 on cuda and contiguous; output has shape (1,).atol=1e-2, rtol=1e-2 to absorb float32 accumulation drift.Accepts: array
Submit a correct solution to see your kernel performance.