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

486 lines · 8082 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note QuantSchema v1. Canonical metadata, not tensor content authentication or GPU admission.
3note Numerical sources native/models and omega_gpu_fp8_pack.c at b759afc3.
4note All unsigned extent arithmetic is guarded before multiplication or indexing.
5fn quant_sem d view ulong 48 to uint
6if ne get d 0 1
7ret 1
8end
9fmt = get d 1
10if or lt fmt 1 gt fmt 6
11ret 1
12end
13if or eq get d 17 0 eq get d 18 0
14ret 3
15end
16if gt get d 17 div ulong 18446744073709551615 get d 18
17ret 3
18end
19if or ne get d 19 2 ne get d 15 1
20ret 1
21end
22if or ne get d 14 get d 2 ne get d 16 0
23ret 1
24end
25for i ulong 4
26if ne get d add i 20 0
27ret 1
28end
29end
30if or gt get d 9 1 gt get d 10 1
31ret 1
32end
33if gt get d 4 4
34ret 1
35end
36if eq get d 7 0
37if ne get d 8 0
38ret 7
39end
40else
41if ne get d 7 1
42ret 7
43end
44end
45if eq get d 4 0
46if or ne get d 5 0 ne get d 6 0
47ret 1
48end
49else
50if or eq get d 5 0 eq get d 6 0
51ret 1
52end
53end
54if eq fmt 1
55if or lt get d 2 1 gt get d 2 8
56ret 1
57end
58if or lt get d 3 1 gt get d 3 2
59ret 1
60end
61if or ne get d 11 0 ne get d 13 0
62ret 1
63end
64if ne get d 12 0
65ret 1
66end
67if eq get d 7 1
68if ne get d 3 1
69ret 7
70end
71if ge get d 8 shl ulong 1 get d 2
72ret 7
73end
74end
75ret 0
76end
77if or ne get d 3 0 ne get d 7 0
78ret 7
79end
80if or ne get d 11 1 ne get d 13 1
81ret 1
82end
83if gt get d 12 1
84ret 1
85end
86if or eq fmt 4 eq fmt 5
87if ne get d 2 4
88ret 1
89end
90else
91if ne get d 2 8
92ret 1
93end
94end
95if ge fmt 4
96if ne get d 12 0
97ret 1
98end
99if ne get d 5 1
100ret 1
101end
102if eq fmt 5
103if or ne get d 4 3 ne get d 6 16
104ret 1
105end
106else
107if or ne get d 4 2 ne get d 6 32
108ret 1
109end
110end
111end
112ret 0
113end
114fn quant_meta d view ulong 48 to uint
115r = quant_sem d
116if ne r 0
117ret r
118end
119if or lt get d 24 1 gt get d 24 3
120ret 1
121end
122if or ne get d 38 0 ne get d 39 0
123ret 1
124end
125if or gt get d 32 1 gt get d 40 1
126ret 1
127end
128if gt get d 35 4
129ret 1
130end
131for i ulong 6
132if ne get d add i 42 0
133ret 1
134end
135end
136a = get d 27
137if or eq a 0 gt a 4096
138ret 4
139end
140if ne and a sub a 1 0
141ret 4
142end
143if or gt get d 30 65536 gt get d 36 65536
144ret 3
145end
146if or gt get d 31 1024 gt get d 37 1024
147ret 3
148end
149ret 0
150end
151fn quant_ceil a ulong b ulong to ulong
152if eq rem a b 0
153ret div a b
154end
155ret add div a b 1
156end
157fn quant_size typ ulong to ulong
158if eq typ 0
159ret 0
160end
161if eq typ 1
162ret 2
163end
164if eq typ 4
165ret 4
166end
167ret 1
168end
169fn quant_span rows ulong stride ulong width ulong off ulong avail ulong to bool
170if gt off avail
171ret false
172end
173if lt stride width
174ret false
175end
176room = sub avail off
177if gt width room
178ret false
179end
180if eq rows 0
181ret false
182end
183if eq stride 0
184ret false
185end
186ret le sub rows 1 div sub room width stride
187end
188fn quant_layout d view ulong 48 to uint
189fmt = get d 1
190lay = get d 24
191if eq fmt 1
192ret 2
193end
194if eq lay 1
195if or gt fmt 3 ne get d 4 0
196ret 2
197end
198if or ne get d 35 0 ne get d 40 0
199ret 2
200end
201if or ne get d 32 0 ne get d 41 get d 18
202ret 4
203end
204ret 0
205end
206if eq lay 2
207if lt fmt 4
208ret 2
209end
210if or ne get d 35 get d 4 ne get d 40 0
211ret 2
212end
213if eq get d 32 0
214if ne rem get d 18 get d 6 0
215ret 4
216end
217end
218if ne get d 41 mul quant_ceil get d 18 get d 6 get d 6
219ret 4
220end
221ret 0
222end
223if ne fmt 2
224ret 2
225end
226if or ne get d 4 1 ne get d 35 4
227ret 2
228end
229if or ne get d 5 128 ne get d 6 128
230ret 2
231end
232if or ne get d 40 1 ne get d 12 0
233ret 2
234end
235if or ne rem get d 17 128 0 ne rem get d 18 128 0
236ret 4
237end
238if or ne get d 32 0 ne get d 41 get d 18
239ret 4
240end
241ret 0
242end
243fn quant_extents d view ulong 48 to uint
244rows = get d 17
245cols = get d 18
246if or gt rows 65536 gt cols 65536
247ret 3
248end
249if gt get d 41 65536
250ret 3
251end
252unit = div ulong 8 get d 2
253width = quant_ceil cols unit
254if not quant_span rows get d 25 width get d 28 get d 30
255ret 3
256end
257outw = quant_ceil get d 41 unit
258if not quant_span rows get d 33 outw 0 get d 36
259ret 3
260end
261if ne rem get d 33 get d 27 0
262ret 4
263end
264if gt rows div ulong 65536 get d 33
265ret 3
266end
267if ne get d 36 mul rows get d 33
268ret 3
269end
270if eq get d 4 0
271if or ne get d 26 0 ne get d 34 0
272ret 4
273end
274if or ne get d 29 0 ne get d 31 0
275ret 4
276end
277if ne get d 37 0
278ret 4
279end
280ret 0
281end
282srows = quant_ceil rows get d 5
283scount = quant_ceil cols get d 6
284if not quant_span srows get d 26 mul scount quant_size get d 4 get d 29 get d 31
285ret 3
286end
287if not quant_span srows get d 34 mul scount quant_size get d 35 0 get d 37
288ret 3
289end
290if gt srows div ulong 1024 get d 34
291ret 3
292end
293if ne get d 37 mul srows get d 34
294ret 3
295end
296ret 0
297end
298fn quant_check d view ulong 48 to uint
299r = quant_meta d
300if ne r 0
301ret r
302end
303note Bound dimensions before computing padded extents in layout validation.
304if or gt get d 17 65536 gt get d 18 65536
305ret 3
306end
307r = quant_layout d
308if ne r 0
309ret r
310end
311ret quant_extents d
312end
313fn quant_write d view ulong 48 b edit uchar 384 to uint
314r = quant_meta d
315if ne r 0
316ret r
317end
318for i ulong 48
319v = get d i
320for j ulong 8
321put b add mul i 8 j uchar and shr v mul j 8 255
322end
323end
324ret 0
325end
326fn quant_read b view uchar 384 d edit ulong 48 to uint
327for i ulong 48
328v = ulong 0
329for j ulong 8
330v = or v shl ulong get b add mul i 8 j mul j 8
331end
332put d i v
333end
334ret quant_meta d
335end
336note WolframLanguageEvaluator {FromDigits["cbf29ce484222325",16],FromDigits["100000001b3",16]}
337note -> {14695981039346656037,1099511628211}; parent mounted tool 2026-10-28.
338note FNV is indexing only, never authentication or a substitute for content SHA.
339fn quant_hash b view uchar 384 to ulong
340h = ulong 14695981039346656037
341for i ulong 384
342h = mul xor h ulong get b i 1099511628211
343end
344ret h
345end
346fn quant_shash b view uchar 384 to ulong
347h = ulong 14695981039346656037
348for i ulong 192
349h = mul xor h ulong get b i 1099511628211
350end
351ret h
352end
353fn quant_fold sc view uchar 1024 pos ulong to f32
354u = or uint get sc pos shl uint get sc add pos 1 8
355s = bitcast f32 shl u 16
356ret mul s bitcast f32 shl add uint 127 56 23
357end
358fn quant_scpos d view ulong 48 row ulong col ulong to ulong
359base = add get d 29 mul row get d 26
360ret add base mul col quant_size get d 4
361end
362fn quant_svalid sc view uchar 1024 p ulong typ ulong to uint
363u = uint get sc p
364if eq typ 2
365if eq u 255
366ret 6
367end
368end
369if eq typ 3
370if gt u 126
371ret 6
372end
373end
374if eq typ 1
375u = or u shl uint get sc add p 1 8
376s = bitcast f32 shl u 16
377if not le fabs s 3.0e38f32
378ret 6
379end
380if not le fabs quant_fold sc p 3.0e38f32
381ret 6
382end
383end
384ret 0
385end
386fn quant_scales d view ulong 48 sc view uchar 1024 to uint
387if eq get d 4 0
388ret 0
389end
390rows = quant_ceil get d 17 get d 5
391cols = quant_ceil get d 18 get d 6
392for i ulong mul rows cols
393p = quant_scpos d div i cols rem i cols
394r = quant_svalid sc p get d 4
395if ne r 0
396ret r
397end
398end
399ret 0
400end
401fn quant_weights d view ulong 48 src view uchar 65536 to uint
402rows = get d 17
403cols = get d 18
404for r ulong rows
405base = add get d 28 mul r get d 25
406if eq get d 2 4
407if ne rem cols 2 0
408if ne and get src add base div cols 2 240 0
409ret 4
410end
411end
412continue
413end
414for c ulong cols
415u = uint get src add base c
416if eq get d 12 0
417if eq get d 1 3
418if ge and u 127 124
419ret 5
420end
421else
422if eq and u 127 127
423ret 5
424end
425end
426end
427end
428end
429ret 0
430end
431fn quant_copyw d view ulong 48 src view uchar 65536 dst edit uchar 65536 to void
432for i ulong get d 36
433put dst i 0
434end
435width = quant_ceil get d 18 div ulong 8 get d 2
436for i ulong mul get d 17 width
437ip = add get d 28 mul div i width get d 25
438ip = add ip rem i width
439op = mul div i width get d 33
440op = add op rem i width
441put dst op get src ip
442end
443end
444fn quant_scaleout sc view uchar 1024 ds edit uchar 1024 ip ulong op ulong fold bool to void
445if fold
446v = bitcast uint quant_fold sc ip
447for j ulong 4
448put ds add op j uchar and shr v mul j 8 255
449end
450else
451put ds op get sc ip
452end
453end
454fn quant_copys d view ulong 48 sc view uchar 1024 ds edit uchar 1024 to void
455for i ulong get d 37
456put ds i 0
457end
458if eq get d 4 0
459ret
460end
461rows = quant_ceil get d 17 get d 5
462cols = quant_ceil get d 18 get d 6
463for i ulong mul rows cols
464ip = quant_scpos d div i cols rem i cols
465op = mul div i cols get d 34
466op = add op mul rem i cols quant_size get d 35
467quant_scaleout sc ds ip op eq get d 24 3
468end
469end
470fn quant_repack d view ulong 48 src view uchar 65536 sc view uchar 1024 dst edit uchar 65536 ds edit uchar 1024 to uint
471r = quant_check d
472if ne r 0
473ret r
474end
475r = quant_weights d src
476if ne r 0
477ret r
478end
479r = quant_scales d sc
480if ne r 0
481ret r
482end
483quant_copyw d src dst
484quant_copys d sc ds
485ret 0
486end