TensorTonic
Problems
Vector Addition in Triton
GPU ProgrammingLinear Algebra
Easy

Implement an elementwise vector addition kernel in Triton. For each index iii in [0,N)[0, N)[0,N):

out[i]=x[i]+y[i]\texttt{out}[i] = x[i] + y[i]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 NNN, and uses tl.load\texttt{tl.load}tl.load and tl.store\texttt{tl.store}tl.store to move data through registers.

Loading visualization...

Examples

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]

Hint 1

Each program owns one tile. Get its index from \texttt{tl.program_id} and build lane offsets across the tile.

Hint 2

When NNN 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.

Hint 3

No reduction, no shared memory: this is a pure map. Load xxx and yyy, add in registers, store the result.

Requirements

  • Use one Triton program per contiguous tile of BLOCK_SIZE\texttt{BLOCK\_SIZE}BLOCK_SIZE elements
  • Mask the tail so out-of-range lanes never touch memory
  • Do not use external libraries
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • All tensors are torch.float32 on cuda and contiguous.
  • Tolerance: atol=1e-3.
Try Similar Problems
Fused Multiply-Add in TritonEasyL2 Vector Norm in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumAutotuned Matrix Multiplication in TritonMediumTiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Vector Addition in Triton

Vector Addition in Triton

GPU ProgrammingLinear Algebra
Easy

Implement an elementwise vector addition kernel in Triton. For each index iii in [0,N)[0, N)[0,N):

out[i]=x[i]+y[i]\texttt{out}[i] = x[i] + y[i]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 NNN, and uses tl.load\texttt{tl.load}tl.load and tl.store\texttt{tl.store}tl.store to move data through registers.

Loading visualization...

Examples

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]

Hint 1

Each program owns one tile. Get its index from \texttt{tl.program_id} and build lane offsets across the tile.

Hint 2

When NNN 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.

Hint 3

No reduction, no shared memory: this is a pure map. Load xxx and yyy, add in registers, store the result.

Requirements

  • Use one Triton program per contiguous tile of BLOCK_SIZE\texttt{BLOCK\_SIZE}BLOCK_SIZE elements
  • Mask the tail so out-of-range lanes never touch memory
  • Do not use external libraries
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • All tensors are torch.float32 on cuda and contiguous.
  • Tolerance: atol=1e-3.
Try Similar Problems
Fused Multiply-Add in TritonEasyL2 Vector Norm in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumAutotuned Matrix Multiplication in TritonMediumTiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMedium

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1