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 / driver / seqgate.om

730 lines · 14441 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/nvidia/driver/seqgate.om: the sequence gate of the driver slice. It reads the cases the C oracle printed
3note (gpu/nvidia/driver/seq-cases.tsv: the C bodies of CUDApp 84b524ca nvrm_open, alloc_with_cacheability,
4note nvrm_free, chan_extra, nvrm_channel_n, nvrm_channel_destroy, nvrm_enqueue, nvrm_chan_submit, nvrm_close,
5note m16_native_free_memory and the rest, run outside this tree with every device effect recorded) and runs the
6note same program on client.om with fx.om's recorder and the same failure script. The command sequence, the
7note answers, the messages and the final client state must be the same bytes. Exit 0 is PASS.
8note
9note Line: seq PROGRAM K F R TRACE, tab separated. PROGRAM is decimal tokens, the calls made on one client:
10note 1 ADMITSM SELSM DISC NCLS nvrm_open / 2 SLOT SIZE MODE alloc (0 nvrm_alloc, 1 gpu_uncached, 2 vram) /
11note 3 SLOT nvrm_free / 4 EXTRA nvrm_channel_n / 5 nvrm_channel_destroy / 6 SLOT OFF NW nvrm_enqueue /
12note 7 CH SLOT OFF NW nvrm_chan_submit / 8 nvrm_close / 9 SIZE m16_native_alloc_memory / 10 SEL
13note m16_native_free_memory (SEL < 64: legacy row SEL's cpu; else the address SEL) / 11 SLOT FIELD VALUE set a
14note caller descriptor field (0 handle, 1 va, 2 size, 3 cpu) / 12 DST SRC copy a caller descriptor /
15note 13 CH PUT RETIRED set a channel's counters (0 the main one) / 14 MS channel_no_memory_retry_ms /
16note 15 ADMITSM SELSM DISC NCLS m16_native_open / 16 m16_native_create_channel / 17 m16_native_close /
17note 18 SLOT OFF NW nvrm_submit / 19 m16_native_ring_doorbell (nvrm_ring).
18note SLOT is a caller descriptor, 0 to 15. K F R: the failure script (fx.om). TRACE: events "NAME ARGS =R;" in
19note order (fx.om), "OP CODE =RC;" after each call, then the state: "ST ...;" client fields, "LV ...;" each
20note live row, "CH ...;" each extra channel, "MM ...;" each non-empty caller descriptor, "LG ...;" each
21note non-empty m16 legacy row, "PB ...;" m16's pushbuffer when not empty.
22note
23note Controls, two for the first case of each program: the comparison against the expected trace with one
24note byte changed, and the program rerun with another failure script (K 1), each of which must differ.
25note A line is read into a 65536-byte array (fixed when compiled); a longer line is refused by name, never cut.
26
27text sq_use "usage: seqgate SEQ-CASES.tsv\n"
28text sq_topen "seqgate: cannot open, size or map the cases file\n"
29text sq_long "seqgate: a line of the cases file is longer than 65536 bytes; refused\n"
30text sq_fl "FAIL line "
31text sq_at " at byte "
32text sq_tbad "FAIL malformed line "
33text sq_ctl "FAIL control not caught, line "
34text sq_want "\n want: "
35text sq_got "\n got: "
36text sq_ovf "FAIL trace longer than 65536 bytes or a script the recorder cannot follow, line "
37text sq_sum "OMEGA-GPU-DRIVER-SEQ "
38text sq_pass "PASS"
39text sq_fail "FAIL"
40text sq_cs " cases="
41text sq_ps " programs="
42text sq_co " controls="
43text sq_ca " caught="
44text sq_hw " hardware=NOT_RUN\n"
45text sq_nl "\n"
46text sq_seq "seq"
47global sq_p uchar 4096
48global sq_st uchar 256
49global sq_nb uchar 24
50note program tokens and their count
51global sp ulong 256
52note the five tab offsets of the current line
53global sq_t ulong 6
54note sq_n: 0 tokens, 1 line number, 2 cases, 3 fails, 4 controls, 5 caught, 6 programs, 7 file fd, 8 size,
55note 9 control mode (1 on)
56global sq_n ulong 16
57note the previous program, for the first case of each
58global sq_prev uchar 4096
59global sq_pl ulong 1
60
61fn sq_num v ulong to void
62k = ulong 0
63x = v
64while true bound 20
65put sq_nb k uchar add 48 rem x 10
66k = add k 1
67x = div x 10
68if eq x 0
69break
70end
71end
72for j ulong div k 2 bound 10
73a = get sq_nb j
74put sq_nb j get sq_nb sub sub k j 1
75put sq_nb sub sub k j 1 a
76end
77r = write 1 sq_nb 0 k
78end
79
80note --- the state dump, in the oracle's format ---
81fn sq_hex2 b ulong to void
82put sq_nb 0 uchar 32
83h = shr b 4
84lo = and b 15
85put sq_nb 1 uchar add h 48
86if gt h 9
87put sq_nb 1 uchar add h 87
88end
89put sq_nb 2 uchar add lo 48
90if gt lo 9
91put sq_nb 2 uchar add lo 87
92end
93for i ulong 3
94fx_c ulong get sq_nb i
95end
96end
97
98fn sq_row s ulong to void
99fx_su mh s
100fx_su mva s
101fx_su msz s
102fx_su mcpu s
103end
104
105fn sq_dump to void
106fx_c 83
107fx_c 84
108for i ulong 11
109fx_su cg i
110end
111for i ulong 4
112fx_sd bitcast long cg add CS_FDCTL i
113end
114fx_su cg CS_GREG
115fx_su cg CS_VREG
116fx_su cg CS_CREG
117fx_su cg CS_NEXTRA
118fx_su cg CS_LIVEN
119fx_su cg CS_PUT
120fx_su cg CS_RET
121fx_su cg CS_ENT
122fx_su cg CS_USERD
123fx_su cg CS_TOKEN
124fx_su cg CS_CHVA
125fx_su cg CS_CHVASZ
126fx_su cg CS_SLOT
127fx_su cg CS_VANEXT
128fx_su cg CS_TSM
129fx_su cg CS_DISC
130fx_su cg CS_CCLS
131fx_su cg CS_GCLS
132fx_su cg CS_UCLS
133fx_su cg CS_SMV
134fx_su cg CS_GPUID
135fx_su cg CS_MINOR
136fx_su cg CS_UCPU
137fx_su cg CS_LRS
138fx_su cg CS_RETRIES
139for i ulong 16
140sq_hex2 cn_uuidb i
141end
142sq_row 0
143sq_row 1
144fx_semi
145for r ulong cg CS_LIVEN bound 4096
146fx_c 76
147fx_c 86
148fx_su lg r 0
149fx_su lg r 1
150fx_su lg r 2
151fx_su lg r 3
152for f ulong 5
153fx_su lg r add 4 f
154end
155fx_semi
156end
157for i ulong 3
158fx_c 67
159fx_c 72
160for f ulong 10
161fx_su xg i f
162end
163fx_su xg i 10
164sq_row add 2 mul i 2
165sq_row add 3 mul i 2
166fx_semi
167end
168for i ulong 16
169s = add 10 i
170if or or or ne mh s 0 ne mva s 0 ne msz s 0 ne mcpu s 0
171fx_c 77
172fx_c 77
173fx_su i
174sq_row s
175fx_semi
176end
177end
178for i ulong 64
179s = add 26 i
180if or or or ne mh s 0 ne mva s 0 ne msz s 0 ne mcpu s 0
181fx_c 76
182fx_c 71
183fx_su i
184sq_row s
185fx_semi
186end
187end
188if or or or ne mh 9 0 ne mva 9 0 ne msz 9 0 ne mcpu 9 0
189fx_c 80
190fx_c 66
191sq_row 9
192fx_semi
193end
194end
195
196note --- run the program in sp with failure script k f r into fo; false when the program is malformed ---
197note the argument count of call op; 99 for an unknown call
198fn sq_nargs op ulong to ulong
199if or or eq op 1 eq op 7 eq op 15
200ret 4
201end
202if or or or or eq op 2 eq op 6 eq op 11 eq op 13 eq op 18
203ret 3
204end
205if or or or or eq op 3 eq op 4 eq op 9 eq op 10 eq op 14
206ret 1
207end
208if eq op 12
209ret 2
210end
211if or or or or eq op 5 eq op 8 eq op 16 eq op 17 eq op 19
212ret 0
213end
214ret 99
215end
216
217fn sq_a i ulong to ulong
218ret get sp i
219end
220
221fn sq_u i ulong to ulong
222ret and get sp i CN_U32
223end
224
225note 11 SLOT FIELD VALUE
226fn sq_poke i ulong to long
227s = add 10 sq_a i
228fd = sq_a add i 1
229v = sq_a add i 2
230if eq fd 0
231v = and v CN_U32
232end
233put cm add mul s 4 fd v
234ret 0
235end
236
237note 12 DST SRC
238fn sq_copy i ulong to long
239d = add 10 sq_a i
240s = add 10 sq_a add i 1
241mset d mh s mva s msz s mcpu s
242ret 0
243end
244
245note 13 CH PUT RETIRED
246fn sq_ctr i ulong to long
247c = sq_a i
248if eq c 0
249cp CS_PUT sq_u add i 1
250cp CS_RET sq_u add i 2
251ret 0
252end
253xp sub c 1 6 sq_u add i 1
254xp sub c 1 7 sq_u add i 2
255ret 0
256end
257
258note 10 SEL
259fn sq_m16free i ulong to long
260sel = sq_a i
261if lt sel 64
262ret cn_m16free mcpu add 26 sel
263end
264ret cn_m16free sel
265end
266
267note call op with its arguments at sp[i] (checked by sq_ok)
268fn sq_op op ulong i ulong to long
269if eq op 1
270fx_scen sq_a i sq_a add i 1 sq_a add i 2 sq_a add i 3
271ret cn_open
272end
273if eq op 2
274ret cn_alloc_mode sq_a add i 1 add 10 sq_a i sq_a add i 2
275end
276if eq op 3
277ret cn_free add 10 sq_a i
278end
279if eq op 4
280ret cn_channel sq_u i
281end
282if eq op 5
283ret cn_chdestroy
284end
285if eq op 6
286ret cn_enqueue add 10 sq_a i sq_u add i 1 sq_u add i 2
287end
288if eq op 7
289ret cn_submit sq_u i add 10 sq_a add i 1 sq_u add i 2 sq_u add i 3
290end
291if eq op 8
292ret cn_close
293end
294if eq op 9
295ret cn_m16alloc sq_a i
296end
297if eq op 10
298ret sq_m16free i
299end
300if eq op 11
301ret sq_poke i
302end
303if eq op 12
304ret sq_copy i
305end
306if eq op 13
307ret sq_ctr i
308end
309if eq op 15
310fx_scen sq_a i sq_a add i 1 sq_a add i 2 sq_a add i 3
311ret cn_m16open
312end
313if eq op 16
314ret cn_m16chan
315end
316if eq op 17
317ret cn_m16close
318end
319if eq op 18
320ret cn_nsubmit add 10 sq_a i sq_u add i 1 sq_u add i 2
321end
322if eq op 19
323cn_ring
324ret 0
325end
326cp CS_RETMS sq_u i
327ret 0
328end
329
330note the arguments of call op at sp[i] name existing slots, fields and channels
331fn sq_ok op ulong i ulong to bool
332if or or or or or eq op 2 eq op 3 eq op 6 eq op 11 eq op 12 eq op 18
333if gt sq_a i 15
334ret false
335end
336end
337if or eq op 7 eq op 12
338if gt sq_a add i 1 15
339ret false
340end
341end
342if eq op 11
343if gt sq_a add i 1 3
344ret false
345end
346end
347if eq op 13
348if gt sq_a i 3
349ret false
350end
351end
352ret true
353end
354
355fn sq_run k ulong f ulong r ulong to bool
356fx_reset k f r
357cn_zero
358for j ulong 360
359put cm j 0
360end
361np = get sq_n 0
362i = ulong 0
363while lt i np bound 256
364op = get sp i
365i = add i 1
366n = sq_nargs op
367if gt add i n np
368ret false
369end
370if not sq_ok op i
371ret false
372end
373rc = sq_op op i
374i = add i n
375fx_c 79
376fx_c 80
377fx_su op
378fx_rd rc
379end
380sq_dump
381ret true
382end
383
384note --- line fields ---
385note decimal l[a, b): 1 to 20 digits below 2^64, else false (and v unchanged)
386fn sq_dec l view uchar 65536 a ulong b ulong o edit ulong 1 to bool
387if or ge a b gt sub b a 20
388ret false
389end
390v = ulong 0
391for i ulong sub b a bound 20
392c = ulong get l add a i
393if or lt c 48 gt c 57
394ret false
395end
396d = sub c 48
397if gt v 1844674407370955161
398ret false
399end
400if and eq v 1844674407370955161 gt d 5
401ret false
402end
403v = add mul v 10 d
404end
405put o 0 v
406ret true
407end
408
409note the program field l[a, b) into sp; false when it is not decimal tokens separated by single spaces
410fn sq_prog l view uchar 65536 a ulong b ulong to bool
411o = new ulong 1 0
412n = ulong 0
413s = a
414for i ulong sub add b 1 a bound 65537
415p = add a i
416if or eq p b eq get l p 32
417if ge n 256
418ret false
419end
420if not sq_dec l s p o
421ret false
422end
423put sp n get o 0
424n = add n 1
425s = add p 1
426end
427end
428put sq_n 0 n
429ret true
430end
431
432note bytes l[a, b) against fo: the first difference, or 2^64 - 1 when they are the same
433fn sq_cmp l view uchar 65536 a ulong b ulong to ulong
434m = get fz 0
435w = sub b a
436for i ulong m bound 65536
437if ge i w
438ret i
439end
440if ne ulong get fo i ulong get l add a i
441ret i
442end
443end
444if ne m w
445ret m
446end
447ret 18446744073709551615
448end
449
450fn sq_show l view uchar 65536 a ulong b ulong ab ulong to void
451s = ulong 0
452if gt ab 60
453s = sub ab 60
454end
455e = add s 160
456r = write 1 sq_want 0 len sq_want
457we = sub b a
458if gt e we
459e = we
460end
461if lt s e
462r = write 1 l add a s sub e s
463end
464r = write 1 sq_got 0 len sq_got
465ge2 = add s 160
466if gt ge2 get fz 0
467ge2 = get fz 0
468end
469if lt s ge2
470r = write 1 fo s sub ge2 s
471end
472r = write 1 sq_nl 0 len sq_nl
473end
474
475fn sq_fail_line ab ulong to void
476put sq_n 3 add get sq_n 3 1
477r = write 1 sq_fl 0 len sq_fl
478sq_num get sq_n 1
479r = write 1 sq_at 0 len sq_at
480sq_num ab
481end
482
483fn sq_bad to void
484put sq_n 3 add get sq_n 3 1
485r = write 1 sq_tbad 0 len sq_tbad
486sq_num get sq_n 1
487r = write 1 sq_nl 0 len sq_nl
488end
489
490fn sq_ctlmiss to void
491put sq_n 3 add get sq_n 3 1
492r = write 1 sq_ctl 0 len sq_ctl
493sq_num get sq_n 1
494r = write 1 sq_nl 0 len sq_nl
495end
496
497note is the program l[a, b) the one of the previous case; remember it
498fn sq_newprog l view uchar 65536 a ulong b ulong to bool
499w = sub b a
500same = eq w get sq_pl 0
501if gt w 4096
502ret true
503end
504for i ulong w bound 4096
505if ne get sq_prev i get l add a i
506same = false
507end
508put sq_prev i get l add a i
509end
510put sq_pl 0 w
511ret not same
512end
513
514note the fields of line l[0, e) into sq_t (tab offsets) and sq_n 11 12 13 (K F R); false when malformed
515fn sq_parse e ulong l view uchar 65536 to bool
516nt = ulong 0
517for i ulong e bound 65536
518if eq get l i 9
519if lt nt 5
520put sq_t nt i
521end
522nt = add nt 1
523end
524end
525if ne nt 5
526ret false
527end
528if ne get sq_t 0 3
529ret false
530end
531for i ulong 3
532if ne get l i get sq_seq i
533ret false
534end
535end
536if not sq_prog l add get sq_t 0 1 get sq_t 1
537ret false
538end
539o = new ulong 1 0
540for j ulong 3
541if not sq_dec l add get sq_t add j 1 1 get sq_t add j 2 o
542ret false
543end
544put sq_n add 11 j get o 0
545end
546ret true
547end
548
549note run the case and compare; true when the trace is the expected one
550fn sq_case e ulong l view uchar 65536 to bool
551if not sq_run get sq_n 11 get sq_n 12 get sq_n 13
552sq_bad
553ret false
554end
555if or ne get fz 11 0 ne get fz 12 0
556put sq_n 3 add get sq_n 3 1
557w = write 1 sq_ovf 0 len sq_ovf
558sq_num get sq_n 1
559w = write 1 sq_nl 0 len sq_nl
560ret false
561end
562ta = add get sq_t 4 1
563ab = sq_cmp l ta e
564if ne ab 18446744073709551615
565sq_fail_line ab
566sq_show l ta e ab
567ret false
568end
569ret true
570end
571
572note the two controls of a program's first case
573fn sq_ctls e ulong l edit uchar 65536 to void
574ta = add get sq_t 4 1
575note control 1: the expected trace with one byte changed must not compare equal
576mid = add ta div sub e ta 2
577keep = get l mid
578put l mid uchar xor ulong keep 1
579put sq_n 4 add get sq_n 4 1
580if ne sq_cmp l ta e 18446744073709551615
581put sq_n 5 add get sq_n 5 1
582else
583sq_ctlmiss
584end
585put l mid keep
586note control 2: the same program with another failure script must give another trace
587k2 = ulong 1
588if eq get sq_n 11 1
589k2 = ulong 2
590end
591put sq_n 4 add get sq_n 4 1
592if sq_run k2 0 1
593if ne sq_cmp l ta e 18446744073709551615
594put sq_n 5 add get sq_n 5 1
595else
596sq_ctlmiss
597end
598else
599sq_ctlmiss
600end
601end
602
603fn sq_line e ulong l edit uchar 65536 to void
604put sq_n 1 add get sq_n 1 1
605if eq e 0
606ret
607end
608if eq get l 0 35
609ret
610end
611if not sq_parse e l
612sq_bad
613ret
614end
615put sq_n 2 add get sq_n 2 1
616first = sq_newprog l add get sq_t 0 1 get sq_t 1
617if first
618put sq_n 6 add get sq_n 6 1
619end
620if not sq_case e l
621ret
622end
623if first
624sq_ctls e l
625end
626end
627
628fn sq_gsize fd int to ulong
629if ne fstat fd sq_st 0 128 0
630ret 0
631end
632size = ulong 0
633for j ulong 8
634size = or size shl ulong get sq_st add 48 j mul j 8
635end
636ret size
637end
638
639fn sq_open to long
640if ne argcnt 2
641r = write 2 sq_use 0 len sq_use
642ret 0
643end
644pl = argread 1 sq_p 0 4095
645if lt pl 1
646r = write 2 sq_use 0 len sq_use
647ret 0
648end
649fd = int fopen sq_p 0 ulong pl 524288 0
650if lt fd 0
651r = write 2 sq_topen 0 len sq_topen
652ret 0
653end
654size = sq_gsize fd
655put sq_n 7 ulong fd
656put sq_n 8 size
657h = long 0
658if gt size 0
659h = mapnew fd 0 size 1 2
660end
661if le h 0
662r = write 2 sq_topen 0 len sq_topen
663ret 0
664end
665ret h
666end
667
668fn sq_eol k ulong l view uchar 65536 to ulong
669for i ulong k bound 65536
670if eq get l i 10
671ret i
672end
673end
674ret k
675end
676
677fn sq_summary to int
678r = write 1 sq_sum 0 len sq_sum
679pass = and eq get sq_n 3 0 gt get sq_n 2 0
680pass = and pass eq get sq_n 4 get sq_n 5
681pass = and pass eq get sq_n 4 mul 2 get sq_n 6
682if pass
683r = write 1 sq_pass 0 len sq_pass
684else
685r = write 1 sq_fail 0 len sq_fail
686end
687r = write 1 sq_cs 0 len sq_cs
688sq_num get sq_n 2
689r = write 1 sq_ps 0 len sq_ps
690sq_num get sq_n 6
691r = write 1 sq_co 0 len sq_co
692sq_num get sq_n 4
693r = write 1 sq_ca 0 len sq_ca
694sq_num get sq_n 5
695r = write 1 sq_hw 0 len sq_hw
696if pass
697ret 0
698end
699ret 1
700end
701
702fn main to int
703l = new uchar 65536 0
704h = sq_open
705if le h 0
706ret 2
707end
708size = get sq_n 8
709pos = ulong 0
710while lt pos size bound 9223372036854775807
711k = sub size pos
712if gt k 65536
713k = ulong 65536
714end
715if ne mapread h pos l 0 k long k
716r = write 2 sq_topen 0 len sq_topen
717ret 2
718end
719e = sq_eol k l
720if and eq e k eq k 65536
721r = write 2 sq_long 0 len sq_long
722ret 2
723end
724sq_line e l
725pos = add pos add e 1
726end
727r = mapdrop h
728q = fclose int get sq_n 7
729ret sq_summary
730end