Implement a tiled matrix multiplication kernel in Triton. Given A of shape (M,K) and B of shape (K,N), compute C=A⋅B of shape (M,N):
C[i,j]=k=0∑K−1A[i,k]⋅B[k,j]This is the canonical 2D-tile parallel pattern. Each program owns a BLOCK_M×BLOCK_N output tile and walks the shared K dimension in chunks, accumulating partial products in an fp32 register tile before storing the result.
Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]
Output: [[19, 22], [43, 50]]
Input: A = [[1, 0, 1], [0, 1, 0]], B = [[1, 2], [3, 4], [5, 6]]
Output: [[6, 8], [3, 4]]
Use a 2D launch grid sized (⌈M/BLOCK_M⌉,⌈N/BLOCK_N⌉). Each program reads its two program IDs to locate its output tile.
Initialize the accumulator with tl.zeros((BLOCK_M,BLOCK_N),dtype=tl.float32), loop over K in steps of BLOCK_K, and cast to the output dtype only on the final store.
Use tl.dot on the loaded A and B tiles. The mask on the K tail prevents partial products from leaking past the last full chunk.
torch.float32 on cuda.atol=1e-2 + rtol=1e-2 * abs(expected) for K≥128 to absorb fp32 accumulation drift.Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.
Implement a tiled matrix multiplication kernel in Triton. Given A of shape (M,K) and B of shape (K,N), compute C=A⋅B of shape (M,N):
C[i,j]=k=0∑K−1A[i,k]⋅B[k,j]This is the canonical 2D-tile parallel pattern. Each program owns a BLOCK_M×BLOCK_N output tile and walks the shared K dimension in chunks, accumulating partial products in an fp32 register tile before storing the result.
Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]
Output: [[19, 22], [43, 50]]
Input: A = [[1, 0, 1], [0, 1, 0]], B = [[1, 2], [3, 4], [5, 6]]
Output: [[6, 8], [3, 4]]
Use a 2D launch grid sized (⌈M/BLOCK_M⌉,⌈N/BLOCK_N⌉). Each program reads its two program IDs to locate its output tile.
Initialize the accumulator with tl.zeros((BLOCK_M,BLOCK_N),dtype=tl.float32), loop over K in steps of BLOCK_K, and cast to the output dtype only on the final store.
Use tl.dot on the loaded A and B tiles. The mask on the K tail prevents partial products from leaking past the last full chunk.
torch.float32 on cuda.atol=1e-2 + rtol=1e-2 * abs(expected) for K≥128 to absorb fp32 accumulation drift.Accepts: array
Accepts: array
Submit a correct solution to see your kernel performance.