TensorTonic
Problems
Vectorized Vector Add in Triton
GPU Programming
Easy

Reimplement elementwise vector addition with a large tile size so each program handles more work. 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]

The kernel logic is identical to the standard vector-add. The differentiator is the block-size choice. With a 102410241024-wide block, a one-million-element add launches roughly 100010001000 programs; with a 409640964096-wide block the same job launches 244244244. Fewer programs amortize launch overhead, widen memory transactions when the compiler can vectorize the loads, and tend to improve achieved bandwidth on long arrays.

The trade-off is register pressure. At fp32 with 409640964096 elements per program, the per-program register footprint is 161616KB - comfortably under the per-SM budget but worth tracking on hotter kernels. This problem isolates the launcher-level decision so the effect is measurable.

Loading visualization...

Examples

Input: x = [1, 2, 3, 4], y = [5, 6, 7, 8]

Output: [6, 8, 10, 12]

Input: x = [0.5, 1.5, 2.5], y = [1, 1, 1]

Output: [1.5, 2.5, 3.5]

Hint 1

Only the launcher constant changes from a standard vector add. The kernel body is byte-for-byte the same; the point is to measure the bandwidth effect of fewer, larger programs.

Hint 2

The tail mask matters more here than at a 102410241024-wide block: a single partial tile now covers up to 409540954095 lanes that must not touch memory.

Hint 3

No reduction, no shared memory. The only knob is the tile width, which the launcher fixes as a tl.constexpr\texttt{tl.constexpr}tl.constexpr on the kernel.

Requirements

  • Use a block size of 409640964096 to amortize launch overhead on long arrays
  • Use one Triton program per contiguous tile of the input
  • Mask the tail so the final partial tile is safe
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1 000 0001 \le N \le 1\,000\,0001≤N≤1000000.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3 (default elementwise tolerance, no fp32 accumulation drift here).
Try Similar Problems
Block-Pointer Matmul in TritonMediumSplit-K Matmul in TritonHardGrouped Program-ID Matmul in TritonHardDropout (Inverted Scaling) in TritonEasyVector Sum Reduction in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyVector Max Reduction in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasy

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Vectorized Vector Add in Triton

Vectorized Vector Add in Triton

GPU Programming
Easy

Reimplement elementwise vector addition with a large tile size so each program handles more work. 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]

The kernel logic is identical to the standard vector-add. The differentiator is the block-size choice. With a 102410241024-wide block, a one-million-element add launches roughly 100010001000 programs; with a 409640964096-wide block the same job launches 244244244. Fewer programs amortize launch overhead, widen memory transactions when the compiler can vectorize the loads, and tend to improve achieved bandwidth on long arrays.

The trade-off is register pressure. At fp32 with 409640964096 elements per program, the per-program register footprint is 161616KB - comfortably under the per-SM budget but worth tracking on hotter kernels. This problem isolates the launcher-level decision so the effect is measurable.

Loading visualization...

Examples

Input: x = [1, 2, 3, 4], y = [5, 6, 7, 8]

Output: [6, 8, 10, 12]

Input: x = [0.5, 1.5, 2.5], y = [1, 1, 1]

Output: [1.5, 2.5, 3.5]

Hint 1

Only the launcher constant changes from a standard vector add. The kernel body is byte-for-byte the same; the point is to measure the bandwidth effect of fewer, larger programs.

Hint 2

The tail mask matters more here than at a 102410241024-wide block: a single partial tile now covers up to 409540954095 lanes that must not touch memory.

Hint 3

No reduction, no shared memory. The only knob is the tile width, which the launcher fixes as a tl.constexpr\texttt{tl.constexpr}tl.constexpr on the kernel.

Requirements

  • Use a block size of 409640964096 to amortize launch overhead on long arrays
  • Use one Triton program per contiguous tile of the input
  • Mask the tail so the final partial tile is safe
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1 000 0001 \le N \le 1\,000\,0001≤N≤1000000.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3 (default elementwise tolerance, no fp32 accumulation drift here).
Try Similar Problems
Block-Pointer Matmul in TritonMediumSplit-K Matmul in TritonHardGrouped Program-ID Matmul in TritonHardDropout (Inverted Scaling) in TritonEasyVector Sum Reduction in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyVector Max Reduction in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasy

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