Implement a tiled transpose kernel in Triton. Given A of shape (M,N), write out of shape (N,M) such that:
out[j,i]=A[i,j]This is a 2D tile pattern with no reduction: each program loads a BLOCK_M×BLOCK_N tile of A and stores its transpose into out. The interesting part is that the load is row-contiguous in A but the store is row-contiguous in a transposed coordinate system, so the per-axis strides on the two pointer expressions are swapped.
Input: A = [[1, 2, 3], [4, 5, 6]]
Output: [[1, 4], [2, 5], [3, 6]]
Input: A = [[1, 2], [3, 4], [5, 6]]
Output: [[1, 3, 5], [2, 4, 6]]
Use a 2D launch grid sized (⌈M/BLOCK_M⌉,⌈N/BLOCK_N⌉). Each program owns a tile of A in the input coordinate system.
Build one set of row and column index vectors. Use them on the load with A's strides, and on the store with out's strides but with row and column roles swapped.
Both tile axes can be partial. Combine the row tail mask and the column tail mask with an AND for the 2D mask on the load and the store.
torch.float32 on cuda.atol=1e-3. No accumulation, no precision loss.Accepts: array
Submit a correct solution to see your kernel performance.
Implement a tiled transpose kernel in Triton. Given A of shape (M,N), write out of shape (N,M) such that:
out[j,i]=A[i,j]This is a 2D tile pattern with no reduction: each program loads a BLOCK_M×BLOCK_N tile of A and stores its transpose into out. The interesting part is that the load is row-contiguous in A but the store is row-contiguous in a transposed coordinate system, so the per-axis strides on the two pointer expressions are swapped.
Input: A = [[1, 2, 3], [4, 5, 6]]
Output: [[1, 4], [2, 5], [3, 6]]
Input: A = [[1, 2], [3, 4], [5, 6]]
Output: [[1, 3, 5], [2, 4, 6]]
Use a 2D launch grid sized (⌈M/BLOCK_M⌉,⌈N/BLOCK_N⌉). Each program owns a tile of A in the input coordinate system.
Build one set of row and column index vectors. Use them on the load with A's strides, and on the store with out's strides but with row and column roles swapped.
Both tile axes can be partial. Combine the row tail mask and the column tail mask with an AND for the 2D mask on the load and the store.
torch.float32 on cuda.atol=1e-3. No accumulation, no precision loss.Accepts: array
Submit a correct solution to see your kernel performance.