@triton.autotune(configs=get_cuda_autotune_config(), key=['M', 'N', 'K'])
@triton.jit
def matmul_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,
    stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_SIZE_M: tl.constexpr,
    BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:
    tl.constexpr, ALLOWTF32: tl.constexpr, PRECISIONMATCH: tl.constexpr):
    """Kernel for computing the matmul C = A x B.
    A has shape (M, K), B has shape (K, N) and C has shape (M, N)
    """
    pid = tl.program_id(axis=0)
    num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)
    num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
    num_pid_in_group = GROUP_SIZE_M * num_pid_n
    group_id = pid // num_pid_in_group
    first_pid_m = group_id * GROUP_SIZE_M
    group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)
    pid_m = first_pid_m + pid % num_pid_in_group % group_size_m
    pid_n = pid % num_pid_in_group // group_size_m
    a_tile = tl.make_block_ptr(a_ptr, shape=(M, K), strides=(stride_am,
        stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0), block_shape=(
        BLOCK_SIZE_M, BLOCK_SIZE_K), order=(0, 1))
    b_tile = tl.make_block_ptr(b_ptr, shape=(K, N), strides=(stride_bk,
        stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N), block_shape=(
        BLOCK_SIZE_K, BLOCK_SIZE_N), order=(0, 1))
    ASM: tl.constexpr = 'cvt.rna.tf32.f32 $0, $1;'
    accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)
    for _ in range(0, tl.cdiv(K, BLOCK_SIZE_K)):
        a = tl.load(a_tile, boundary_check=(1,), padding_option='zero')
        b = tl.load(b_tile, boundary_check=(0,), padding_option='zero')
        if ALLOWTF32 and PRECISIONMATCH:
            a = tl.inline_asm_elementwise(ASM, '=r, r', [a], dtype=tl.
                float32, is_pure=True, pack=1)
            b = tl.inline_asm_elementwise(ASM, '=r, r', [b], dtype=tl.
                float32, is_pure=True, pack=1)
        accumulator = tl.dot(a, b, accumulator, input_precision='tf32' if
            ALLOWTF32 else 'ieee')
        a_tile = tl.advance(a_tile, (0, BLOCK_SIZE_K))
        b_tile = tl.advance(b_tile, (BLOCK_SIZE_K, 0))
    c_tile = tl.make_block_ptr(c_ptr, shape=(M, N), strides=(stride_cm,
        stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n * BLOCK_SIZE_N),
        block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))
    c = accumulator.to(c_tile.dtype.element_ty)
    tl.store(c_tile, c, boundary_check=(0, 1))
