interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / controls / softmax_unstable / triton_kernel.py

18 lines · 508 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0
2import triton
3import triton.language as tl
4
5
6@triton.jit
7def _softmax(x, y, D, BLOCK: tl.constexpr):
8 r = tl.program_id(0)
9 k = tl.arange(0, BLOCK)
10 m = k < D
11 # CONTROL: the max subtraction is deliberately omitted
12 v = tl.load(x + r * D + k, mask=m, other=-float("inf"))
13 e = tl.exp(v)
14 tl.store(y + r * D + k, e / tl.sum(e, axis=0), mask=m)
15
16
17def launch(p, t):
18 _softmax[(p["R"],)](t["x"], t["y"], p["D"], BLOCK=triton.next_power_of_2(p["D"]))