interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / gemm_nn / triton_kernel.py

24 lines · 1140 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0
2# tl.dot with input_precision="ieee": full f32 products and f32 accumulation (the interpreter runs
3# np.matmul in float32; on a GPU this forbids TF32), so the gamma(K) dot-product bound applies.
4import triton
5import triton.language as tl
6
7
8@triton.jit
9def _gemm_nn(A, B, C, M, N, K, BM: tl.constexpr, BN: tl.constexpr, BK: tl.constexpr):
10 rm = tl.program_id(0) * BM + tl.arange(0, BM)
11 rn = tl.program_id(1) * BN + tl.arange(0, BN)
12 rk = tl.arange(0, BK)
13 acc = tl.zeros((BM, BN), dtype=tl.float32)
14 for k0 in range(0, K, BK):
15 kk = k0 + rk
16 a = tl.load(A + rm[:, None] * K + kk[None, :], mask=(rm[:, None] < M) & (kk[None, :] < K), other=0.0)
17 b = tl.load(B + kk[:, None] * N + rn[None, :], mask=(kk[:, None] < K) & (rn[None, :] < N), other=0.0)
18 acc = tl.dot(a, b, acc, input_precision="ieee")
19 tl.store(C + rm[:, None] * N + rn[None, :], acc, mask=(rm[:, None] < M) & (rn[None, :] < N))
20
21
22def launch(p, t):
23 M, N, K = p["M"], p["N"], p["K"]
24 _gemm_nn[(triton.cdiv(M, 16), triton.cdiv(N, 16))](t["A"], t["B"], t["C"], M, N, K, BM=16, BN=16, BK=16)