openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / tsoftmax16 / 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 _tsoftmax16(x, y, NR: tl.constexpr): |
| 8 | r = tl.program_id(0) * NR + tl.arange(0, NR) |
| 9 | c = tl.arange(0, 32) |
| 10 | v = tl.load(x + r[:, None] * 32 + c[None, :]) |
| 11 | m = tl.max(v, axis=1) |
| 12 | e = tl.exp(v - m[:, None]) |
| 13 | s = tl.sum(e, axis=1) |
| 14 | tl.store(y + r[:, None] * 32 + c[None, :], e / s[:, None]) |
| 15 | |
| 16 | |
| 17 | def launch(p, t): |
| 18 | _tsoftmax16[(p["TILES"],)](t["x"], t["y"], NR=16) |