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 / native / abft / run.om

731 lines · 12612 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note native/abft evaluator driver. Owns inputs, the ground-truth record gref, the nonce stream, the
3note tolerances and admission. Each attempt forks a candidate child whose only channel back is a memfd
4note plus its exit status; the evaluator kills it at the frozen deadline and always reaps it.
5note Output columns are printed first (COLUMNS lines); docs/abft/CONTRACT.md section 8 decodes them.
6text MFN "abftout"
7text TCASE "CASE"
8text TSCH "SCHED"
9text TWIT "WITNESS"
10text TTAL "TALLY"
11text TRES "RESOURCES"
12text TPLAN "PLAN"
13text TGATE "GATE"
14text THDR "COLUMNS PLAN version rows S deadline_ns retries first last\nCOLUMNS CASE row rep att dt m n k w pol tgt site fault sub p1 p2 seed nonce exit sig bytes corrupt struct dig full abft samp adm verdict t_cand t_ref t_full t_abft t_samp t_dig sched steps\nCOLUMNS SCHED row status reason pol tgt site control distinct reps round_robin\nCOLUMNS TALLY row cases corrupt full_tp full_fn full_fp full_tn abft_tp abft_fn abft_fp abft_tn samp_tp samp_fn samp_fp samp_tn dig_tp dig_fn dig_fp dig_tn struct_tp struct_fn struct_fp struct_tn adm_tp adm_fn adm_fp adm_tn accept recovered rejected sched_status timeouts reps\nCOLUMNS WITNESS row partner reps same orig_det red_det verdict\nCOLUMNS RESOURCES forks reaped timeouts kills fd_errors wait_errors fd_first fd_last\nCOLUMNS GATE id pass observed expected\n"
15const CEXIT ulong 0
16const CSIG ulong 1
17const CBYT ulong 2
18const CCOR ulong 3
19const CSTR ulong 4
20const CDIG ulong 5
21const CFUL ulong 6
22const CABF ulong 7
23const CSAM ulong 8
24const CADM ulong 9
25const CTC ulong 10
26const CTR ulong 11
27const CTF ulong 12
28const CTA ulong 13
29const CTS ulong 14
30const CTD ulong 15
31const CSH ulong 16
32const CSTP ulong 17
33const CNON ulong 18
34const CVER ulong 19
35global gx uchar 262160
36global gst uchar 4
37global gnon uchar 8
38global gab uchar 32
39global gdig ulong 1
40global gcs ulong 32
41global gtl ulong 32
42global gtr ulong 2048
43global ghs ulong 256
44global gres ulong 8
45global kq ulong 16
46global gwp ulong 256
47global gwc ulong 256
48global gwn ulong 4
49global gexit ulong 64
50fn cs i ulong to ulong
51ret get gcs i
52end
53fn css i ulong v ulong to void
54put gcs i v
55end
56fn pget r ulong f ulong to ulong
57ret get pl add mul r 16 f
58end
59fn rinc i ulong to void
60put gres i add get gres i 1
61end
62fn tinc i ulong to void
63put gtl i add get gtl i 1
64end
65fn bv b bool to ulong
66if b
67ret 1
68end
69ret 0
70end
71fn ptxt0 to void
72for i ulong len TCASE
73ochar get TCASE i
74end
75end
76fn ptxt1 to void
77for i ulong len TSCH
78ochar get TSCH i
79end
80end
81fn ptxt2 to void
82for i ulong len TWIT
83ochar get TWIT i
84end
85end
86fn ptxt3 to void
87for i ulong len TTAL
88ochar get TTAL i
89end
90end
91fn ptxt4 to void
92for i ulong len TRES
93ochar get TRES i
94end
95end
96fn ptxt5 to void
97for i ulong len TPLAN
98ochar get TPLAN i
99end
100end
101fn ptxt6 to void
102for i ulong len TGATE
103ochar get TGATE i
104end
105end
106fn ptxth to void
107for i ulong len THDR
108ochar get THDR i
109end
110end
111fn bfgen to ulong
112s = and rnext 0 1
113e = add 120 rbelow 0 8
114m = rbelow 0 128
115ret or or shl s 15 shl e 7 m
116end
117fn gval to ulong
118if eq get gd 0 0
119ret and rnext 0 MASK
120end
121ret bfgen
122end
123note Inputs from stream 0 seeded by (row seed, rep); evaluator-owned, never candidate-chosen.
124fn gen rep ulong to void
125rseed 0 add mul kf KSEED 1000003 rep
126put gd 0 kf KDT
127put gd 1 kf KM
128put gd 2 kf KN
129put gd 3 kf KK
130for e ulong mul dm dk
131put ga e gval
132end
133for e ulong mul dk dn
134put gb e gval
135end
136end
137note Ground-truth record: the same tiled algorithm, fault free, one worker, round robin, in the
138note evaluator process. Used only to label corrupt/clean; no checker or admission reads it.
139fn cref to void
140for f ulong 16
141put kq f get kp f
142end
143put kp KFLT 0
144put kp KW 1
145put kp KPOL 0
146put kat 0 0
147s = crun
148if eq s 0
149trap 11
150end
151for e ulong mul dm dn
152put gref e get cc e
153end
154for f ulong 16
155put kp f get kq f
156end
157end
158fn cpack e ulong v ulong to void
159for b ulong 4
160put gx add mul e 4 b uchar and shr v mul b 8 255
161end
162end
163fn cpack8 o ulong v ulong to void
164for b ulong 8
165put gx add o b uchar and shr v mul b 8 255
166end
167end
168note Child: the candidate. Writes M*N little-endian u32 words, its schedule hash and step count.
169fn cchild fd int to void
170s = crun
171mn = mul kf KM kf KN
172for e ulong mn
173cpack e get cc e
174end
175nb = mul mn 4
176cpack8 nb get csh 0
177cpack8 add nb 8 s
178w = pwrite fd gx 0 add nb 16 0
179if ne w long add nb 16
180exit 70
181end
182exit 0
183end
184fn reap pid long to void
185dl = add now get pcfg 1
186r = long 0
187while true bound 999999
188r = waitpid int pid gst 0 4 1
189if ne r 0
190break
191end
192if gt now dl
193k = killpid int pid 9
194if ne k 0
195rinc 5
196end
197rinc 2
198rinc 3
199tinc 30
200r = waitpid int pid gst 0 4 0
201break
202end
203z = sleepns 100000
204if lt z 0
205rinc 5
206end
207end
208if lt r 0
209rinc 5
210else
211rinc 1
212end
213css CSIG and ulong get gst 0 127
214css CEXIT ulong get gst 1
215end
216fn word e ulong to ulong
217v = ulong 0
218for b ulong 4
219v = or v shl ulong get gx add mul e 4 b mul b 8
220end
221ret v
222end
223fn word8 o ulong to ulong
224v = ulong 0
225for b ulong 8
226v = or v shl ulong get gx add o b mul b 8
227end
228ret v
229end
230fn collect fd int to void
231mn = mul dm dn
232nb = mul mn 4
233for e ulong mn
234put gobs e 0
235end
236r = pread fd gx 0 add nb 16 0
237c = fclose fd
238if ne c 0
239rinc 4
240end
241if lt r 0
242css CBYT 0
243ret
244end
245css CBYT ulong r
246if ne ulong r add nb 16
247ret
248end
249for e ulong mn
250put gobs e word e
251end
252css CSH word8 nb
253css CSTP word8 add nb 8
254end
255fn okout to bool
256if ne cs CEXIT 0
257ret false
258end
259if ne cs CSIG 0
260ret false
261end
262ret eq cs CBYT add mul mul dm dn 4 16
263end
264fn truth to ulong
265if not okout
266ret 1
267end
268for e ulong mul dm dn
269if ne get gobs e get gref e
270ret 1
271end
272end
273ret 0
274end
275fn nonce to ulong
276r = random gnon 0 8 0
277if ne r 8
278trap 12
279end
280v = ulong 0
281for b ulong 8
282v = or v shl ulong get gnon b mul b 8
283end
284ret v
285end
286note Detectors. Timed with now (monons); check time is reported separately, never inside t_cand.
287fn detect to void
288t = now
289css CDIG bv ne cdig get gdig 0
290css CTD sub now t
291css CSTR bv not okout
292if not okout
293css CFUL 2
294css CABF 2
295css CSAM 2
296ret
297end
298if gt cnonfin 0
299css CSTR 1
300end
301n = nonce
302css CNON n
303rseed 1 n
304t = now
305css CFUL bv gt cfull 0
306css CTF sub now t
307t = now
308css CABF bv gt cabft 0
309css CTA sub now t
310t = now
311css CSAM bv gt csamp get pcfg 0 0
312css CTS sub now t
313end
314fn admit to ulong
315if eq cs CSTR 1
316ret 1
317end
318if eq cs CDIG 1
319ret 1
320end
321if eq cs CFUL 1
322ret 1
323end
324ret bv eq cs CABF 1
325end
326fn attempt att ulong to void
327for i ulong 32
328if ne i CTR
329css i 0
330end
331end
332put kat 0 att
333fd = memfd MFN 0 len MFN 0
334if lt fd 0
335trap 13
336end
337t = now
338pid = fork
339if eq pid 0
340cchild int fd
341end
342if lt pid 0
343trap 14
344end
345rinc 0
346reap pid
347css CTC sub now t
348collect int fd
349css CCOR truth
350detect
351css CADM admit
352end
353fn tadd b ulong d ulong c ulong to void
354if eq d 2
355ret
356end
357if eq c 1
358if eq d 1
359tinc b
360else
361tinc add b 1
362end
363else
364if eq d 1
365tinc add b 2
366else
367tinc add b 3
368end
369end
370end
371fn tcase to void
372tinc 0
373c = cs CCOR
374if eq c 1
375tinc 1
376end
377if eq cs CEXIT 103
378put gexit kf 0 add get gexit kf 0 1
379end
380tadd 2 cs CFUL c
381tadd 6 cs CABF c
382tadd 10 cs CSAM c
383tadd 14 cs CDIG c
384tadd 18 cs CSTR c
385tadd 22 cs CADM c
386end
387fn pcase r ulong rep ulong att ulong to void
388ptxt0
389onum add r 1
390onum rep
391onum att
392for f ulong 13
393onum kf add f 1
394end
395onum cs CNON
396for q ulong 10
397onum cs q
398end
399onum cs CVER
400for q ulong 6
401onum cs add CTC q
402end
403onum cs CSH
404onum cs CSTP
405onl
406end
407fn hseen h ulong to void
408n = get gwn 2
409for q ulong n
410if eq get ghs q h
411ret
412end
413end
414if lt n 256
415put ghs n h
416put gwn 2 add n 1
417end
418end
419fn odig2 to ulong
420h = ulong 14695981039346656037
421for e ulong mul dm dn
422h = fnvw h get gobs e
423end
424ret h
425end
426note One rep: fresh inputs, digest, ground truth, optional common-mode corruption, then up to
427note 1 + retries attempts. Verdict 0 ACCEPT, 1 RECOVERED, 2 REJECTED, 4 retry follows.
428fn runrep r ulong rep ulong to void
429gen rep
430put krep 0 rep
431put gdig 0 cdig
432t = now
433cref
434css CTR sub now t
435if eq kf KFLT 7
436p = kf KP1
437put ga p xor get ga p shl ulong 1 kf KP2
438end
439last = get pcfg 2
440for att ulong add last 1
441attempt att
442if eq att 0
443hseen cs CSH
444put gwc rep odig2
445if eq cs CADM 1
446put gwn 1 add get gwn 1 1
447end
448end
449if eq cs CADM 0
450css CVER bv gt att 0
451else
452if eq att last
453css CVER 2
454else
455css CVER 4
456end
457end
458tcase
459pcase r rep att
460if ne cs CVER 4
461tinc add 26 cs CVER
462break
463end
464end
465for e ulong mul dm dn
466put gprev e get gref e
467end
468end
469fn psched r ulong st ulong rsn ulong to void
470ptxt1
471onum add r 1
472onum st
473onum rsn
474onum kf KPOL
475onum kf KTGT
476onum kf KSITE
477onum shr and kf KFLG 2 1
478onum get gwn 2
479onum get kp 14
480onum bv eq kf KPOL 0
481onl
482end
483fn ptally r ulong to void
484ptxt3
485onum add r 1
486for q ulong 32
487onum get gtl q
488end
489onl
490for q ulong 32
491put gtr add mul r 32 q get gtl q
492end
493end
494note CUDApp#56: a row flagged bit3 is the reduced-concurrency partner of the row before it (same
495note seed). OR-RR: fault-free output digests equal rep by rep. OC-RC: verdict 1 means the original
496note concurrency detected a fault the reduced run never showed, a counterexample to using it as proof.
497fn pwit r ulong to void
498reps = get kp 14
499same = ulong 0
500for q ulong reps
501if eq get gwp q get gwc q
502same = add same 1
503end
504end
505od = get gwn 0
506rd = get gwn 1
507v = ulong 0
508if ne same reps
509v = 2
510end
511if and gt od 0 eq rd 0
512v = 1
513end
514ptxt2
515onum add r 1
516onum r
517onum reps
518onum same
519onum od
520onum rd
521onum v
522onl
523put gwn 3 add mul v 1000 same
524end
525fn runrow r ulong to void
526for f ulong 16
527put kp f pget r f
528end
529put kat 0 0
530for q ulong 32
531put gtl q 0
532end
533put gwn 2 0
534put gwn 1 0
535put gtl 31 get kp 14
536rsn = sreason
537st = sstatus rsn
538put gtl 29 st
539if ne st 0
540psched r st rsn
541ptally r
542ret
543end
544gen 1000000
545cref
546for e ulong mul dm dn
547put gprev e get gref e
548end
549for rep ulong get kp 14
550runrep r rep
551end
552psched r st rsn
553ptally r
554if eq and kf KFLG 8 8
555pwit r
556end
557for q ulong 256
558put gwp q get gwc q
559end
560put gwn 0 get gwn 1
561oflush
562end
563fn tl id ulong i ulong to ulong
564ret get gtr add mul sub id 1 32 i
565end
566fn pgate id ulong ok bool obs ulong exp ulong to bool
567ptxt6
568onum id
569onum bv ok
570onum obs
571onum exp
572onl
573ret ok
574end
575note Gates (docs/abft/CONTRACT.md section 9). Declared admission misses: rows 11 and 17
576note (f32 mantissa flips below the P1 rounding bound). Only meaningful over the full plan.
577fn gfp to ulong
578s = ulong 0
579for r ulong get pn 0
580for d ulong 6
581s = add s tl add r 1 add 4 mul d 4
582end
583end
584ret s
585end
586fn gfn to ulong
587s = ulong 0
588for r ulong get pn 0
589id = add r 1
590if and ne id 11 ne id 17
591s = add s tl id 23
592end
593end
594ret s
595end
596fn gsched to ulong
597bad = ulong 0
598for r ulong get pn 0
599id = add r 1
600e = ulong 0
601if eq id 37
602e = 65
603end
604if or eq id 38 eq id 39
605e = 69
606end
607if ne tl id 29 e
608bad = add bad 1
609end
610end
611ret bad
612end
613fn gates to ulong
614fail = ulong 0
615v = gfp
616if not pgate 1 eq v 0 v 0
617fail = add fail 1
618end
619v = gfn
620if not pgate 2 eq v 0 v 0
621fail = add fail 1
622end
623v = gsched
624if not pgate 3 eq v 0 v 0
625fail = add fail 1
626end
627v = add tl 43 27 tl 44 28
628if not pgate 4 eq v add tl 43 31 tl 44 31 v add tl 43 31 tl 44 31
629fail = add fail 1
630end
631ret add fail gates2
632end
633fn gates2 to ulong
634fail = ulong 0
635ok = and eq get gres 0 get gres 1 eq get gres 6 get gres 7
636ok = and ok eq add get gres 4 get gres 5 0
637if not pgate 5 ok sub get gres 0 get gres 1 0
638fail = add fail 1
639end
640v = tl 36 30
641if not pgate 6 eq v mul 2 tl 36 31 v mul 2 tl 36 31
642fail = add fail 1
643end
644v = add tl 40 7 tl 40 2
645if not pgate 7 eq v mul 2 tl 40 1 v mul 2 tl 40 1
646fail = add fail 1
647end
648note Gate 8 (revised after the first sandbox run, see CONTRACT.md section 9): the digest catches every
649note corrupt case, and full/checksum detect only the cases the structural check flags as nonfinite.
650s = tl 42 18
651c = tl 42 1
652ok = and eq tl 42 14 c and eq add tl 42 3 s c eq add tl 42 7 s c
653v = add add tl 42 14 tl 42 3 tl 42 7
654if not pgate 8 ok v sub mul 3 c mul 2 s
655fail = add fail 1
656end
657v = get gwn 3
658if not pgate 9 eq v tl 51 31 v tl 51 31
659fail = add fail 1
660end
661note Gate 10 (added after the first sandbox run): every row 26 attempt ends in Omega trap 3 (exit 103).
662v = get gexit 26
663if not pgate 10 eq v tl 26 0 v tl 26 0
664fail = add fail 1
665end
666ret fail
667end
668fn argnum i ulong d ulong to ulong
669if le ulong argcnt i
670ret d
671end
672n = argread i gab 0 32
673if le n 0
674ret d
675end
676v = ulong 0
677for q ulong ulong n
678c = ulong get gab q
679if or lt c 48 gt c 57
680exit 64
681end
682v = add mul v 10 sub c 48
683end
684ret v
685end
686fn fdprobe to ulong
687fd = memfd MFN 0 len MFN 0
688if lt fd 0
689trap 13
690end
691c = fclose int fd
692if ne c 0
693rinc 4
694end
695ret ulong fd
696end
697fn main to int
698pfill
699put gres 6 fdprobe
700first = argnum 1 1
701last = argnum 2 get pn 0
702if or or eq first 0 gt first last gt last get pn 0
703exit 64
704end
705ptxth
706ptxt5
707onum get pcfg 3
708onum get pn 0
709onum get pcfg 0
710onum get pcfg 1
711onum get pcfg 2
712onum first
713onum last
714onl
715oflush
716for r ulong sub add last 1 first
717runrow add sub first 1 r
718end
719put gres 7 fdprobe
720ptxt4
721for q ulong 8
722onum get gres q
723end
724onl
725fail = ulong 0
726if and eq first 1 eq last get pn 0
727fail = gates
728end
729oflush
730ret int fail
731end