interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / device-window / race.om

574 lines · 10033 bytes Raw Blame History
1note race.om: CPU-only control for the evidence-directory step of tools/run-device-window (the
2note Omega program tools/run-device-window.om) and of its shell predecessor tools/run-device-window.sh
3note (DRA-105 F5, omega-bridge #78; DRA-441). Opens no GPU and makes no spark-window call.
4note
5note Each trial starts two device-mode runs of the program with the same new ledger id at the
6note same moment (both children block on one pipe until the parent writes). Exactly one may get
7note past the directory step: the other must exit 2 with a REFUSE line. Neither may reach a
8note window call: SPARK_WINDOW=NEGCTL-none skips the open, CUBIN_DIR names a missing directory so
9note the run that got the directory stops at the cubin copy (exit 1) before the first row, and
10note PATH=/usr/bin:/bin holds no spark-window at all. Then, on the same ledger id, a third
11note device-mode run must refuse (exit 2) and leave rc.txt and window.txt as they were, and a
12note dry-run must report EXISTS (exit 1).
13note
14note usage: race SCRIPT SCRATCH [TRIALS]
15note SCRIPT the program to test. A name ending in ".sh" is copied to SCRATCH/tools/
16note run-device-window.sh and run with /bin/sh; any other name (the compiled
17note tools/run-device-window.om) is copied to SCRATCH/tools/run-device-window with
18note mode 0755 and run directly, so it finds SCRATCH as its tree from /proc/self/exe.
19note SCRATCH a directory that must not exist yet; the caller removes it afterwards
20note TRIALS default 100
21note prints one summary line, then RACE PASS (exit 0) or RACE FAIL (exit 1); usage errors exit 2.
22note compiler: the newest omega-mv main seed/out/omc; tests/device-window/README.md has the commands.
23text tb "/usr/bin/env\nSPARK_WINDOW=NEGCTL-none\nPATH=/usr/bin:/bin\nCUBIN_DIR=\nCUDAPP=\n/bin/sh\n/tools/run-device-window.sh\n--ledger\nRACE-\n/evidence/device-window/\n/no-cubins\n/no-cudapp\n/logs/\n/rc.txt\n/window.txt\n/01-cubin-matmul.log\nREFUSE: \n/tools\n/logs\n.a\n.b\n--dry-run\nCUDA_VISIBLE_DEVICES=\nEXISTS \n.c\n.d\nRACE trials=\n one_winner=\n both_proceeded=\n both_refused=\n seq_refused=\n dryrun_exists=\n evidence_ok=\nRACE PASS\nRACE FAIL\nFAIL trial=\n exits=\nusage: race SCRIPT SCRATCH [TRIALS]; SCRATCH must not exist\n bits=\n,\nMAXPY=/nonexistent/python\n/tools/run-device-window\n"
24global ish ulong 1
25global sb uchar 4096
26global sn ulong 1
27global ap uchar 1024
28global an ulong 1
29global pk uchar 4096
30global pn ulong 2
31global fb uchar 65536
32global st uchar 4
33global ends uchar 8
34global stb uchar 128
35global lg uchar 16384
36global lgn ulong 1
37global kp ulong 2
38global tn ulong 1
39global one uchar 2
40global cnt ulong 8
41global ex long 4
42global sz long 2
43note tbpos k: kp[0] = start, kp[1] = length of entry k of tb (entries end with a newline)
44fn tbpos k ulong to void
45i = ulong 0
46e = ulong 0
47c = true
48while c bound 999999
49if ge i len tb
50c = false
51else
52if eq e k
53c = false
54else
55if eq get tb i 10
56e = add e 1
57end
58i = add i 1
59end
60end
61end
62put kp 0 i
63j = i
64d = true
65while d bound 999999
66if ge j len tb
67d = false
68else
69if eq get tb j 10
70d = false
71else
72j = add j 1
73end
74end
75end
76put kp 1 sub j i
77end
78fn sbclr to void
79put sn 0 0
80end
81fn sbc b uchar to void
82n = get sn 0
83put sb n b
84put sn 0 add n 1
85end
86fn sbk k ulong to void
87tbpos k
88s = get kp 0
89m = get kp 1
90for i ulong m
91sbc get tb add s i
92end
93end
94fn sbap to void
95for i ulong get an 0
96sbc get ap i
97end
98end
99fn sbnum v ulong to void
100d = new uchar 24 0
101n = ulong 0
102x = v
103c = true
104while c bound 30
105put d n uchar add 48 rem x 10
106n = add n 1
107x = div x 10
108if eq x 0
109c = false
110end
111end
112while gt n 0 bound 30
113n = sub n 1
114sbc get d n
115end
116end
117fn flush to void
118sbc 10
119k = write 1 sb 0 get sn 0
120sbclr
121end
122fn sayn k ulong v ulong to void
123sbk k
124sbnum v
125end
126note packet for execprog: u16 count, then records of u16 length and bytes (OMEGESE packed list)
127fn pkbeg to void
128put pn 0 2
129put pn 1 0
130end
131fn pkrec to void
132n = get sn 0
133p = get pn 0
134put pk p uchar and n 255
135put pk add p 1 uchar shr n 8
136for i ulong n
137put pk add add p 2 i get sb i
138end
139put pn 0 add add p 2 n
140put pn 1 add get pn 1 1
141sbclr
142end
143fn pkk k ulong to void
144sbk k
145pkrec
146end
147fn pkend to void
148c = get pn 1
149put pk 0 uchar and c 255
150put pk 1 uchar shr c 8
151end
152note pevid: sb = SCRATCH/evidence/device-window/RACE-<trial>
153fn pevid to void
154sbap
155sbk 9
156sbk 8
157sbnum get tn 0
158end
159note plog tag: sb = SCRATCH/logs/RACE-<trial><tag>
160fn plog tag ulong to void
161sbap
162sbk 12
163sbk 8
164sbnum get tn 0
165sbk tag
166end
167note fsz: size of the file named by sb, -1 when stat fails; clears sb
168fn fsz to long
169r = stat sb 0 get sn 0 stb 0 128
170sbclr
171if lt r 0
172ret -1
173end
174v = long 0
175for i ulong 8
176v = or shl v 8 long get stb sub 55 i
177end
178ret v
179end
180note fszp k: size of SCRATCH/evidence/device-window/RACE-<trial> + entry k
181fn fszp k ulong to long
182pevid
183sbk k
184ret fsz
185end
186note logrd tag: lg = the bytes of the run's log, lgn[0] = their count
187fn logrd tag ulong to void
188plog tag
189f = fopen sb 0 get sn 0 0 0
190sbclr
191put lgn 0 0
192if lt f 0
193ret
194end
195n = ulong 0
196c = true
197while c bound 999999
198if ge n 16384
199c = false
200else
201k = read int f lg n sub 16384 n
202if le k 0
203c = false
204else
205n = add n ulong k
206end
207end
208end
209z = fclose int f
210put lgn 0 n
211end
212fn hasat i ulong to bool
213s = get kp 0
214m = get kp 1
215for j ulong m
216if ne get lg add i j get tb add s j
217ret false
218end
219end
220ret true
221end
222note logfind tag k: does the run's log contain entry k of tb
223fn logfind tag ulong k ulong to bool
224logrd tag
225tbpos k
226m = get kp 1
227n = get lgn 0
228if lt n m
229ret false
230end
231for i ulong add sub n m 1
232if hasat i
233ret true
234end
235end
236ret false
237end
238fn fdat i ulong to int
239v = uint 0
240for j ulong 4
241v = or v shl uint get ends add i j uint mul j 8
242end
243ret int v
244end
245note spawn mode tag: fork one run of the script (mode 0 device, 1 dry-run); its stdout and
246note stderr go to SCRATCH/logs/RACE-<trial><tag>; it starts when the parent calls release
247fn spawn mode ulong tag ulong to long
248p = fork
249if ne p 0
250ret p
251end
252sbclr
253rfd = fdat 0
254k = read rfd one 0 1
255plog tag
256f = fopen sb 0 get sn 0 577 420
257sbclr
258if lt f 0
259exit 121
260end
261a = dupfd int f 1 0
262b = dupfd int f 2 0
263pkbeg
264pkk 0
265if eq mode 1
266pkk 22
267pkk 40
268else
269pkk 1
270end
271pkk 2
272sbk 3
273sbap
274sbk 10
275pkrec
276sbk 4
277sbap
278sbk 11
279pkrec
280if eq get ish 0 1
281pkk 5
282sbap
283sbk 6
284pkrec
285else
286sbap
287sbk 41
288pkrec
289end
290pkk 7
291sbk 8
292sbnum get tn 0
293pkrec
294if eq mode 1
295pkk 21
296end
297pkend
298x = execprog pk 0 get pn 0
299exit 120
300end
301fn openp to void
302r = pipefds ends 0 8 0
303if ne r 0
304exit 91
305end
306end
307fn release to void
308w = fdat 4
309k = write w one 0 2
310a = fclose fdat 0
311b = fclose w
312end
313note wexit pid: exit status of the run, 1000 + signal when it was killed, -1 when wait failed
314fn wexit p long to long
315r = waitpid int p st 0 4 0
316if lt r 0
317ret -1
318end
319if ne get st 0 0
320ret add 1000 long get st 0
321end
322ret long get st 1
323end
324note racep: the two concurrent runs; bit 1 exactly one winner (exit 1, no REFUSE) and one
325note refusal (exit 2 with REFUSE), 2 both proceeded, 4 both refused
326fn racep to ulong
327openp
328pa = spawn 0 19
329pb = spawn 0 20
330release
331ea = wexit pa
332eb = wexit pb
333put ex 0 ea
334put ex 1 eb
335fa = logfind 19 16
336fz = logfind 20 16
337res = ulong 0
338if and eq ea 2 eq eb 1
339if and fa not fz
340res = or res 1
341end
342end
343if and eq ea 1 eq eb 2
344if and fz not fa
345res = or res 1
346end
347end
348if and eq ea 1 eq eb 1
349res = or res 2
350end
351if and eq ea 2 eq eb 2
352res = or res 4
353end
354ret res
355end
356note shape: bit 32 when rc.txt is empty, window.txt was written and no row log exists
357fn shape to ulong
358w0 = fszp 14
359r0 = fszp 13
360put sz 0 w0
361put sz 1 r0
362m = fszp 15
363if gt w0 0
364if and eq r0 0 eq m -1
365ret 32
366end
367end
368ret 0
369end
370note seqp: bit 8 when a later run on the same ledger id refuses and changes nothing
371fn seqp to ulong
372openp
373pc = spawn 0 24
374release
375ec = wexit pc
376put ex 2 ec
377fc = logfind 24 16
378w1 = fszp 14
379r1 = fszp 13
380if and eq ec 2 fc
381if and eq w1 get sz 0 eq r1 get sz 1
382ret 8
383end
384end
385ret 0
386end
387note dryp: bit 16 when a dry-run on the same ledger id reports EXISTS and exits 1
388fn dryp to ulong
389openp
390pd = spawn 1 25
391release
392ed = wexit pd
393put ex 3 ed
394fx = logfind 25 23
395if and eq ed 1 fx
396ret 16
397end
398ret 0
399end
400fn sbex i ulong to void
401v = get ex i
402if lt v 0
403sbnum 999
404else
405sbnum ulong v
406end
407end
408note trial: the bits above; 57 = 1 + 8 + 16 + 32 is a pass
409fn trial to ulong
410a = racep
411b = shape
412c = seqp
413d = dryp
414res = or or or a b c d
415if ne res 57
416sayn 35 get tn 0
417sbk 36
418sbex 0
419sbk 39
420sbex 1
421sbk 39
422sbex 2
423sbk 39
424sbex 3
425sayn 38 res
426flush
427end
428ret res
429end
430fn bump i ulong to void
431put cnt i add get cnt i 1
432end
433fn mkd to void
434r = makedir sb 0 get sn 0 493
435sbclr
436if ne r 0
437sbk 37
438flush
439exit 2
440end
441end
442fn usage to void
443sbk 37
444flush
445exit 2
446end
447note setup: SCRATCH from argument 2, its tools/ and logs/ directories, and the copy of SCRIPT
448fn setup to void
449r = argread 2 ap 0 1024
450if le r 0
451usage
452end
453put an 0 ulong r
454sbap
455mkd
456sbap
457sbk 17
458mkd
459sbap
460sbk 18
461mkd
462q = argread 1 sb 0 4096
463if le q 0
464usage
465end
466put sn 0 ulong q
467put ish 0 0
468if ge q 3
469u = ulong q
470a = eq get sb sub u 3 46
471b = eq get sb sub u 2 115
472c = eq get sb sub u 1 104
473if and and a b c
474put ish 0 1
475end
476end
477f = fopen sb 0 get sn 0 0 0
478sbclr
479if lt f 0
480usage
481end
482sbap
483if eq get ish 0 1
484sbk 6
485else
486sbk 41
487end
488g = fopen sb 0 get sn 0 577 493
489sbclr
490if lt g 0
491usage
492end
493go = true
494while go bound 9223372036854775807
495k = read int f fb 0 65536
496if lt k 0
497usage
498end
499if eq k 0
500go = false
501else
502w = write int g fb 0 ulong k
503if ne w k
504usage
505end
506end
507end
508y = fclose int g
509z = fclose int f
510end
511note ntrials c: argument 3 as a decimal count, 100 when absent
512fn ntrials c long to ulong
513if lt c 4
514ret 100
515end
516y = argread 3 sb 0 32
517if le y 0
518usage
519end
520t = ulong 0
521for i ulong ulong y
522b = get sb i
523if or lt b 48 gt b 57
524usage
525end
526t = add mul t 10 ulong sub b 48
527end
528ret t
529end
530fn tally res ulong to void
531for i ulong 6
532if ne and res shl ulong 1 i 0
533bump i
534end
535end
536end
537fn main to int
538c = argcnt
539if lt c 3
540usage
541end
542setup
543trials = ntrials c
544for t ulong trials
545put tn 0 add t 1
546tally trial
547end
548sayn 26 trials
549sayn 27 get cnt 0
550sayn 28 get cnt 1
551sayn 29 get cnt 2
552sayn 30 get cnt 3
553sayn 31 get cnt 4
554sayn 32 get cnt 5
555flush
556ok = gt trials 0
557for i ulong 6
558if ne i 1
559if ne i 2
560if ne get cnt i trials
561ok = false
562end
563end
564end
565end
566if ok
567sbk 33
568flush
569ret 0
570end
571sbk 34
572flush
573ret 1
574end