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 / gemm-any / host.om

256 lines · 4429 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note x32: type rt ct wm wn stall mutant band M N K layout lda ldb A B AP BP C.
3note p64: Mp Np Kp KS2 a_bytes b_bytes ap_bytes bp_bytes grid[6] threads[3], spans[2], effective_ld[2].
4note p24..53 launch argument words; p54 first launch. Result 0 OK, 1 BAD_ARGS, 2 TOO_LARGE.
5fn gh_pow v ulong to bool
6ret or eq v 1 or eq v 2 eq v 4
7end
8fn gh_esz t ulong to ulong
9if eq t 1
10ret 1
11end
12if eq t 3
13ret 4
14end
15ret 2
16end
17fn gh_step t ulong to ulong
18if eq t 1
19ret 32
20end
21ret 16
22end
23fn gh_round v ulong m ulong to ulong
24ret mul div add v sub m 1 m m
25end
26fn gemm_host_value op ulong a ulong b ulong c ulong d ulong to ulong
27if eq op 0
28ret gh_esz a
29end
30if eq op 1
31ret gh_step a
32end
33if eq op 2
34if le a 3
35ret 1
36end
37ret 0
38end
39if eq op 3
40ret and mul 4 add add mul 4 a mul 2 b mul a b 4294967295
41end
42if eq op 4
43ret and add a 255 18446744073709551360
44end
45if eq op 5
46if and ne a 0 ge b c
47ret 1
48end
49ret 0
50end
51if eq op 6
52if and eq a 1 and eq b 48 eq c 0
53ret 0
54end
55ret 1
56end
57ret d
58end
59fn gemm_host_cfg x view ulong 32 to ulong
60if gt get x 0 3
61ret 0
62end
63for i ulong 4
64if not gh_pow get x add i 1
65ret 0
66end
67end
68if or lt get x 5 1 gt get x 5 15
69ret 0
70end
71if gt get x 6 3
72ret 0
73end
74b = get x 7
75if or gt b 32 ne and b sub b 1 0
76ret 0
77end
78ret 1
79end
80fn gh_pack groups ulong ks2 ulong frag ulong to ulong
81ret mul mul add mul groups ks2 2 frag 512
82end
83fn gemm_host_plan x view ulong 32 p edit ulong 64 to ulong
84if eq gemm_host_cfg x 0
85ret 1
86end
87for i ulong 3
88if eq get x add i 8 0
89ret 1
90end
91end
92for i ulong 3
93if gt get x add i 8 16384
94ret 2
95end
96end
97for i ulong 64
98put p i 0
99end
100ks = gh_step get x 0
101hga = mul 16 get x 1
102hgb = mul 8 get x 2
103put p 0 gh_round get x 8 mul hga get x 3
104put p 1 gh_round get x 9 mul hgb get x 4
105put p 2 gh_round get x 10 mul 4 ks
106put p 3 div get p 2 mul 2 ks
107put p 4 mul mul get x 8 get x 10 gh_esz get x 0
108put p 5 mul mul get x 10 get x 9 gh_esz get x 0
109put p 6 gh_pack div get p 0 hga get p 3 mul 2 get x 1
110put p 7 gh_pack div get p 1 hgb get p 3 get x 2
111put p 8 get p 3
112put p 9 div get p 0 hga
113put p 10 get p 3
114put p 11 div get p 1 hgb
115put p 12 div get p 1 mul hgb get x 4
116put p 13 div get p 0 mul hga get x 3
117if gt get x 7 1
118gx = get p 12
119gy = get p 13
120band = get x 7
121put p 12 mul band gy
122put p 13 div add gx sub band 1 band
123end
124put p 14 128
125put p 15 128
126put p 16 mul mul 32 get x 3 get x 4
127if eq get x 0 3
128put p 6 0
129put p 7 0
130for i ulong 9
131put p add 8 i 0
132end
133put p 12 div add get x 9 127 128
134put p 13 get x 8
135put p 16 128
136end
137ret 0
138end
139note Stored spans use 64-bit arithmetic exactly as C; outer,inner,ld originate from u32.
140fn gh_span col ulong rows ulong kk ulong ld ulong to ulong
141ou = rows
142iu = kk
143if ne col 0
144ou = kk
145iu = rows
146end
147if eq ld 0
148ld = iu
149end
150if or lt ld iu gt ld 4294967295
151ret 0
152end
153sp = add mul sub ou 1 ld iu
154if gt sp 4294967295
155ret 0
156end
157ret sp
158end
159fn gemm_host_span x view ulong 32 p edit ulong 64 to ulong
160if gt get x 11 3
161ret 1
162end
163for i ulong 3
164if eq get x add i 8 0
165ret 1
166end
167end
168sa = gh_span and get x 11 1 get x 8 get x 10 get x 12
169sb = gh_span and xor get x 11 2 2 get x 9 get x 10 get x 13
170if or eq sa 0 eq sb 0
171ret 1
172end
173put p 17 sa
174put p 18 sb
175put p 19 get x 12
176if eq get x 12 0
177put p 19 get x 10
178if ne and get x 11 1 0
179put p 19 get x 8
180end
181end
182put p 20 get x 13
183if eq get x 13 0
184put p 20 get x 9
185if ne and get x 11 2 0
186put p 20 get x 10
187end
188end
189ret 0
190end
191fn gh_put64 p edit ulong 64 w ulong v ulong to void
192put p w and v 4294967295
193put p add w 1 shr v 32
194end
195fn gemm_host_drive x view ulong 32 p edit ulong 64 to ulong
196if gt get x 11 3
197ret 1
198end
199rc = gemm_host_plan x p
200if ne rc 0
201ret rc
202end
203rc = gemm_host_span x p
204if ne rc 0
205ret rc
206end
207if eq get x 0 3
208if ne get x 11 0
209ret 1
210end
211if ne get p 19 get x 10
212ret 1
213end
214if ne get p 20 get x 9
215ret 1
216end
217put p 54 2
218gh_put64 p 44 get x 14
219gh_put64 p 46 get x 15
220gh_put64 p 48 get x 18
221put p 50 get x 8
222put p 51 get x 9
223put p 52 get x 10
224ret 0
225end
226gh_put64 p 24 get x 14
227gh_put64 p 26 get x 16
228put p 28 get x 8
229put p 29 get x 10
230put p 30 get p 19
231put p 31 1
232if ne and get x 11 1 0
233put p 30 1
234put p 31 get p 19
235end
236put p 32 get p 3
237gh_put64 p 34 get x 15
238gh_put64 p 36 get x 17
239put p 38 get x 9
240put p 39 get x 10
241put p 40 1
242put p 41 get p 20
243if ne and get x 11 2 0
244put p 40 get p 20
245put p 41 1
246end
247put p 42 get p 3
248gh_put64 p 44 get x 16
249gh_put64 p 46 get x 17
250gh_put64 p 48 get x 18
251put p 50 get x 8
252put p 51 get x 9
253put p 52 get p 3
254put p 53 div get p 1 mul mul 8 get x 2 get x 4
255ret 0
256end