Implement an elementwise vector addition kernel in Triton. For each index i in [0,N):
out[i]=x[i]+y[i]This is the canonical Triton "hello world" map. It teaches the block-level programming model: launch a 1D grid of programs where each program handles a contiguous tile, masks tail elements that fall past N, and uses tl.load and tl.store to move data through registers.
Input: x = [1.0, 2.0, 3.0, 4.0], y = [5.0, 6.0, 7.0, 8.0]
Output: [6.0, 8.0, 10.0, 12.0]
Input: x = [0.0, -1.0, 2.5], y = [1.0, 1.0, -0.5]
Output: [1.0, 0.0, 2.0]
Each program owns one tile. Get its index from \texttt{tl.program_id} and build lane offsets across the tile.
When N is not a multiple of the block size, the last tile spills past the array. A single tail mask shared by every load and store keeps those lanes inert.
No reduction, no shared memory: this is a pure map. Load x and y, add in registers, store the result.
torch.float32 on cuda and contiguous.atol=1e-3.Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.
Implement an elementwise vector addition kernel in Triton. For each index i in [0,N):
out[i]=x[i]+y[i]This is the canonical Triton "hello world" map. It teaches the block-level programming model: launch a 1D grid of programs where each program handles a contiguous tile, masks tail elements that fall past N, and uses tl.load and tl.store to move data through registers.
Input: x = [1.0, 2.0, 3.0, 4.0], y = [5.0, 6.0, 7.0, 8.0]
Output: [6.0, 8.0, 10.0, 12.0]
Input: x = [0.0, -1.0, 2.5], y = [1.0, 1.0, -0.5]
Output: [1.0, 0.0, 2.0]
Each program owns one tile. Get its index from \texttt{tl.program_id} and build lane offsets across the tile.
When N is not a multiple of the block size, the last tile spills past the array. A single tail mask shared by every load and store keeps those lanes inert.
No reduction, no shared memory: this is a pure map. Load x and y, add in registers, store the result.
torch.float32 on cuda and contiguous.atol=1e-3.Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.