openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / dot / 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 _dot(a, b, y, n, BLOCK: tl.constexpr): |
| 8 | # one program: BLOCK lane accumulators of a[i]*b[i] over the strided input, then a tree sum |
| 9 | lane = tl.arange(0, BLOCK) |
| 10 | acc = tl.zeros([BLOCK], dtype=tl.float32) |
| 11 | for off in range(0, n, BLOCK): |
| 12 | i = off + lane |
| 13 | m = i < n |
| 14 | acc += tl.load(a + i, mask=m, other=0.0) * tl.load(b + i, mask=m, other=0.0) |
| 15 | tl.store(y, tl.sum(acc, axis=0)) |
| 16 | |
| 17 | |
| 18 | def launch(p, t): |
| 19 | _dot[(1,)](t["a"], t["b"], t["y"], p["n"], BLOCK=4096) |