tl.make_block_ptr creates a descriptor for an N-dimensional block within a parent tensor. It records the base pointer, shape, strides, starting offsets, block shape, and memory order; creating the descriptor does not access memory. Use tl.load and tl.store to perform the actual read and write. section 5.4.3 section 5.6.2
For each block, provide:
- The parent tensor’s base pointer, shape, and strides. section 5.4.3
- The block’s starting offsets, block shape, and dimension order. section 5.4.3
Matrix tiles
A transpose kernel describes an input tile and a transposed destination tile with separate block pointers, then loads, transposes, and stores them. A matrix multiplication kernel similarly describes operand tiles for loading into tl.dot. section 5.4.3 section 5.6.2
Listing 5.5 Tiled matrix transpose using make_block_ptr
@triton.jit
def transpose_tiled_kernel(
x_ptr, y_ptr,
M, N,
stride_xm, stride_xn,
stride_ym, stride_yn,
BLOCK_M: tl.constexpr,
BLOCK_N: tl.constexpr,
):
pid_m = tl.program_id(axis=0)
pid_n = tl.program_id(axis=1)
x_block = tl.make_block_ptr(
x_ptr,
shape=(M, N),
strides=(stride_xm, stride_xn),
offsets=(pid_m * BLOCK_M, pid_n * BLOCK_N),
block_shape=(BLOCK_M, BLOCK_N),
order=(1, 0),
)
tile = tl.load(x_block, boundary_check=(0, 1))
y_block = tl.make_block_ptr(
y_ptr,
shape=(N, M),
strides=(stride_ym, stride_yn),
offsets=(pid_n * BLOCK_N, pid_m * BLOCK_M),
block_shape=(BLOCK_N, BLOCK_M),
order=(1, 0),
)
tl.store(y_block, tl.trans(tile), boundary_check=(0, 1))
See the complete tiled transpose kernel, including block-pointer arguments, boundary checks, and the load-transpose-store sequence. section 5.4.3
