Skip to content

matmul精度没有对齐,需要手动添加hint #122

@Truth-Ke

Description

@Truth-Ke

Describe the bug
精度没有对齐

@triton.jit
def linear_relu_kernel(input_ptr, weight_ptr, bias_ptr, output_ptr, M, N, K,
    stride_im, stride_in, stride_wk, stride_wn, stride_om, stride_on,
    ACTIVATION: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,
    BLOCK_K: tl.constexpr):
    pid = tl.program_id(0)
    num_pid_m = tl.cdiv(M, BLOCK_M)
    pid_m = pid % num_pid_m
    pid_n = pid // num_pid_m
    offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)
    offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)
    input_ptr_block = input_ptr + offs_m[:, None] * stride_im
    weight_ptr_block = weight_ptr + offs_n[None, :] * stride_wk
    acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
    for k in range(0, K, BLOCK_K):
        k_offs = k + tl.arange(0, BLOCK_K)
        k_mask = k_offs < K
        input_block = tl.load(input_ptr_block + k_offs[None, :] * stride_in,
            mask=(offs_m[:, None] < M) & k_mask[None, :], other=0.0)
        weight_block = tl.load(weight_ptr_block + k_offs[:, None] *
            stride_wn, mask=k_mask[:, None] & (offs_n[None, :] < N), other=0.0)
        acc += tl.dot(input_block, weight_block)
    if bias_ptr is not None:
        bias = tl.load(bias_ptr + offs_n, mask=offs_n < N, other=0.0)
        acc += bias[None, :]
    if ACTIVATION:
        acc = tl.where(acc > 0, acc, 0.0)
    mask_output = (offs_m[:, None] < M) & (offs_n[None, :] < N)
    output_ptr += offs_m[:, None] * stride_om + offs_n[None, :] * stride_on
    tl.store(output_ptr, acc, mask=mask_output)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions