Compute the maximum of a 1D float tensor with one Triton program. For a tensor x of length N, write the scalar max into out[0]:
out[0]=0≤i<Nmaxx[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.
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]
Size the block to the next power of two above N and launch a grid of one program. The whole array lives in registers.
For the tail mask, load with other=-float(’inf’) so padded lanes never win the comparison against real elements.
Reduce in registers with tl.max along the tile axis and store the scalar directly. No atomic, no cross-program communication.
torch.float32 on cuda and contiguous; output has shape (1,).atol=1e-3. Max is exact under float comparison since no accumulation happens.Accepts: array
Submit a correct solution to see your kernel performance.
Compute the maximum of a 1D float tensor with one Triton program. For a tensor x of length N, write the scalar max into out[0]:
out[0]=0≤i<Nmaxx[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.
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]
Size the block to the next power of two above N and launch a grid of one program. The whole array lives in registers.
For the tail mask, load with other=-float(’inf’) so padded lanes never win the comparison against real elements.
Reduce in registers with tl.max along the tile axis and store the scalar directly. No atomic, no cross-program communication.
torch.float32 on cuda and contiguous; output has shape (1,).atol=1e-3. Max is exact under float comparison since no accumulation happens.Accepts: array
Submit a correct solution to see your kernel performance.