Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/openaccel-lab/blob/main/workloads/argmax/triton_kernel.py # openaccel-lab aien-dev/openaccel-lab Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `openaccel-lab / workloads / argmax / triton_kernel.py` 24 lines ยท 856 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 import triton 3 import triton.language as tl 4 5 6 @triton.jit 7 def _amax(x, y, n, BLOCK: tl.constexpr): 8 # one program: lane j keeps the first maximum of x[j], x[j+BLOCK], ... (strict > keeps the 9 # earlier index); then the smallest index among the lanes that hold the overall maximum. 10 lane = tl.arange(0, BLOCK) 11 bv = tl.full([BLOCK], float("-inf"), dtype=tl.float32) 12 bi = tl.full([BLOCK], `2147483647`, dtype=tl.int32) 13 for off in range(0, n, BLOCK): 14 i = off + lane 15 v = tl.load(x + i, mask=i < n, other=float("-inf")) 16 take = (v > bv) & (i < n) 17 bv = tl.where(take, v, bv) 18 bi = tl.where(take, i, bi) 19 m = tl.max(bv, axis=0) 20 tl.store(y, tl.min(tl.where(bv == m, bi, `2147483647`), axis=0)) 21 22 23 def launch(p, t): 24 _amax[(1,)](t["x"], t["y"], p["n"], BLOCK=4096)