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 / api / attn_tables.om

124 lines · 2475 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note The caller acquires native table pointers; Omega walks each plain table.
3note Preserve the cut-F float polynomial, scalar order and empty-split handling.
4fn av_ex2 x f32 to f32
5if le x f32 -127.0
6ret f32 0.0
7end
8if gt x f32 127.0
9x = f32 127.0
10end
11adj = f32 0.5
12if lt x f32 0.0
13adj = f32 -0.5
14end
15n = int add x adj
16f = sub x f32 n
17px = f32 1.535336188319500e-4
18px = add mul px f f32 1.339887440266574e-3
19px = add mul px f f32 9.618437357674640e-3
20px = add mul px f f32 5.550332471162809e-2
21px = add mul px f f32 2.402264791363012e-1
22px = add mul px f f32 6.931472028550421e-1
23px = add f32 1.0 mul f px
24if lt n -126
25px = mul px f32 0.5
26n = int -126
27end
28ret mul px bitcast f32 shl uint add n 127 23
29end
30fn av_fw p view f32 * q view ulong 16 row ulong w edit f32 18 to ulong
31pw = add get q 2 2
32base = mul row get q 1
33base = mul base pw
34mx = bitcast f32 uint 4286578688
35for s ulong get q 1
36idx = mul s pw
37idx = add idx base
38idx = add idx get q 2
39v = get p idx
40if gt v mx
41mx = v
42end
43end
44put w 17 f32 0.0
45if not gt mx bitcast f32 uint 4286578688
46ret 0
47end
48put w 17 f32 1.0
49lsum = f32 0.0
50for s ulong get q 1
51idx = mul s pw
52idx = add idx base
53idx = add idx get q 2
54v = get p idx
55v = av_ex2 sub v mx
56put w s v
57idx = add idx 1
58v = mul v get p idx
59lsum = add lsum v
60end
61put w 16 div f32 1.0 lsum
62ret 0
63end
64fn av_fval p view f32 * w view f32 18 q view ulong 4 d ulong to f32
65if not gt get w 17 f32 0.0
66ret f32 0.0
67end
68base = mul get q 3 get q 1
69base = mul base add get q 2 2
70a = f32 0.0
71for s ulong get q 1
72idx = mul s add get q 2 2
73idx = add idx base
74idx = add idx d
75v = get p idx
76v = mul get w s v
77a = add a v
78end
79ret mul a get w 16
80end
81fn av_fout p view f32 * dest edit f32 * w view f32 18 q view ulong 4 to void
82for d ulong get q 2
83v = av_fval p w q d
84idx = mul get q 3 get q 2
85idx = add idx d
86put dest idx v
87end
88end
89fn vc_fold p view f32 * dest edit f32 * q view ulong 16 to ulong
90w = new f32 18 0.0
91r = new ulong 4 0
92put r 0 get q 0
93put r 1 get q 1
94put r 2 get q 2
95for jj ulong get q 7
96row = add get q 6 jj
97rc = av_fw p q row w
98if ne rc 0
99ret rc
100end
101put r 3 row
102av_fout p dest w r
103end
104ret 0
105end
106fn av_fold p view f32 * dest edit f32 * q view ulong 16 to ulong
107z = new ulong 16 0
108for j ulong 16
109put z j get q j
110end
111for bb ulong add div get q 0 1000000 1
112put z 6 mul bb 1000000
113cnt = sub get q 0 get z 6
114if gt cnt 1000000
115cnt = ulong 1000000
116end
117put z 7 cnt
118rc = vc_fold p dest z
119if ne rc 0
120ret rc
121end
122end
123ret 0
124end