interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / rmsnorm / triton_kernel.py

17 lines · 510 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0
2import triton
3import triton.language as tl
4
5
6@triton.jit
7def _rmsnorm(x, w, y, D, BLOCK: tl.constexpr):
8 r = tl.program_id(0)
9 k = tl.arange(0, BLOCK)
10 m = k < D
11 v = tl.load(x + r * D + k, mask=m, other=0.0)
12 rs = 1.0 / tl.sqrt(tl.sum(v * v, axis=0) / D + 1e-6)
13 tl.store(y + r * D + k, v * rs * tl.load(w + k, mask=m, other=0.0), mask=m)
14
15
16def launch(p, t):
17 _rmsnorm[(p["R"],)](t["x"], t["w"], t["y"], p["D"], BLOCK=triton.next_power_of_2(p["D"]))