Implement a tiled row reduction in Triton. For an input matrix x with R rows and C columns, its output y contains one float32 sum per row:
yr=c=0∑C−1float32(xr,c).Here, r and c index rows and columns, and float32 denotes conversion before summation. Complete only the empty kernel body; the supplied solve launcher is implemented. The pointers identify input and output buffers, n_cols is the column count, row_stride and col_stride are input strides in elements, and BLOCK_SIZE is the compile-time tile width. Return no value; write a contiguous float32 vector of length R into the supplied output buffer.
Input: x = [[1, 1, 1], [1, 1, 1]], dtype = float32, tile_size = 32
Output: [3, 3]
Explanation: Each row contains three ones, so each row sum is 3.
Input: x has shape (1, 33) with every value equal to 1, dtype = float16, tile_size = 32
Output: [33]
Input: x = [[1, 2, -1], [0.5, 1.5, 2]], dtype = bfloat16, tile_size = 64
Output: [2, 4]
tl.load accepts a mask and a fallback value for incomplete tiles.
tl.sum reduces values along a block axis.
tl.program_id identifies the current row program.
Accepts: array
Accepts: string
Accepts: number
Submit a correct solution to see your kernel performance.
Implement a tiled row reduction in Triton. For an input matrix x with R rows and C columns, its output y contains one float32 sum per row:
yr=c=0∑C−1float32(xr,c).Here, r and c index rows and columns, and float32 denotes conversion before summation. Complete only the empty kernel body; the supplied solve launcher is implemented. The pointers identify input and output buffers, n_cols is the column count, row_stride and col_stride are input strides in elements, and BLOCK_SIZE is the compile-time tile width. Return no value; write a contiguous float32 vector of length R into the supplied output buffer.
Input: x = [[1, 1, 1], [1, 1, 1]], dtype = float32, tile_size = 32
Output: [3, 3]
Explanation: Each row contains three ones, so each row sum is 3.
Input: x has shape (1, 33) with every value equal to 1, dtype = float16, tile_size = 32
Output: [33]
Input: x = [[1, 2, -1], [0.5, 1.5, 2]], dtype = bfloat16, tile_size = 64
Output: [2, 4]
tl.load accepts a mask and a fallback value for incomplete tiles.
tl.sum reduces values along a block axis.
tl.program_id identifies the current row program.
Accepts: array
Accepts: string
Accepts: number
Submit a correct solution to see your kernel performance.