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 / tests / models / quant-caller.om

514 lines · 7444 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Concatenate quant.om and existing fp8/mxfp4/nvfp4 models before this caller.
3fn qt_base d edit ulong 48 fmt ulong cols ulong to void
4for i ulong 48
5put d i 0
6end
7put d 0 1
8put d 1 fmt
9put d 2 8
10put d 11 1
11put d 13 1
12put d 14 8
13put d 15 1
14put d 17 1
15put d 18 cols
16put d 19 2
17put d 24 1
18put d 25 cols
19put d 27 1
20put d 30 cols
21put d 33 cols
22put d 36 cols
23put d 41 cols
24if ge fmt 4
25put d 24 2
26put d 4 2
27put d 5 1
28put d 6 32
29if eq fmt 5
30put d 4 3
31put d 6 16
32end
33if lt fmt 6
34put d 2 4
35put d 14 4
36end
37put d 25 quant_ceil cols div ulong 8 get d 2
38put d 30 get d 25
39put d 26 quant_ceil cols get d 6
40put d 31 get d 26
41put d 32 1
42put d 41 mul quant_ceil cols get d 6 get d 6
43put d 33 quant_ceil get d 41 div ulong 8 get d 2
44put d 36 get d 33
45put d 34 get d 26
46put d 35 get d 4
47put d 37 get d 31
48end
49end
50fn qt_wire to uint
51d = new ulong 48 0
52p = new ulong 48 0
53wire = new uchar 384 0
54other = new uchar 384 0
55qt_base d 4 3
56if ne quant_write d wire 0
57ret 1
58end
59if ne quant_read wire p 0
60ret 2
61end
62for i ulong 48
63if ne get p i get d i
64ret 3
65end
66end
67if ne quant_write p other 0
68ret 4
69end
70if ne quant_hash wire quant_hash other
71ret 5
72end
73put p 28 1
74if ne quant_write p other 0
75ret 6
76end
77if ne quant_shash wire quant_shash other
78ret 7
79end
80if eq quant_hash wire quant_hash other
81ret 8
82end
83ret 0
84end
85fn qt_nib src view uchar 65536 i ulong to uint
86v = uint get src div i 2
87ret and shr v uint mul rem i 2 4 15
88end
89fn qt_numer src view uchar 65536 sc view uchar 1024 dst view uchar 65536 ds view uchar 1024 fmt ulong cols ulong to uint
90block = ulong 32
91if eq fmt 5
92block = 16
93end
94for i ulong cols
95a = uint get src i
96b = uint get dst i
97if eq fmt 6
98a = e4m3bits a
99b = e4m3bits b
100else
101a = qt_nib src i
102b = qt_nib dst i
103if eq fmt 4
104a = mxfp4bits a uint get sc div i block
105b = mxfp4bits b uint get ds div i block
106else
107a = nvfp4bits a uint get sc div i block
108b = nvfp4bits b uint get ds div i block
109end
110end
111if ne a b
112ret 1
113end
114end
115ret 0
116end
117fn qt_blocks fmt ulong cols ulong to uint
118d = new ulong 48 0
119src = new uchar 65536 0
120sc = new uchar 1024 0
121dst = new uchar 65536 255
122ds = new uchar 1024 255
123qt_base d fmt cols
124for i ulong get d 30
125put src i uchar and i 255
126end
127if eq get d 2 4
128if ne rem cols 2 0
129pos = div cols 2
130put src pos and get src pos 15
131end
132end
133for i ulong get d 31
134put sc i 127
135if eq fmt 5
136put sc i 56
137end
138end
139if eq fmt 6
140for i ulong cols
141if eq and get src i 127 127
142put src i 0
143end
144end
145end
146if ne quant_repack d src sc dst ds 0
147ret 6
148end
149for i ulong get d 30
150if ne get src i get dst i
151ret 7
152end
153end
154for i ulong get d 36
155if ge i get d 30
156if ne get dst i 0
157ret 8
158end
159end
160end
161for i ulong get d 31
162if ne get sc i get ds i
163ret 9
164end
165end
166note Independently implemented source numeric decoder consumes actual packed output.
167if ne qt_numer src sc dst ds fmt cols 0
168ret 10
169end
170ret 0
171end
172fn qt_fp8 fmt ulong to uint
173d = new ulong 48 0
174src = new uchar 65536 0
175sc = new uchar 1024 0
176dst = new uchar 65536 255
177ds = new uchar 1024 255
178qt_base d fmt 256
179put d 12 1
180for i ulong 256
181put src i uchar i
182end
183if ne quant_repack d src sc dst ds 0
184ret 1
185end
186for i ulong 256
187if ne get src i get dst i
188ret 2
189end
190end
191put d 12 0
192if ne quant_repack d src sc dst ds 5
193ret 3
194end
195for i ulong 256
196if eq fmt 2
197if eq and i 127 127
198put src i 0
199end
200else
201if ge and i 127 124
202put src i 0
203end
204end
205end
206if ne quant_repack d src sc dst ds 0
207ret 4
208end
209ret 0
210end
211fn qt_negative to uint
212d = new ulong 48 0
213src = new uchar 65536 0
214sc = new uchar 1024 0
215dst = new uchar 65536 211
216ds = new uchar 1024 213
217qt_base d 4 3
218put sc 0 255
219if ne quant_repack d src sc dst ds 6
220ret 1
221end
222if or ne get dst 0 211 ne get ds 0 213
223ret 2
224end
225put sc 0 127
226put src 1 240
227if ne quant_repack d src sc dst ds 4
228ret 3
229end
230put src 1 0
231put d 31 0
232if ne quant_check d 3
233ret 4
234end
235put d 31 1
236put d 25 0
237if ne quant_check d 3
238ret 5
239end
240put d 25 2
241put d 27 3
242if ne quant_check d 4
243ret 6
244end
245put d 27 1
246put d 39 1
247if ne quant_check d 1
248ret 7
249end
250put d 39 0
251put d 42 1
252if ne quant_check d 1
253ret 8
254end
255put d 42 0
256put d 17 18446744073709551615
257if ne quant_check d 3
258ret 9
259end
260put d 17 1
261put d 7 1
262if ne quant_check d 7
263ret 10
264end
265put d 7 0
266put d 32 0
267if ne quant_check d 4
268ret 11
269end
270put d 32 1
271put d 41 31
272if ne quant_check d 4
273ret 12
274end
275put d 41 32
276put d 9 2
277if ne quant_check d 1
278ret 13
279end
280put d 9 0
281put d 1 7
282if ne quant_check d 1
283ret 14
284end
285ret 0
286end
287fn qt_ints to uint
288d = new ulong 48 0
289wire = new uchar 384 0
290p = new ulong 48 0
291qt_base d 2 8
292put d 1 1
293put d 3 1
294put d 11 0
295put d 13 0
296for bits ulong 8
297put d 2 add bits 1
298put d 14 add bits 1
299put d 7 1
300put d 8 sub shl ulong 1 add bits 1 1
301if ne quant_sem d 0
302ret 1
303end
304if ne quant_write d wire 0
305ret 2
306end
307if ne quant_read wire p 0
308ret 3
309end
310if ne quant_check p 2
311ret 4
312end
313put d 8 shl ulong 1 add bits 1
314if ne quant_sem d 7
315ret 5
316end
317end
318ret 0
319end
320fn qt_foldcase to uint
321d = new ulong 48 0
322src = new uchar 65536 0
323sc = new uchar 1024 0
324dst = new uchar 65536 255
325ds = new uchar 1024 255
326qt_base d 2 256
327put d 17 128
328put d 4 1
329put d 5 128
330put d 6 128
331put d 24 3
332put d 26 4
333put d 30 mul ulong 128 256
334put d 31 4
335put d 34 8
336put d 35 4
337put d 36 get d 30
338put d 37 8
339put d 40 1
340note BF16 source patterns 0 and sign-bit-only preserve signed zero.
341put sc 3 128
342if ne quant_repack d src sc dst ds 0
343ret 1
344end
345if ne get ds 7 128
346ret 2
347end
348put sc 0 128
349put sc 1 127
350if ne quant_repack d src sc dst ds 6
351ret 3
352end
353put sc 0 0
354put sc 1 128
355if ne quant_repack d src sc dst ds 0
356ret 4
357end
358if ne get ds 3 128
359ret 5
360end
361put sc 0 128
362put sc 1 63
363if ne quant_repack d src sc dst ds 0
364ret 6
365end
366if ne bitcast uint quant_fold sc 0 shl add uint 127 56 23
367ret 7
368end
369ret 0
370end
371fn qt_strides to uint
372d = new ulong 48 0
373src = new uchar 65536 0
374sc = new uchar 1024 0
375dst = new uchar 65536 255
376ds = new uchar 1024 255
377qt_base d 4 3
378put d 17 2
379put d 25 4
380put d 26 2
381put d 27 32
382put d 28 3
383put d 29 2
384put d 30 16
385put d 31 6
386put d 33 32
387put d 34 2
388put d 36 64
389put d 37 4
390put src 3 33
391put src 4 3
392put src 7 67
393put src 8 5
394put sc 2 127
395put sc 4 128
396if ne quant_repack d src sc dst ds 0
397ret 1
398end
399if or ne get dst 0 33 ne get dst 1 3
400ret 2
401end
402if or ne get dst 32 67 ne get dst 33 5
403ret 3
404end
405if or ne get ds 0 127 ne get ds 2 128
406ret 4
407end
408if or ne get ds 1 0 ne get ds 3 0
409ret 5
410end
411for i ulong 64
412if gt rem i 32 1
413if ne get dst i 0
414ret 6
415end
416end
417end
418put d 28 18446744073709551615
419if ne quant_repack d src sc dst ds 3
420ret 7
421end
422ret 0
423end
424fn qt_boundone fmt ulong scale uchar want uint to uint
425d = new ulong 48 0
426src = new uchar 65536 0
427sc = new uchar 1024 0
428dst = new uchar 65536 211
429ds = new uchar 1024 213
430qt_base d fmt 1
431put sc 0 scale
432if ne quant_repack d src sc dst ds want
433ret 1
434end
435if eq want 0
436if ne get ds 0 scale
437ret 2
438end
439else
440if ne get dst 0 211
441ret 3
442end
443if ne get ds 0 213
444ret 3
445end
446end
447ret 0
448end
449fn qt_boundaries to uint
450for f ulong 3
451if ne qt_boundone add f 4 0 0 0
452ret 1
453end
454if ne qt_boundone add f 4 126 0 0
455ret 2
456end
457if ne qt_boundone add f 4 255 6 0
458ret 3
459end
460if eq f 1
461if ne qt_boundone 5 127 6 0
462ret 4
463end
464if ne qt_boundone 5 254 6 0
465ret 5
466end
467else
468if ne qt_boundone add f 4 127 0 0
469ret 6
470end
471if ne qt_boundone add f 4 254 0 0
472ret 7
473end
474end
475end
476ret 0
477end
478fn main to int
479if ne qt_wire 0
480ret 7
481end
482for fmt ulong 3
483for k ulong 65
484if ne qt_blocks add fmt 4 add k 1 0
485ret 1
486end
487end
488end
489if ne qt_fp8 2 0
490ret 2
491end
492if ne qt_fp8 3 0
493ret 3
494end
495if ne qt_negative 0
496ret 4
497end
498if ne qt_ints 0
499ret 5
500end
501if ne qt_foldcase 0
502ret 6
503end
504if ne qt_consumer 0
505ret 8
506end
507if ne qt_strides 0
508ret 9
509end
510if ne qt_boundaries 0
511ret 10
512end
513ret 0
514end