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 / tools / ampfam.om

481 lines · 10217 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note ampfam: the plan, control and verdicts of tools/ampere_families.c (SM86 producer coverage of the
3note existing Blackwell generator families). The C shell calls one generator, the SM121 encoder or the
4note SM86 encoder when this unit asks for it and prints the text it returns; this unit owns the order of
5note the 133 producer steps, each generator's specification, which steps must encode and which must be
6note refused, the short-circuit of a failing step and the message with the oracle's source line.
7note facts f (ulong 32), the C header constants: 0 OMEGA_PATTN_MODE_FUSED, 1 _ATTEND, 2 _APPEND,
8note 3 OMEGA_TC2_EPI_F32, 4 OMEGA_TC2_EPI_SWIGLU, 5 OMEGA_DEC_AXPY, 6 OMEGA_DEC_XBOUND, 7 OMEGA_DEC_RES,
9note 8 OMEGA_DEC_GATHER, 9 OMEGA_DEC_RES_ADD | OMEGA_DEC_RES_NORM, 10 OMEGA_QG_IN_F32, 11 OMEGA_QG_IN_BF16,
10note 12 OMEGA_GDN_COPY, 13 OMEGA_GDN_ZERO, 14 OMEGA_TERN_LAYOUT_ROWMAJOR, 15 OMEGA_TERN_LAYOUT_BLOCK,
11note 16 OMEGA_TERN_MAX_K, 17 OMEGA_TERN_CHUNK_MAX, 18 OMEGA_TERN_EPI_F32.
12note state s (ulong 64, all 0 at the start): 0 step, 1 phase, 2 rc of the last call (int64 bits, written by
13note the shell), 3 SM121 length a, 4 SM86 length b (written by the shell), 5 expectation (0 encode,
14note 1 refuse), 6 source line, 9 generator id, 10 initial SM86 length, 16..23 the generator fields.
15note Returns 1 (call generator s 9 with s 16..23), 2 (SM121 encoder, a = 0), 3 (SM86 encoder, b = s 10),
16note 4 + 256 * length (print o 0 to stderr, exit 1), 5 + 256 * length (print o 0 to stdout, exit 0),
17note 0 (abort: called again after the end).
18const AFPLAN ulong 1048576
19const AFSKIP ulong 1048577
20const AFEND ulong 1048578
21fn af_s o edit uchar 128 p ulong w ulong n ulong to ulong
22i = ulong 0
23while lt i n bound 9
24put o add p i uchar and shr w mul i 8 255
25i = add i 1
26end
27ret add p n
28end
29fn af_nd v ulong to ulong
30n = ulong 1
31x = div v 10
32while ne x 0 bound 20
33n = add n 1
34x = div x 10
35end
36ret n
37end
38fn af_u o edit uchar 128 p ulong v ulong to ulong
39w = af_nd v
40k = add p w
41x = v
42for i ulong w
43k = sub k 1
44put o k uchar add 48 rem x 10
45x = div x 10
46end
47ret add p w
48end
49note af_cnt: passes of `for (v = lo; v <= hi; ++v)`.
50fn af_cnt lo ulong hi ulong to ulong
51if lt hi lo
52ret ulong 0
53end
54ret add sub hi lo 1
55end
56note af_set: generator g, expectation ex, line ln, fields cleared (a C designated initializer).
57fn af_set s edit ulong 64 g ulong ex ulong ln ulong to ulong
58put s 9 g
59put s 5 ex
60put s 6 ln
61for i ulong 8
62put s add 16 i ulong 0
63end
64ret AFPLAN
65end
66fn af_fl s edit ulong 64 k ulong v ulong to ulong
67put s add 16 k v
68ret AFPLAN
69end
70fn af_f4 s edit ulong 64 a ulong b ulong c ulong d ulong to ulong
71x = af_fl s 0 a
72x = af_fl s 1 b
73x = af_fl s 2 c
74ret af_fl s 3 d
75end
76note af_sa: decode_attn depth 1..4 (line 44); prefill_attn FUSED..ATTEND, APPEND encodes (50), the
77note others are refused (51).
78fn af_sa s edit ulong 64 f view ulong 32 i ulong to ulong
79x = ulong 0
80if lt i 4
81x = af_set s 1 0 44
82ret af_fl s 0 add i 1
83end
84i = sub i 4
85n = af_cnt get f 0 get f 1
86if lt i n
87m = add get f 0 i
88if eq m get f 2
89x = af_set s 2 0 50
90x = af_fl s 2 1
91else
92x = af_set s 2 1 51
93end
94x = af_fl s 0 4
95ret af_fl s 1 m
96end
97ret sub i n
98end
99note af_sb: the fixed bf16, fp8 GEMV/GEMM and router steps (lines 54..68).
100fn af_sb s edit ulong 64 i ulong to ulong
101x = ulong 0
102if lt i 3
103x = af_set s 3 0 54
104x = af_f4 s 256 1 4 1
105if eq i 1
106x = af_set s 3 0 55
107x = af_f4 s 256 1 4 1
108x = af_fl s 4 1
109end
110if eq i 2
111x = af_set s 3 0 57
112x = af_f4 s 256 1 4 1
113x = af_fl s 5 256
114x = af_fl s 6 2
115end
116ret AFPLAN
117end
118if lt i 6
119x = af_set s 4 0 59
120if eq i 4
121x = af_set s 4 0 60
122x = af_fl s 4 1
123end
124if eq i 5
125x = af_set s 5 0 61
126x = af_fl s 4 1
127end
128ret af_f4 s 256 8 1 8
129end
130if lt i 8
131x = af_set s 6 0 63
132if eq i 7
133x = af_set s 6 0 64
134x = af_fl s 4 1
135end
136ret af_f4 s 256 8 2 8
137end
138if lt i 10
139x = af_set s 7 0 66
140if eq i 9
141x = af_set s 7 0 68
142x = af_fl s 2 256
143x = af_fl s 3 1
144end
145x = af_fl s 0 8
146ret af_fl s 1 1
147end
148ret sub i 10
149end
150note af_sc: pf_copy, rl, mc and the tensor-core probe, peak, bandwidth and GEMM steps (lines 69..78).
151fn af_sc s edit ulong 64 i ulong to ulong
152x = ulong 0
153if eq i 0
154ret af_set s 8 0 69
155end
156if eq i 1
157x = af_set s 9 0 71
158x = af_fl s 0 128
159x = af_fl s 1 32
160ret af_fl s 2 1
161end
162if eq i 2
163x = af_set s 10 0 73
164x = af_fl s 0 128
165ret af_fl s 1 4
166end
167if eq i 3
168ret af_set s 11 0 74
169end
170if eq i 4
171x = af_set s 12 0 75
172ret af_f4 s 2 2 8 128
173end
174if eq i 5
175x = af_set s 13 0 76
176x = af_fl s 0 2
177x = af_fl s 1 1
178ret af_fl s 2 128
179end
180if eq i 6
181x = af_set s 14 0 78
182ret af_f4 s 128 2 2 4
183end
184ret sub i 7
185end
186note af_sd: tc2 epi F32..SWIGLU by direct 0..1 (F32 encodes, line 83; the others are refused, 84);
187note dec kinds AXPY..XBOUND (line 91).
188fn af_sd s edit ulong 64 f view ulong 32 i ulong to ulong
189x = ulong 0
190n = mul af_cnt get f 3 get f 4 2
191if lt i n
192e = add get f 3 div i 2
193if eq e get f 3
194x = af_set s 15 0 83
195else
196x = af_set s 15 1 84
197end
198x = af_f4 s 128 2 2 4
199x = af_fl s 4 2
200x = af_fl s 5 e
201x = af_fl s 6 rem i 2
202ret af_fl s 7 256
203end
204i = sub i n
205n = af_cnt get f 5 get f 6
206if lt i n
207k = add get f 5 i
208x = af_set s 16 0 91
209x = af_fl s 0 k
210if eq k get f 5
211x = af_fl s 1 256
212end
213if eq k get f 7
214x = af_fl s 2 get f 9
215end
216if eq k get f 8
217x = af_fl s 3 256
218x = af_fl s 1 256
219end
220ret AFPLAN
221end
222ret sub i n
223end
224note af_se: pq in_type F32..BF16 (95), qgemm (98), qmma probe (99), qmma peak (100), f2e4 probe (101),
225note all refused.
226fn af_se s edit ulong 64 f view ulong 32 i ulong to ulong
227x = ulong 0
228n = af_cnt get f 10 get f 11
229if lt i n
230x = af_set s 17 1 95
231x = af_fl s 0 128
232ret af_fl s 1 add get f 10 i
233end
234i = sub i n
235if eq i 0
236x = af_set s 18 1 98
237ret af_f4 s 128 4 8 128
238end
239if eq i 1
240x = af_set s 19 1 99
241x = af_fl s 0 0
242ret af_fl s 1 8
243end
244if eq i 2
245x = af_set s 20 1 100
246ret af_f4 s 2 2 8 128
247end
248if eq i 3
249ret af_set s 21 1 101
250end
251ret sub i 4
252end
253note af_sf: per shape 0..1, decode_attn256 depth 1..4 by prep by multi (112), then prefill_attn256
254note refused (117); shape 1 is 16 q heads, 2 kv heads, 4 q heads per CTA.
255fn af_sf s edit ulong 64 i ulong to ulong
256x = ulong 0
257if ge i 34
258ret sub i 34
259end
260sh = div i 17
261j = rem i 17
262if lt j 16
263x = af_set s 22 0 112
264x = af_fl s 0 add div j 4 1
265x = af_fl s 1 rem div j 2 2
266x = af_fl s 2 rem j 2
267if eq sh 1
268x = af_fl s 3 16
269x = af_fl s 4 2
270x = af_fl s 5 4
271end
272ret AFPLAN
273end
274x = af_set s 23 1 117
275if eq sh 1
276x = af_fl s 0 16
277x = af_fl s 1 2
278end
279ret AFPLAN
280end
281note af_sg: ratio 2..3 by state_bf16 0..1: gdn (bf16 refused 122, f32 encodes 123), gdn_multi (124),
282note gdn_prep (125), gdn_scan refused (127), gdn_post refused (128); gdn_copy COPY..ZERO (132).
283fn af_sg s edit ulong 64 f view ulong 32 i ulong to ulong
284x = ulong 0
285if lt i 20
286c = div i 5
287k = rem i 5
288bf = rem c 2
289if eq k 0
290if eq bf 1
291x = af_set s 24 1 122
292else
293x = af_set s 24 0 123
294end
295end
296if eq k 1
297x = af_set s 25 0 124
298end
299if eq k 2
300x = af_set s 26 0 125
301end
302if eq k 3
303x = af_set s 27 1 127
304end
305if eq k 4
306x = af_set s 28 1 128
307end
308x = af_fl s 0 add 2 div c 2
309ret af_fl s 1 bf
310end
311i = sub i 20
312n = af_cnt get f 12 get f 13
313if lt i n
314x = af_set s 29 0 132
315ret af_fl s 0 add get f 12 i
316end
317ret sub i n
318end
319note af_sh: ternary GEMV, k of 256, 2560, 8192, OMEGA_TERN_MAX_K by the five layouts by epilogue 0..1
320note (144); a k above OMEGA_TERN_CHUNK_MAX with the f32 epilogue is skipped.
321fn af_sh s edit ulong 64 f view ulong 32 i ulong to ulong
322x = ulong 0
323if ge i 40
324ret sub i 40
325end
326ki = div i 10
327sh = rem div i 2 5
328e = rem i 2
329k = get f 16
330if eq ki 0
331k = ulong 256
332end
333if eq ki 1
334k = ulong 2560
335end
336if eq ki 2
337k = ulong 8192
338end
339if and gt k get f 17 eq e get f 18
340ret AFSKIP
341end
342x = af_set s 30 0 144
343lay = get f 14
344r = shl ulong 1 sh
345if gt sh 2
346lay = get f 15
347r = shl ulong 1 sub sh 2
348end
349x = af_f4 s k lay r 4
350x = af_fl s 4 1
351ret af_fl s 5 e
352end
353note af_plan: plans step i; AFPLAN, AFSKIP, or AFEND past the last step.
354fn af_plan s edit ulong 64 f view ulong 32 i ulong to ulong
355i = af_sa s f i
356if ge i AFPLAN
357ret i
358end
359i = af_sb s i
360if ge i AFPLAN
361ret i
362end
363i = af_sc s i
364if ge i AFPLAN
365ret i
366end
367i = af_sd s f i
368if ge i AFPLAN
369ret i
370end
371i = af_se s f i
372if ge i AFPLAN
373ret i
374end
375i = af_sf s i
376if ge i AFPLAN
377ret i
378end
379i = af_sg s f i
380if ge i AFPLAN
381ret i
382end
383i = af_sh s f i
384if ge i AFPLAN
385ret i
386end
387ret AFEND
388end
389note af_bad: the verdict of the SM86 call: encode needs rc 0 and b == a, refuse needs rc -2 and b == 0.
390fn af_bad s view ulong 64 to ulong
391rc = get s 2
392if eq get s 5 0
393if or ne rc 0 ne get s 3 get s 4
394ret ulong 1
395end
396ret ulong 0
397end
398if or ne rc sub ulong 0 2 ne get s 4 0
399ret ulong 1
400end
401ret ulong 0
402end
403note af_fail: "Ampere family producer failed at line %d\n" or "Ampere unsupported family accepted at
404note line %d\n".
405fn af_fail s edit ulong 64 o edit uchar 128 to ulong
406put s 1 4
407p = ulong 0
408if eq get s 5 0
409note s "Ampere family producer failed at line "
410p = af_s o p 7358993333125934401 8
411p = af_s o p 8246126623597358433 8
412p = af_s o p 7359007570909291631 8
413p = af_s o p 8386019596710996321 8
414p = af_s o p 35620016188448 6
415else
416note s "Ampere unsupported family accepted at line "
417p = af_s o p 8439857243694853441 8
418p = af_s o p 8390891584458421102 8
419p = af_s o p 7811895293743490149 8
420p = af_s o p 8390317583334711417 8
421p = af_s o p 7596482355684992101 8
422p = af_s o p 2123118 3
423end
424p = af_u o p get s 6
425put o p uchar 10
426ret add 4 shl add p 1 8
427end
428fn af_done s edit ulong 64 o edit uchar 128 to ulong
429put s 1 5
430p = ulong 0
431note s "Ampere extended existing generator families encoded (host only)\n"
432p = af_s o p 7286935739088006465 8
433p = af_s o p 2334101988908037240 8
434p = af_s o p 7453010382218164325 8
435p = af_s o p 8386109761109976864 8
436p = af_s o p 7811895293743493743 8
437p = af_s o p 8026380341519541609 8
438p = af_s o p 8317981558328026468 8
439p = af_s o p 732249921040621684 8
440ret add 5 shl p 8
441end
442fn ampfam f view ulong 32 s edit ulong 64 o edit uchar 128 to ulong
443ph = get s 1
444rc = get s 2
445if gt ph 3
446ret ulong 0
447end
448if eq ph 1
449if ne rc 0
450ret af_fail s o
451end
452put s 1 2
453ret ulong 2
454end
455if eq ph 2
456if ne rc 0
457ret af_fail s o
458end
459put s 1 3
460put s 10 get s 5
461ret ulong 3
462end
463if eq ph 3
464if ne af_bad s 0
465ret af_fail s o
466end
467put s 0 add get s 0 1
468end
469for t ulong 64
470r = af_plan s f get s 0
471if eq r AFPLAN
472put s 1 1
473ret ulong 1
474end
475if ne r AFSKIP
476ret af_done s o
477end
478put s 0 add get s 0 1
479end
480ret ulong 0
481end