interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / dnn-activations / kernel.om

153 lines · 4076 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note One warp per CTA, one component per lane. Tail lanes exit before addressing.
3note Vregs: 0 tid,1 block,2 input pair,3 output pair,4 input address pair,
4note 5 output address pair,6 count,7 index,8 original x,9 bounded abs x,
5note 10 t,11 exp,12 result,13 constant scratch,14 scratch,15 polynomial,
6note 16 one,17 zero,18 log2e,19 original abs bits. Params input,output,count.
7fn da_copy x edit ulong 8192 m edit ulong 512 d ulong a ulong to void
8aa_mad x m d a 1 AN
9end
10fn da_mulc x edit ulong 8192 m edit ulong 512 d ulong a ulong v f32 to void
11aa_mov x m 13 ulong bitcast uint v
12aa_bin x m 32 d a 13
13end
14fn da_addc x edit ulong 8192 m edit ulong 512 d ulong a ulong v f32 to void
15aa_mov x m 13 ulong bitcast uint v
16aa_bin x m 30 d a 13
17end
18fn da_horner x edit ulong 8192 m edit ulong 512 v f32 to void
19aa_bin x m 32 15 15 10
20da_addc x m 15 15 v
21end
22fn da_exp x edit ulong 8192 m edit ulong 512 to void
23note Input 11 is nonpositive and bounded. Tail exp forced to exact zero.
24aa_bin x m 32 11 11 18
25aa_i x m 47 aa_rg 11 11 AN AN 0 2
26end
27fn da_erf x edit ulong 8192 m edit ulong 512 to void
28note A&S 7.1.26 erfc polynomial at |x|/sqrt(2), not tanh GELU.
29da_mulc x m 9 9 0.707106781f32
30da_mulc x m 10 9 0.3275911f32
31aa_bin x m 30 10 10 16
32aa_i x m 40 aa_rg 10 10 AN AN 0 2
33aa_bin x m 32 11 9 9
34da_mulc x m 11 11 -1.0f32
35da_exp x m
36aa_mov x m 13 ulong bitcast uint 10.0f32
37aa_cmp x m 19 13
38aa_mov x m 11 0
39aa_pred x m 2
40aa_mov x m 15 ulong bitcast uint 1.061405429f32
41da_horner x m -1.453152027f32
42da_horner x m 1.421413741f32
43da_horner x m -0.284496736f32
44da_horner x m 0.254829592f32
45aa_bin x m 32 15 15 10
46aa_bin x m 32 15 15 11
47da_mulc x m 15 15 0.5f32
48note Negative tail uses x*erfc/2 directly; no 1-erf cancellation.
49aa_bin x m 31 14 16 15
50aa_bin x m 32 12 8 14
51aa_mov x m 13 2147483648
52aa_cmp x m 8 13
53aa_bin x m 32 12 8 15
54aa_pred x m 2
55end
56fn da_sig x edit ulong 8192 m edit ulong 512 op ulong to void
57note SiLU uses exp(-abs x). Tanh GELU uses sigmoid(2*sqrt(2/pi)*(x+.044715*x^3)).
58if eq op 2
59aa_bin x m 32 11 9 9
60da_mulc x m 11 11 0.044715f32
61aa_bin x m 30 11 11 16
62aa_bin x m 32 11 11 9
63da_mulc x m 11 11 -1.595769122f32
64else
65da_mulc x m 11 9 -1.0f32
66end
67da_exp x m
68cut = f32 80.0
69if eq op 2
70cut = f32 10.0
71end
72aa_mov x m 13 ulong bitcast uint cut
73aa_cmp x m 19 13
74aa_mov x m 11 0
75aa_pred x m 2
76aa_bin x m 30 10 16 11
77aa_i x m 40 aa_rg 10 10 AN AN 0 2
78aa_bin x m 32 12 8 10
79note Multiply exp before x for negative values. Every intermediate stays finite.
80aa_bin x m 32 14 11 10
81aa_mov x m 13 2147483648
82aa_cmp x m 8 13
83aa_bin x m 32 12 8 14
84aa_pred x m 2
85end
86fn da_start x edit ulong 8192 m edit ulong 512 dtype ulong to void
87for i ulong 20
88kind = ulong 1
89if and ge i 2 le i 5
90kind = ulong 2
91end
92v = aa_v m kind
93end
94put m 2 1
95put m 320 2
96aa_i x m 7 aa_rg 0 AN AN AN 856 260
97aa_i x m 3 aa_rg 0 AN AN AN 33 2
98aa_i x m 3 aa_rg 1 AN AN AN 37 2
99aa_i x m 5 aa_rg 2 AN AN AN 896 2
100aa_i x m 5 aa_rg 3 AN AN AN 904 2
101aa_i x m 4 aa_rg 6 AN AN AN 912 2
102aa_mad x m 7 1 32 0
103aa_cmp x m 7 6
104aa_i x m 45 aa_rg AN AN AN AN 0 5
105aa_pred x m 2
106bytes = ulong 4
107if ne dtype 0
108bytes = ulong 2
109end
110aa_addr x m 4 7 bytes 2
111aa_addr x m 5 7 4 3
112aa_load x m 8 4 0 dtype
113aa_mov x m 16 ulong bitcast uint 1.0f32
114aa_mov x m 17 0
115aa_mov x m 18 ulong bitcast uint 1.442695041f32
116aa_i x m 18 aa_rg 19 8 AN AN 2147483647 0
117end
118fn dnn_activations op ulong dtype ulong unused ulong mutant ulong x edit ulong 8192 m edit ulong 512 to ulong
119for i ulong 512
120put m i 0
121end
122if or or gt op 3 gt dtype 2 or ne unused 0 ne mutant 0
123ret 1
124end
125da_start x m dtype
126if eq op 0
127note ReLU copies signed zero; strictly negative values produce positive zero.
128da_copy x m 12 8
129aa_mov x m 13 2147483648
130aa_cmp x m 8 13
131aa_mov x m 12 0
132aa_pred x m 2
133aa_mov x m 13 1
134aa_cmp x m 19 13
135da_copy x m 12 8
136aa_pred x m 6
137else
138cut = f32 80.0
139if ne op 3
140cut = f32 10.0
141end
142aa_mov x m 13 ulong bitcast uint cut
143aa_bin x m 36 9 19 13
144if eq op 1
145da_erf x m
146else
147da_sig x m op
148end
149end
150aa_i x m 12 aa_rg AN 5 12 AN 0 3
151aa_i x m 45 aa_rg AN AN AN AN 0 5
152ret get m 4
153end