openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / rope / triton_kernel.py
| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | import triton |
| 3 | import triton.language as tl |
| 4 | |
| 5 | |
| 6 | @triton.jit |
| 7 | def _rope(x, cs, sn, y, H, h, BLOCK: tl.constexpr): |
| 8 | th = tl.program_id(0) # t*H + j |
| 9 | t = th // H |
| 10 | i = tl.arange(0, BLOCK) |
| 11 | m = i < h |
| 12 | o = th * 2 * h + i |
| 13 | c = tl.load(cs + t * h + i, mask=m, other=0.0) |
| 14 | s = tl.load(sn + t * h + i, mask=m, other=0.0) |
| 15 | x1 = tl.load(x + o, mask=m, other=0.0) |
| 16 | x2 = tl.load(x + o + h, mask=m, other=0.0) |
| 17 | tl.store(y + o, x1 * c - x2 * s, mask=m) |
| 18 | tl.store(y + o + h, x1 * s + x2 * c, mask=m) |
| 19 | |
| 20 | |
| 21 | def launch(p, t): |
| 22 | _rope[(p["T"] * p["H"],)](t["x"], t["cos"], t["sin"], t["y"], p["H"], p["h"], |
| 23 | BLOCK=triton.next_power_of_2(p["h"])) |