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

862 lines · 14891 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note tests/abft/driver.om: DRA-420/DRA-387 GEMM fault-detection evaluator driver, seeded Omega. It
4note checks the compiler pin and the frozen plan hash, builds build/abft/abft and cul1-unit with the
5note pinned omc, runs the CUL1 unit and the evaluator, and prints the evaluator's GATE lines.
6note From the repository root:
7note mkdir -p build && "$OMEGA_OMC" < tests/abft/driver.om > build/abft-driver
8note chmod +x build/abft-driver && OMEGA_OMC=/abs/omega-mv/seed/out/omc build/abft-driver [OUT_DIR] [FIRST LAST]
9note OMEGA_OMC must be omega-mv e5b32567 seed/out/omc (sha256 PIN); any other compiler is refused.
10note Exit: 0 every step and gate passed; 2 OMEGA_OMC unset; 1 pin, frozen-hash, input or output
11note failure; otherwise the failing step's status (omc, cul1-unit, then the evaluator: its failed
12note gate count, 64 for bad arguments). A signalled child is 128 + signal. Children get an empty
13note environment and inherit stdin and stderr.
14
15text pinhex "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f"
16text envkey "OMEGA_OMC="
17text frozen "tests/abft/FROZEN.sha256"
18text defout "build/abft"
19text slash "/"
20text two " "
21text nl "\n"
22text p1 "tests/abft/frozen.om"
23text p2 "native/abft/lib.om"
24text p3 "native/abft/check.om"
25text p4 "native/abft/cand.om"
26text p5 "native/abft/sched.om"
27text p6 "native/abft/run.om"
28text q1 "native/learn53/task.om"
29text q2 "tests/learn53/fixtures.om"
30text q3 "native/abft/cul1.om"
31text q4 "tests/abft/cul1-unit.om"
32text nabft "abft"
33text nabsrc "abft.om"
34text nabtmp "abft.tmp"
35text nculu "cul1-unit"
36text ncusrc "cul1-unit.om"
37text ncutmp "cul1-unit.tmp"
38text nlog "abft.log"
39text gatep "GATE"
40text enoomc "OMEGA_OMC: set OMEGA_OMC to the pinned omega-mv e5b32567 seed/out/omc\n"
41text epin "abft: OMEGA_OMC is not the pinned omc "
42text efrz "abft: FAILED "
43text enofrz "abft: no properly formatted lines in tests/abft/FROZEN.sha256\n"
44text eread "abft: cannot read "
45text ewrite "abft: cannot write "
46text emkdir "abft: cannot create "
47text ebig "abft: input or argument too large\n"
48text eproc "abft: fork or wait failed\n"
49
50global pb uchar 4096
51global pbn ulong 1
52global ob uchar 4096
53global obn ulong 1
54global cp uchar 4096
55global cpn ulong 1
56note ab holds one whole environment entry: Linux refuses any longer than 32 pages (131072 bytes on
57note 4 KiB pages, 2097152 on 64 KiB), so envread never returns -105 and a long OMEGA_OMC is not unset
58global ab uchar 2097152
59global av uchar 16384
60global avp ulong 1
61global avc ulong 1
62global avl ulong 1
63global fa uchar 4194304
64global fan ulong 1
65global fb uchar 4194304
66global fbn ulong 1
67global hexd uchar 64
68global stb uchar 4
69global kk uint 64
70global ivs uint 8
71global hv uint 8
72global ws uint 64
73global st uint 8
74global blk uchar 64
75global bk ulong 2
76
77note ---- output ------------------------------------------------------------------------------
78fn say t view uchar * to void
79r = write 1 t 0 len t
80end
81
82fn esay t view uchar * to void
83r = write 2 t 0 len t
84end
85
86fn die t view uchar * to void
87esay t
88exit 1
89end
90
91note stderr: T, then the path pb, then a newline; exit 1
92fn diep t view uchar * to void
93esay t
94r = write 2 pb 0 get pbn 0
95esay nl
96exit 1
97end
98
99note ---- paths: pb is the working path, ob the output directory --------------------------------
100fn pclear to void
101put pbn 0 0
102end
103
104fn pcat t view uchar * to void
105p = get pbn 0
106n = len t
107if gt add p n 4095
108die ebig
109end
110for i ulong n
111put pb add p i get t i
112end
113put pbn 0 add p n
114end
115
116note pb = OUT/NAME
117fn opath t view uchar * to void
118n = get obn 0
119for i ulong n
120put pb i get ob i
121end
122put pbn 0 n
123pcat slash
124pcat t
125end
126
127fn opr to long
128ret fopen pb 0 get pbn 0 0 0
129end
130
131fn opw to long
132ret fopen pb 0 get pbn 0 577 438
133end
134
135fn fclo fd long to void
136if ge fd 0
137r = fclose int fd
138end
139end
140
141note ---- packed argument list ---------------------------------------------------------------
142fn areset to void
143put avc 0 0
144put avp 0 2
145put av 0 0
146put av 1 0
147end
148
149fn afix to void
150p = get avp 0
151q = get avl 0
152m = sub sub p q 2
153if gt m 65535
154die ebig
155end
156put av q uchar and m 255
157put av add q 1 uchar shr m 8
158end
159
160fn anew to void
161p = get avp 0
162if gt add p 2 len av
163die ebig
164end
165put avl 0 p
166put avp 0 add p 2
167c = add get avc 0 1
168put avc 0 c
169put av 0 uchar and c 255
170put av 1 uchar shr c 8
171afix
172end
173
174note append the path pb to the current record
175fn apb to void
176p = get avp 0
177n = get pbn 0
178if gt add p n len av
179die ebig
180end
181for i ulong n
182put av add p i get pb i
183end
184put avp 0 add p n
185afix
186end
187
188note append argument I of this process as a new record
189fn aarg i ulong to void
190anew
191p = get avp 0
192n = argread i av p sub len av p
193if lt n 0
194die ebig
195end
196put avp 0 add p ulong n
197afix
198end
199
200note ---- children ---------------------------------------------------------------------------
201note run the argument list; a negative descriptor is inherited. Shell-style status.
202fn spawn fi int fo int to ulong
203pid = fork
204if lt pid 0
205die eproc
206end
207if eq pid 0
208if ge fi 0
209r = dupfd fi 0 0
210end
211if ge fo 0
212r = dupfd fo 1 0
213end
214r = execprog av 0 get avp 0
215if eq r -2
216exit 127
217end
218exit 126
219end
220r = waitpid int pid stb 0 4 0
221if ne r pid
222die eproc
223end
224sg = and ulong get stb 0 127
225if eq sg 0
226ret ulong get stb 1
227end
228ret add sg 128
229end
230
231note ---- files ------------------------------------------------------------------------------
232note fb = the bytes of the file pb; false when it cannot be read
233fn rdb to bool
234put fbn 0 0
235fd = opr
236if lt fd 0
237ret false
238end
239n = ulong 0
240while true bound 999999
241if eq n len fb
242die ebig
243end
244r = read int fd fb n sub len fb n
245if lt r 0
246fclo fd
247ret false
248end
249if eq r 0
250break
251end
252n = add n ulong r
253end
254fclo fd
255put fbn 0 n
256ret true
257end
258
259note append the file T to fa; exit 1 when it cannot be read (cat under set -e)
260fn cata t view uchar * to void
261pclear
262pcat t
263fd = opr
264if lt fd 0
265diep eread
266end
267n = get fan 0
268while true bound 999999
269if eq n len fa
270die ebig
271end
272r = read int fd fa n sub len fa n
273if lt r 0
274fclo fd
275diep eread
276end
277if eq r 0
278break
279end
280n = add n ulong r
281end
282fclo fd
283put fan 0 n
284end
285
286note write fa to the file pb
287fn wrfa to void
288fd = opw
289if lt fd 0
290diep ewrite
291end
292n = get fan 0
293o = ulong 0
294while lt o n bound 999999
295r = write int fd fa o sub n o
296if le r 0
297fclo fd
298diep ewrite
299end
300o = add o ulong r
301end
302r = fclose int fd
303if ne r 0
304diep ewrite
305end
306end
307
308note ---- SHA-256 (FIPS 180-4) ----------------------------------------------------------------
309note SHA-256 (FIPS 180-4) constants, copied from om/cache/digest.om kc_k and kc_iv
310fn shainit to void
311put kk 0 1116352408
312put kk 1 1899447441
313put kk 2 3049323471
314put kk 3 3921009573
315put kk 4 961987163
316put kk 5 1508970993
317put kk 6 2453635748
318put kk 7 2870763221
319put kk 8 3624381080
320put kk 9 310598401
321put kk 10 607225278
322put kk 11 1426881987
323put kk 12 1925078388
324put kk 13 2162078206
325put kk 14 2614888103
326put kk 15 3248222580
327put kk 16 3835390401
328put kk 17 4022224774
329put kk 18 264347078
330put kk 19 604807628
331put kk 20 770255983
332put kk 21 1249150122
333put kk 22 1555081692
334put kk 23 1996064986
335put kk 24 2554220882
336put kk 25 2821834349
337put kk 26 2952996808
338put kk 27 3210313671
339put kk 28 3336571891
340put kk 29 3584528711
341put kk 30 113926993
342put kk 31 338241895
343put kk 32 666307205
344put kk 33 773529912
345put kk 34 1294757372
346put kk 35 1396182291
347put kk 36 1695183700
348put kk 37 1986661051
349put kk 38 2177026350
350put kk 39 2456956037
351put kk 40 2730485921
352put kk 41 2820302411
353put kk 42 3259730800
354put kk 43 3345764771
355put kk 44 3516065817
356put kk 45 3600352804
357put kk 46 4094571909
358put kk 47 275423344
359put kk 48 430227734
360put kk 49 506948616
361put kk 50 659060556
362put kk 51 883997877
363put kk 52 958139571
364put kk 53 1322822218
365put kk 54 1537002063
366put kk 55 1747873779
367put kk 56 1955562222
368put kk 57 2024104815
369put kk 58 2227730452
370put kk 59 2361852424
371put kk 60 2428436474
372put kk 61 2756734187
373put kk 62 3204031479
374put kk 63 3329325298
375put ivs 0 1779033703
376put ivs 1 3144134277
377put ivs 2 1013904242
378put ivs 3 2773480762
379put ivs 4 1359893119
380put ivs 5 2600822924
381put ivs 6 528734635
382put ivs 7 1541459225
383end
384
385fn shasched to void
386for i ulong 16
387b = mul i 4
388v = shl uint get blk b 24
389v = or v shl uint get blk add b 1 16
390v = or v shl uint get blk add b 2 8
391v = or v uint get blk add b 3
392put ws i v
393end
394for j ulong 48
395q = add j 16
396x = get ws sub q 15
397y = get ws sub q 2
398s0 = xor xor rotr x 7 rotr x 18 shr x 3
399s1 = xor xor rotr y 17 rotr y 19 shr y 10
400put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1
401end
402end
403
404fn shat1 i ulong to uint
405e = get st 4
406s1 = xor xor rotr e 6 rotr e 11 rotr e 25
407ch = xor and e get st 5 and not e get st 6
408ret add add add add get st 7 s1 ch get kk i get ws i
409end
410
411fn shat2 to uint
412a = get st 0
413b = get st 1
414c = get st 2
415s0 = xor xor rotr a 2 rotr a 13 rotr a 22
416mj = xor xor and a b and a c and b c
417ret add s0 mj
418end
419
420fn shacomp to void
421shasched
422for i ulong 8
423put st i get hv i
424end
425for i ulong 64
426t1 = shat1 i
427t2 = shat2
428put st 7 get st 6
429put st 6 get st 5
430put st 5 get st 4
431put st 4 add get st 3 t1
432put st 3 get st 2
433put st 2 get st 1
434put st 1 get st 0
435put st 0 add t1 t2
436end
437for i ulong 8
438put hv i add get hv i get st i
439end
440end
441
442fn shabyte b uchar to void
443n = get bk 0
444put blk n b
445n = add n 1
446if eq n 64
447shacomp
448n = ulong 0
449end
450put bk 0 n
451put bk 1 add get bk 1 1
452end
453
454fn hexch v uint to uchar
455if lt v 10
456ret uchar add v 48
457end
458ret uchar add v 87
459end
460
461fn shafinal to void
462bits = mul get bk 1 8
463shabyte 128
464while ne get bk 0 56 bound 64
465shabyte 0
466end
467for i ulong 8
468shabyte uchar and shr bits mul sub 7 i 8 255
469end
470for i ulong 8
471v = get hv i
472for j ulong 8
473put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15
474end
475end
476end
477
478note hexd = sha256 of the file pb; false when it cannot be read
479fn hashpb to bool
480fd = opr
481if lt fd 0
482ret false
483end
484m = new uchar 4096 0
485for i ulong 8
486put hv i get ivs i
487end
488put bk 0 0
489put bk 1 0
490while true
491r = read int fd m 0 len m
492if lt r 0
493fclo fd
494ret false
495end
496if eq r 0
497fclo fd
498shafinal
499ret true
500end
501for i ulong ulong r
502shabyte get m i
503end
504end
505ret false
506end
507
508note print "HEX OUT/NAME" (sha256sum)
509fn sumln t view uchar * to void
510opath t
511if hashpb
512r = write 1 hexd 0 64
513say two
514r = write 1 pb 0 get pbn 0
515say nl
516else
517diep eread
518end
519end
520
521note ---- steps ------------------------------------------------------------------------------
522note cp = the value of OMEGA_OMC (empty when unset)
523fn envomc to void
524put cpn 0 0
525c = envcnt
526for i ulong ulong c
527n = envread i ab 0 len ab
528if gt n long len envkey
529if pfx
530k = sub ulong n len envkey
531note host words trap 3 on a path longer than 4095 bytes (OMEGESE, paths)
532if gt k 4095
533die ebig
534end
535for j ulong k
536put cp j get ab add len envkey j
537end
538put cpn 0 k
539ret
540end
541end
542end
543end
544
545note ab starts with OMEGA_OMC=
546fn pfx to bool
547for j ulong len envkey
548if ne get ab j get envkey j
549ret false
550end
551end
552ret true
553end
554
555note ob = argument 1 when it is not empty (${1:-build/abft}), else build/abft
556fn outset to void
557put obn 0 0
558if gt ulong argcnt 1
559n = argread 1 ob 0 len ob
560if or lt n 0 gt n 4095
561die ebig
562end
563put obn 0 ulong n
564end
565if eq get obn 0 0
566for i ulong len defout
567put ob i get defout i
568end
569put obn 0 len defout
570end
571end
572
573note mkdir -p ob
574fn mkout to void
575n = get obn 0
576for i ulong n
577if eq get ob i 47
578if gt i 0
579r = makedir ob 0 i 511
580end
581end
582end
583r = makedir ob 0 n 511
584if and ne r 0 ne r -17
585for i ulong n
586put pb i get ob i
587end
588put pbn 0 n
589diep emkdir
590end
591end
592
593note one FROZEN line [s, e): the hash of the file fb[s+66 .. e) must equal fb[s .. s+64)
594fn frzone s ulong e ulong to void
595k = sub e add s 66
596if gt k 4095
597die ebig
598end
599for i ulong k
600put pb i get fb add add s 66 i
601end
602put pbn 0 k
603g = false
604if hashpb
605g = true
606for i ulong 64
607if ne get hexd i get fb add s i
608g = false
609end
610end
611end
612if g
613else
614diep efrz
615end
616end
617
618note sha256sum -c tests/abft/FROZEN.sha256: every "HEX PATH" line must match; malformed lines are
619note skipped, and a file with no well-formed line fails
620fn frzchk to void
621pclear
622pcat frozen
623if rdb
624else
625diep eread
626end
627nf = ulong 0
628s = ulong 0
629n = get fbn 0
630while lt s n bound 999999
631e = lend s
632if frzwell s e
633frzone s e
634nf = add nf 1
635end
636s = add e 1
637end
638if eq nf 0
639die enofrz
640end
641end
642
643note index of the next newline at or after s in fb, or the end of fb
644fn lend s ulong to ulong
645n = get fbn 0
646for i ulong sub n s
647if eq get fb add s i 10
648ret add s i
649end
650end
651ret n
652end
653
654note line [s, e) is 64 lowercase hex digits, two spaces and a nonempty path
655fn frzwell s ulong e ulong to bool
656if le e add s 66
657ret false
658end
659for i ulong 64
660c = get fb add s i
661if or lt c 48 gt c 102
662ret false
663end
664if and gt c 57 lt c 97
665ret false
666end
667end
668if ne get fb add s 64 32
669ret false
670end
671ret eq get fb add s 65 32
672end
673
674note compile OUT/SRC (written from fa) with the pinned omc into OUT/TMP, make it executable and
675note rename it to OUT/BIN; a compile failure exits with omc's status
676fn build src view uchar * tmp view uchar * bin view uchar * to void
677opath src
678wrfa
679fi = opr
680if lt fi 0
681diep eread
682end
683opath tmp
684fo = opw
685if lt fo 0
686fclo fi
687diep ewrite
688end
689areset
690anew
691apcp
692s = spawn int fi int fo
693fclo fi
694fclo fo
695if ne s 0
696exit int s
697end
698opath tmp
699r = chmx
700if ne r 0
701diep ewrite
702end
703rnm tmp bin
704end
705
706note chmod +x pb: add every execute bit the umask allows, as the shell does
707fn chmx to long
708um = int umask 18
709r = umask um
710ret chmod pb 0 get pbn 0 and 511 not um
711end
712
713note append the compiler path cp to the current record
714fn apcp to void
715p = get avp 0
716n = get cpn 0
717if gt add p n len av
718die ebig
719end
720for i ulong n
721put av add p i get cp i
722end
723put avp 0 add p n
724afix
725end
726
727note rename OUT/A to OUT/B
728fn rnm a view uchar * b view uchar * to void
729areset
730opath a
731anew
732apb
733opath b
734anew
735apb
736r = renames av 0 get avp 0 0
737if ne r 0
738diep ewrite
739end
740end
741
742note print every line of fb that starts with GATE
743fn gates to void
744n = get fbn 0
745s = ulong 0
746while lt s n bound 999999
747e = lend s
748if gatln s e
749r = write 1 fb s sub e s
750say nl
751end
752s = add e 1
753end
754end
755
756fn gatln s ulong e ulong to bool
757if lt sub e s len gatep
758ret false
759end
760for i ulong len gatep
761if ne get fb add s i get gatep i
762ret false
763end
764end
765ret true
766end
767
768note pb = the compiler; its sha256 must be the pin
769fn pinchk to void
770n = get cpn 0
771for i ulong n
772put pb i get cp i
773end
774put pbn 0 n
775g = false
776if hashpb
777g = true
778for i ulong 64
779if ne get hexd i get pinhex i
780g = false
781end
782end
783end
784if g
785else
786diep epin
787end
788end
789
790fn bldabft to void
791put fan 0 0
792cata p1
793cata p2
794cata p3
795cata p4
796cata p5
797cata p6
798build nabsrc nabtmp nabft
799end
800
801fn bldcul1 to void
802put fan 0 0
803cata q1
804cata q2
805cata q3
806cata q4
807build ncusrc ncutmp nculu
808end
809
810note OUT/abft with the arguments after OUT_DIR, stdout to OUT/abft.log; then the GATE lines
811fn runabft to ulong
812areset
813opath nabft
814anew
815apb
816c = ulong argcnt
817i = ulong 2
818while lt i c bound 65536
819aarg i
820i = add i 1
821end
822opath nlog
823fo = opw
824rc = ulong 1
825if ge fo 0
826rc = spawn -1 int fo
827fclo fo
828end
829opath nlog
830if rdb
831gates
832end
833ret rc
834end
835
836fn main to int
837envomc
838if eq get cpn 0 0
839esay enoomc
840ret 2
841end
842shainit
843outset
844mkout
845pinchk
846frzchk
847bldabft
848bldcul1
849sumln nabft
850sumln nculu
851sumln nabsrc
852sumln ncusrc
853areset
854opath nculu
855anew
856apb
857s = spawn -1 -1
858if ne s 0
859ret int s
860end
861ret int runabft
862end