v9.1.1
Menu

Triton Row Max Reduction

mediumFREEReductions & NormalizationTriton Programming

Problem Statement

Compute the maximum of each row of a (M, N) tensor. Pad masked lanes with -inf so they never win the max.

Background

Identical structure to the row sum, but use other=-float('inf') on the load and tl.max(row, axis=0).

Your Task

Implement row_max_kernel and run(M=64, N=300) comparing to x.max(dim=1).values.

How it is tested

Your solution must define a top-level function run(...) that allocates inputs on the GPU, launches your Triton kernel, and returns a boolean from torch.allclose(triton_out, torch_reference, ...). The grader prints run(...); the expected output is True.

Example

Input
M = 64, N = 300
Output
True
Reasoning
  • The input values M = 64 and N = 300 define the size of the tensor, with 64 rows and 300 columns.
  • The row_max_kernel function computes the maximum of each row, replacing masked lanes with −inf-inf to ensure they don't affect the result.
  • The run function allocates the input tensor on the GPU, launches the row_max_kernel, and calculates the reference result using x.max(dim=1).values.
  • The output True indicates that the result from the row_max_kernel is identical to the reference result, within a certain tolerance, as verified by torch.allclose.

Constraints

  • Load masked lanes with other=-float('inf')
  • Reduce with tl.max(row, axis=0)
  • One program per row

Learn this in

More from Triton Programming

solution.py

Test results

Sign in to run your code against the test cases.