interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / nvidia / om / api / apish_shp.om

900 lines · 12539 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Shape, alignment, overflow and refusal decisions for the kernel-family API shells.
3note One ulong result. Multi-field results pack the second field in bits 32..63.
4note op 1 lane bytes, 2 fp8 defaults, 3 register fit, 4 tgemm bm, 5 tgemm spec,
5note 6 tgemm size, 7 tern rows and depth, 8 tern warps and ctas, 9 pad 8,
6note 10 segment bound, 11 segment end, 12 f32 finite, 13 packed bytes, 14 align,
7note 15 tile 8, 16 cta budget, 17 perm4, 18 pf bm, 19 swiglu source, 20 max mkn,
8note 21 decode cache bounds, 22 decode register fit, 23 tern pack args, 24 router rows,
9note 25 router dest, 26 router source, 27 decode splits, 28 power of two, 29 theta.
10note 30 fp8 mt, 31 tc spec, 32 tc warps, 33 round up, 34 window offset, 35 window ok, 36 quant group.
11note 37 qgemm rows, 38 qgemm wait, 39 declared registers at most 128.
12
13fn lane k uint to ulong
14if eq rem k 512 0
15ret ulong 16
16end
17ret ulong 8
18end
19
20fn fp8def mt uint wp uint to ulong
21m = mt
22w = wp
23if eq mt 0
24m = 4
25end
26if eq wp 0
27w = 16
28end
29ret or ulong ulong m shl ulong ulong w 32
30end
31
32fn regfit w uint decl uint to ulong
33p = mul ulong mul ulong 32 ulong w ulong decl
34if le p ulong 65536
35ret ulong 1
36end
37ret ulong 0
38end
39
40fn tgbm rt uint w uint n uint to ulong
41if ne rt 0
42ret mul ulong 16 ulong rt
43end
44ww = w
45if eq w 0
46ww = 16
47if ne rem n 256 0
48ww = 8
49end
50end
51if eq ww 16
52ret ulong 128
53end
54ret ulong 64
55end
56
57fn tgspec rt uint w uint n uint to ulong
58ww = w
59if eq w 0
60ww = 16
61if ne rem n 256 0
62ww = 8
63end
64end
65r = rt
66if eq rt 0
67r = 4
68if eq ww 16
69r = 8
70end
71end
72ret or ulong ulong r shl ulong ulong ww 32
73end
74
75fn tgsz m uint n uint bm uint to ulong
76if or eq m 0 eq bm 0
77ret ulong 1
78end
79if ne rem m bm 0
80ret ulong 1
81end
82if gt div m bm 65535
83ret ulong 2
84end
85if ge mul ulong ulong m ulong n ulong 4294967296
86ret ulong 2
87end
88ret ulong 0
89end
90
91fn take ksc uint r uint d uint best uint lim uint to uint
92if eq d 0
93ret best
94end
95if gt d lim
96ret best
97end
98if ne rem ksc d 0
99ret best
100end
101if gt mul r d 16
102ret best
103end
104if gt d best
105ret d
106end
107ret best
108end
109fn scan ksc uint r uint d0 uint to uint
110best = uint 1
111f = uint 1
112while le mul ulong f ulong f ulong ksc bound 65537
113if eq rem ksc f 0
114q = div ksc f
115best = take ksc r f best d0
116best = take ksc r q best d0
117end
118f = add f 1
119end
120ret best
121end
122fn ctz32 x uint to uint
123if eq x 0
124ret 32
125end
126n = uint 0
127v = x
128while eq and v 1 0 bound 31
129v = shr v 1
130n = add n 1
131end
132ret n
133end
134fn invodd a uint to uint
135x = uint 1
136for i uint 5
137x = mul x sub 2 mul a x
138end
139ret x
140end
141fn largest step uint d0 uint to uint
142if eq step 0
143ret 0
144end
145ret sub d0 rem d0 step
146end
147fn cong0 r uint d0 uint to uint
148inv = invodd r
149best = uint 1
150s = uint 0
151while le s 16 bound 17
152pp = mul s inv
153if and le pp d0 ge pp 2
154if gt pp best
155best = pp
156end
157end
158s = add s 1
159end
160ret best
161end
162fn candhi sg uint inv uint mod uint d0 uint to uint
163pp = and mul sg inv sub mod 1
164if gt pp d0
165ret 0
166end
167ret add pp mul div sub d0 pp mod mod
168end
169fn conghi r uint d0 uint v uint to uint
170g = shl 1 v
171inv = invodd shr r v
172mod = shl 1 sub 32 v
173best = uint 1
174s = uint 0
175while le s 16 bound 17
176if eq rem s g 0
177c = candhi div s g inv mod d0
178if and ge c 2 gt c best
179best = c
180end
181end
182s = add s g
183end
184ret best
185end
186fn cong r uint d0 uint to uint
187v = ctz32 r
188if ge v 5
189d = largest shl 1 sub 32 v d0
190if ge d 2
191ret d
192end
193ret 1
194end
195if eq v 0
196ret cong0 r d0
197end
198ret conghi r d0 v
199end
200fn tdepth ksc uint r uint d0 uint to uint
201d = d0
202while gt d 1 bound 65537
203if eq rem ksc d 0
204if le mul r d 16
205ret d
206end
207end
208d = sub d 1
209end
210ret d
211end
212
213fn ternd k uint lay uint R uint gr uint gd uint to ulong
214nch = div add k 8191 8192
215ksc = uint 0
216if ne nch 0
217ksc = div div k nch 256
218end
219r = gr
220if eq lay 1
221r = R
222end
223if and eq lay 0 eq r 0
224r = 1
225end
226d0 = gd
227if and eq gd 0 ne r 0
228d0 = div 16 r
229end
230d0 = tdepth ksc r d0
231ret or ulong ulong r shl ulong ulong d0 32
232end
233
234fn ternwc w uint ct uint to ulong
235ww = w
236cc = ct
237if eq w 0
238ww = 8
239end
240if eq ct 0
241cc = 160
242end
243ret or ulong ulong ww shl ulong ulong cc 32
244end
245
246fn pad8 n uint to ulong
247ret ulong mul div add n 7 8 8
248end
249
250fn segb i uint cnt uint n uint en uint mu uint to ulong
251if ge add i 1 cnt
252ret ulong n
253end
254if eq mu 2
255if eq cnt 0
256ret ulong 0
257end
258ret ulong mul add i 1 div n cnt
259end
260ret ulong en
261end
262
263fn segend i uint cnt uint n uint en uint pv uint to ulong
264if or eq cnt 0 gt cnt 4
265ret ulong 1
266end
267if eq en 0
268ret ulong 1
269end
270if and ne i 0 le en pv
271ret ulong 1
272end
273if and eq add i 1 cnt ne en n
274ret ulong 1
275end
276ret ulong 0
277end
278
279fn finite u uint to ulong
280if eq and shr u 23 255 255
281ret ulong 0
282end
283ret ulong 1
284end
285
286fn pkbytes e uint k uint to ulong
287ret mul mul ulong add div k 4 1 ulong e ulong 16
288end
289
290fn alignok lo uint mask uint to ulong
291if eq and lo mask 0
292ret ulong 1
293end
294ret ulong 0
295end
296
297fn tile8 c0 uint to ulong
298if eq rem c0 8 0
299ret ulong 1
300end
301ret ulong 0
302end
303
304fn ctabud segs uint ov uint to ulong
305if ne ov 0
306ret ulong ov
307end
308if ge segs 64
309ret ulong 2
310end
311if ge segs 8
312ret ulong 12
313end
314ret ulong 96
315end
316
317fn perm4 q uint to ulong
318h = and q 3
319o = uint 0
320if eq h 1
321o = 2
322end
323if eq h 2
324o = 1
325end
326if eq h 3
327o = 3
328end
329ret ulong or and q 4294967292 o
330end
331
332fn pfbm rt uint to ulong
333r = rt
334if eq rt 0
335r = 8
336end
337ret mul ulong 16 ulong r
338end
339
340fn swsrc p uint n uint to ulong
341G = div p 16
342h = rem p 16
343i = uint perm4 add mul 8 G rem h 8
344if lt h 8
345ret ulong i
346end
347ret ulong add div n 2 i
348end
349
350fn maxmnk m uint k uint n uint to ulong
351if or eq m 0 or eq k 0 eq n 0
352ret ulong 0
353end
354if or gt m 8192 or gt k 16384 gt n 262144
355ret ulong 0
356end
357ret ulong 1
358end
359
360fn dcache layers uint mx uint rot uint to ulong
361if or eq layers 0 gt layers 64
362ret ulong 1
363end
364if or eq mx 0 or gt mx 131072 ne rem mx 256 0
365ret ulong 1
366end
367if or lt rot 2 or gt rot 256 ne rem rot 2 0
368ret ulong 1
369end
370ret ulong 0
371end
372
373fn dreg decl uint to ulong
374if le mul ulong 256 ulong decl ulong 65536
375ret ulong 1
376end
377ret ulong 0
378end
379
380fn tpack n uint k uint lay uint R uint np uint to ulong
381if or eq n 0 ne rem k 16 0
382ret ulong 1
383end
384if lt np n
385ret ulong 1
386end
387step = uint 1
388if eq lay 1
389step = R
390end
391if eq step 0
392ret ulong 1
393end
394if ne rem np mul 2 step 0
395ret ulong 1
396end
397ret ulong 0
398end
399
400fn rrows s uint to ulong
401if eq s 0
402ret ulong 16
403end
404ret ulong s
405end
406
407fn rtdst g uint ex uint q uint e uint to ulong
408ret ulong add mul add mul g e ex 4 q
409end
410
411fn rtsrc ex uint k uint g uint q uint to ulong
412ret ulong add add mul ex k mul 4 g q
413end
414
415fn dsplit pos uint per uint mx uint to ulong
416p = per
417if eq per 0
418p = 256
419end
420if ne rem p 256 0
421ret ulong 1
422end
423sp = div add pos p p
424if gt sp mx
425ret ulong 2
426end
427ret shl ulong ulong sp 32
428end
429
430fn vy2 v uint to ulong
431if eq v 0
432ret ulong 0
433end
434if eq and v sub v 1 0
435ret ulong 1
436end
437ret ulong 0
438end
439
440fn thok lo uint hi uint to ulong
441t = bitcast f64 or ulong ulong lo shl ulong ulong hi 32
442if gt t 0.0f64
443ret ulong 1
444end
445ret ulong 0
446end
447
448fn fp8mt mt uint segs uint to ulong
449if ne mt 0
450ret ulong mt
451end
452if lt segs 8
453ret ulong 8
454end
455ret ulong 4
456end
457fn tcsp rt uint ct uint n uint to ulong
458r = rt
459c = ct
460if eq rt 0
461r = 4
462end
463if eq ct 0
464c = 1
465if eq rem n 128 0
466c = 2
467end
468end
469ret or ulong ulong r shl ulong ulong c 32
470end
471fn tcw w uint to ulong
472if eq w 0
473ret ulong 8
474end
475ret ulong w
476end
477fn rup v uint q uint to ulong
478if eq q 0
479ret ulong 0
480end
481ret ulong mul div add v sub q 1 q q
482end
483fn woff kp uint col0 uint to ulong
484ret mul mul ulong div col0 8 ulong kp ulong 16
485end
486fn wok c0 uint cols uint n uint to ulong
487if ne rem c0 8 0
488ret ulong 0
489end
490if eq cols 0
491ret ulong 0
492end
493if gt c0 n
494ret ulong 0
495end
496if gt cols sub n c0
497ret ulong 0
498end
499ret ulong 1
500end
501fn qgrp kb uint to ulong
502g = uint 32
503while and gt g 0 ne rem kb g 0 bound 32
504g = sub g 1
505end
506ret ulong g
507end
508fn qrt rt uint to ulong
509if eq rt 0
510ret ulong 4
511end
512ret ulong rt
513end
514fn qwait set uint w uint to ulong
515if eq set 0
516ret ulong 45
517end
518ret ulong w
519end
520fn le128 d uint to ulong
521if gt d 128
522ret ulong 0
523end
524ret ulong 1
525end
526
527fn roomok n uint pos uint mx uint to ulong
528if eq n 0
529ret ulong 1
530end
531if gt pos mx
532ret ulong 1
533end
534room = sub mx pos
535if gt n room
536ret ulong 1
537end
538ret ulong 0
539end
540fn pa256b m uint pos uint mx uint to ulong
541if gt m 32768
542ret ulong 1
543end
544ret roomok m pos mx
545end
546fn qydiv qh uint pc uint to ulong
547if eq pc 0
548ret shl ulong ulong 1 32
549end
550ret ulong div qh pc
551end
552fn qfbyt rows uint qh uint to ulong
553pairs = div add rows 1 2
554ret mul ulong mul ulong pairs ulong qh ulong 1024
555end
556fn gxatt m uint to ulong
557ret ulong div add m 7 8
558end
559fn kvsb mx uint to ulong
560ret mul ulong mx ulong 512
561end
562fn hostb n uint w uint to ulong
563ret mul ulong mul ulong n ulong w ulong 4
564end
565fn vy16 v uint to ulong
566if gt v 16
567ret ulong 1
568end
569ret ulong 0
570end
571fn splt mx uint to ulong
572ret ulong div mx 256
573end
574fn plane kvh uint mx uint to ulong
575ret add mul ulong mul ulong kvh ulong mx ulong 512 ulong 8256
576end
577fn persok p uint to ulong
578if eq p 0
579ret ulong 1
580end
581if eq p 256
582ret ulong 1
583end
584ret ulong 0
585end
586fn stride need uint got uint mask uint to ulong
587if lt got need
588ret ulong 1
589end
590if ne and got mask 0
591ret ulong 1
592end
593ret ulong 0
594end
595fn mtfit n uint pos uint vy uint to ulong
596smax = add div add pos sub n 1 256 1
597prod = mul ulong mul ulong mul ulong n ulong vy ulong smax ulong 6192
598if gt prod ulong 67108864
599ret ulong 1
600end
601ret ulong 0
602end
603fn mtgrp left uint p0 uint t0 uint vy uint to ulong
604n = left
605if gt n 128
606n = uint 128
607end
608pos = add p0 t0
609while and gt n 1 eq mtfit n pos vy 1 bound 128
610n = sub n 1
611end
612smax = add div add pos sub n 1 256 1
613ret or ulong ulong n shl ulong ulong smax 32
614end
615fn mtbig n uint vy uint sm uint to ulong
616ps = mul ulong mul ulong vy ulong sm ulong 6192
617if gt mul ulong n ulong ps ulong 67108864
618ret ulong 1
619end
620ret ulong 0
621end
622fn smaxp pos uint n uint to ulong
623ret ulong add div add pos sub n 1 256 1
624end
625fn mtps vy uint sm uint to ulong
626ret mul ulong mul ulong vy ulong sm ulong 6192
627end
628fn p2bad v uint to ulong
629if eq v 0
630ret ulong 1
631end
632if ne and v sub v 1 0
633ret ulong 1
634end
635ret ulong 0
636end
637
638fn nkbad n uint k uint to ulong
639if eq n 0
640ret ulong 1
641end
642if gt n 1073741824
643ret ulong 1
644end
645if eq k 0
646ret ulong 1
647end
648if ne rem k 256 0
649ret ulong 1
650end
651if gt k 16384
652ret ulong 2
653end
654if and gt k 8192 ne rem k 512 0
655ret ulong 2
656end
657ret ulong 0
658end
659fn layok lay uint R uint to ulong
660if gt lay 1
661ret ulong 1
662end
663if and eq lay 1 ne R 2
664if ne R 4
665ret ulong 1
666end
667end
668ret ulong 0
669end
670fn tritok v uint to ulong
671if eq v 0
672ret ulong 1
673end
674if eq v 1
675ret ulong 1
676end
677if eq v 255
678ret ulong 1
679end
680ret ulong 0
681end
682fn qset k uint to ulong
683if ne rem k 128 0
684ret ulong 0
685end
686kb = div k 128
687if le kb 32
688ret ulong 0
689end
690ret qgrp kb
691end
692fn pfargs n uint k uint lay uint to ulong
693if eq n 0
694ret ulong 1
695end
696if eq k 0
697ret ulong 1
698end
699if ne rem n 128 0
700ret ulong 1
701end
702if ne rem k 128 0
703ret ulong 1
704end
705if gt lay 1
706ret ulong 1
707end
708if and eq lay 1 ne rem n 256 0
709ret ulong 1
710end
711ret ulong 0
712end
713
714
715fn apishp op uint a uint b uint c uint d uint e uint to ulong
716if eq op 1
717ret lane a
718end
719if eq op 2
720ret fp8def a b
721end
722if eq op 3
723ret regfit a b
724end
725if eq op 4
726ret tgbm a b c
727end
728if eq op 5
729ret tgspec a b c
730end
731if eq op 6
732ret tgsz a b c
733end
734if eq op 7
735ret ternd a b c d e
736end
737if eq op 8
738ret ternwc a b
739end
740if eq op 9
741ret pad8 a
742end
743if eq op 10
744ret segb a b c d e
745end
746if eq op 11
747ret segend a b c d e
748end
749if eq op 12
750ret finite a
751end
752if eq op 13
753ret pkbytes a b
754end
755if eq op 14
756ret alignok a b
757end
758if eq op 15
759ret tile8 a
760end
761if eq op 16
762ret ctabud a b
763end
764if eq op 17
765ret perm4 a
766end
767if eq op 18
768ret pfbm a
769end
770if eq op 19
771ret swsrc a b
772end
773if eq op 20
774ret maxmnk a b c
775end
776if eq op 21
777ret dcache a b c
778end
779if eq op 22
780ret dreg a
781end
782if eq op 23
783ret tpack a b c d e
784end
785if eq op 24
786ret rrows a
787end
788if eq op 25
789ret rtdst a b c d
790end
791if eq op 26
792ret rtsrc a b c d
793end
794if eq op 27
795ret dsplit a b c
796end
797if eq op 28
798ret vy2 a
799end
800if eq op 29
801ret thok a b
802end
803if eq op 30
804ret fp8mt a b
805end
806if eq op 31
807ret tcsp a b c
808end
809if eq op 32
810ret tcw a
811end
812if eq op 33
813ret rup a b
814end
815if eq op 34
816ret woff a b
817end
818if eq op 35
819ret wok a b c
820end
821if eq op 36
822ret qgrp a
823end
824if eq op 37
825ret qrt a
826end
827if eq op 38
828ret qwait a b
829end
830if eq op 39
831ret le128 a
832end
833if eq op 40
834ret roomok a b c
835end
836if eq op 41
837ret qydiv a b
838end
839if eq op 42
840ret qfbyt a b
841end
842if eq op 43
843ret gxatt a
844end
845if eq op 44
846ret kvsb a
847end
848if eq op 45
849ret hostb a b
850end
851if eq op 46
852ret pa256b a b c
853end
854if eq op 47
855ret vy16 a
856end
857if eq op 48
858ret splt a
859end
860if eq op 49
861ret plane a b
862end
863if eq op 50
864ret persok a
865end
866if eq op 51
867ret stride a b c
868end
869if eq op 52
870ret mtgrp a b c d
871end
872if eq op 53
873ret mtbig a b c
874end
875if eq op 54
876ret smaxp a b
877end
878if eq op 55
879ret mtps a b
880end
881if eq op 56
882ret p2bad a
883end
884if eq op 57
885ret nkbad a b
886end
887if eq op 58
888ret layok a b
889end
890if eq op 59
891ret tritok a
892end
893if eq op 60
894ret qset a
895end
896if eq op 61
897ret pfargs a b c
898end
899ret ulong 0
900end