openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / scan_i32 / 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 _scan(x, y, n, BLOCK: tl.constexpr): |
| 8 | # one program walks the input in blocks: block-local inclusive cumsum plus the running carry |
| 9 | lane = tl.arange(0, BLOCK) |
| 10 | carry = tl.sum(tl.zeros([BLOCK], dtype=tl.int32), axis=0) |
| 11 | for off in range(0, n, BLOCK): |
| 12 | i = off + lane |
| 13 | m = i < n |
| 14 | v = tl.load(x + i, mask=m, other=0) |
| 15 | tl.store(y + i, tl.cumsum(v, axis=0) + carry, mask=m) |
| 16 | carry += tl.sum(v, axis=0) |
| 17 | |
| 18 | |
| 19 | def launch(p, t): |
| 20 | _scan[(1,)](t["x"], t["y"], p["n"], BLOCK=4096) |