TensorTonic
Problems
Vector Max Reduction in Triton
GPU Programming
Easy

Compute the maximum of a 1D float tensor with one Triton program. For a tensor xxx of length NNN, write the scalar max into out[0]\texttt{out}[0]out[0]:

out[0]=max⁡0≤i<Nx[i]\texttt{out}[0] = \max_{0 \le i < N} x[i]out[0]=0≤i<Nmax​x[i]

This problem uses a single-program reduction: one program loads the entire array (masked at the tail) and reduces it in registers. The pattern is the building block for fused row-wise softmax: load a row, take its max, subtract, then exp.

Loading visualization...

Examples

Input: x = [1.0, 4.0, 2.0, 3.0]

Output: [4.0]

Input: x = [-5.0, -1.0, -3.0, -2.0]

Output: [-1.0]

Hint 1

Size the block to the next power of two above NNN and launch a grid of one program. The whole array lives in registers.

Hint 2

For the tail mask, load with other=-float(’inf’)\texttt{other=-float('inf')}other=-float(’inf’) so padded lanes never win the comparison against real elements.

Hint 3

Reduce in registers with tl.max\texttt{tl.max}tl.max along the tile axis and store the scalar directly. No atomic, no cross-program communication.

Requirements

  • Use a single Triton program that covers the whole array in one tile
  • Mask the tail so masked lanes lose every comparison
  • Store the scalar result directly; no atomics needed for a single-program reduction
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤655361 \le N \le 655361≤N≤65536 for the single-program reduction pattern used here.
  • Input tensor is torch.float32 on cuda and contiguous; output has shape (1,).
  • Tolerance: atol=1e-3. Max is exact under float comparison since no accumulation happens.
Try Similar Problems
Vector Sum Reduction in TritonEasyL2 Vector Norm in TritonEasyRow-Wise LogSumExp in TritonMediumSingle-Pass Mean and Variance in TritonMediumFused Row-Wise Softmax in TritonMediumDropout (Inverted Scaling) in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Vector Max Reduction in Triton

Vector Max Reduction in Triton

GPU Programming
Easy

Compute the maximum of a 1D float tensor with one Triton program. For a tensor xxx of length NNN, write the scalar max into out[0]\texttt{out}[0]out[0]:

out[0]=max⁡0≤i<Nx[i]\texttt{out}[0] = \max_{0 \le i < N} x[i]out[0]=0≤i<Nmax​x[i]

This problem uses a single-program reduction: one program loads the entire array (masked at the tail) and reduces it in registers. The pattern is the building block for fused row-wise softmax: load a row, take its max, subtract, then exp.

Loading visualization...

Examples

Input: x = [1.0, 4.0, 2.0, 3.0]

Output: [4.0]

Input: x = [-5.0, -1.0, -3.0, -2.0]

Output: [-1.0]

Hint 1

Size the block to the next power of two above NNN and launch a grid of one program. The whole array lives in registers.

Hint 2

For the tail mask, load with other=-float(’inf’)\texttt{other=-float('inf')}other=-float(’inf’) so padded lanes never win the comparison against real elements.

Hint 3

Reduce in registers with tl.max\texttt{tl.max}tl.max along the tile axis and store the scalar directly. No atomic, no cross-program communication.

Requirements

  • Use a single Triton program that covers the whole array in one tile
  • Mask the tail so masked lanes lose every comparison
  • Store the scalar result directly; no atomics needed for a single-program reduction
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤655361 \le N \le 655361≤N≤65536 for the single-program reduction pattern used here.
  • Input tensor is torch.float32 on cuda and contiguous; output has shape (1,).
  • Tolerance: atol=1e-3. Max is exact under float comparison since no accumulation happens.
Try Similar Problems
Vector Sum Reduction in TritonEasyL2 Vector Norm in TritonEasyRow-Wise LogSumExp in TritonMediumSingle-Pass Mean and Variance in TritonMediumFused Row-Wise Softmax in TritonMediumDropout (Inverted Scaling) in TritonEasyVector Addition in TritonEasyKV Cache Append in TritonEasyFused Multiply-Add in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasy

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1