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 / d8_process_tax.om

1649 lines · 31277 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note tests/d8_process_tax.om -- developer bar D8, no per-process CUDA tax (docs/issues/D8-process-tax.md).
3note Compiled by the pinned seeded omc (omega-mv e5b32567, sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f).
4note Host forms checked with the omega lookup tool at that pin. It replaced tests/run_d8_process_tax.sh (CUDApp#366).
5note d8_process_tax dry-run OUTDIR HELLO HELLO_CONTROL host only: no GPU, no lease; the GPU devices hidden
6note d8_process_tax gpu OUTDIR HELLO HELLO_CONTROL GB10: one spark-window lease, three runs, judged
7note d8_process_tax check-gpu OUTDIR judges a recorded gpu run again; opens no device
8note d8_process_tax inside-window OUTDIR HELLO HELLO_CONTROL only under spark-window run (the lease holds the chip)
9note An empty OUTDIR selects build/d8-process-tax-dry-run (dry-run) or build/d8-process-tax/UTC-STAMP (gpu).
10note HELLO and HELLO_CONTROL are build/hello_gpu and build/hello_gpu_control; make builds them first.
11note Exit: 0 PASS, 1 FAIL, 2 NOT_RUN, 90 refused (arguments, a buffer bound or a failed host call).
12note
13note What is measured. hello_gpu prints its own overhead line (examples/hello_gpu/hello_gpu.c, D8): resident memory
14note (VmRSS) before the GPU opens, after it opens and with its buffers allocated, its own buffer bytes, and what the
15note session asked the driver for. With --hold-ms it prints its pid and holds its buffers; during the hold this program
16note reads the same process from outside: VmRSS from /proc/PID/status and, on the GPU, the memory the driver reports for
17note the pid (nvidia-smi --query-compute-apps, a read-only ORACLE). The measured process is build/hello_gpu itself.
18note GPU runs, all in one lease, each a separate process:
19note main hello_gpu --hold-ms=3000 must PASS the bar
20note n1-short hello_gpu_control --bug=short --hold-ms=3000 negative control: must FAIL B1
21note n2-ballast hello_gpu_control --d8-ballast-mib=512 --hold-ms=3000 negative control: the open cost must show the
22note 512 MiB held across the open, and the run must FAIL B5
23note The D8 verdict is PASS only when main passes AND both controls are caught.
24note Dry run (host simulator, hello_gpu --sim, the same line without the open): the same three runs, a device-hidden
25note run of the GPU path that must stop at NOT_RUN, the hold bound (--hold-ms=60001 refused with exit 2), the ballast
26note flag refused by the default build (exit 2), and a self-test of the GPU judge and verdict on synthetic logs
27note (labelled synthetic; they are not measurements). The dry run says nothing about the chip.
28note
29note The bar, registered before any chip run (2026-11-06, on CUDApp#280 commit 074adab1):
30note B1 run hello_gpu exits 0 and prints "checked 1048576 of 1048576 elements: 0 wrong, 0 never written" and PASS.
31note B2 line exactly one well-formed D8 line; its open cost and "beyond own buffers" equal the differences of the
32note numbers it prints; own buffers 12288 KiB (sim) or 12288..12352 KiB (a, b, c plus the code buffer).
33note B3 outside the hold line names the pid this program started, and VmRSS read from outside during the hold is within
34note 4096 KiB of the line's "with buffers" number.
35note B4 driver (GPU) the driver's per-process report lists the pid with a whole number of MiB. Missing is FAIL.
36note B5 tax TAX = max(0, open cost, resident beyond own buffers) + max(0, driver MiB x 1024 - own buffers KiB)
37note (GPU) or max(0, resident beyond own buffers) (sim), and TAX <= 262144 KiB.
38note 262144 KiB is 256 MiB (WolframLanguageEvaluator: 256*2^10 -> 262144); the pain D8 answers is about 4.6 GB per
39note model: N[4.6*10^9/(256*2^20)] -> 17.136, the bar is 17.1 times below it. The ballast is 512 MiB
40note (512*2^10 -> 524288 KiB the measurement must see).
41note
42note Host programs this driver starts, by absolute path: /usr/bin/bwrap (hides /dev/nvidia* for the dry run when the
43note nodes exist), /usr/bin/nice and /usr/bin/taskset (D8_CORES pin, default 16,17; D8_CORES= runs unpinned), and on the
44note gpu path /usr/bin/env, then spark-window, nvidia-smi, git and sha256sum found on PATH. execprog starts every child
45note with an empty environment; spark-window needs HOME and PATH, so the gpu path passes HOME, PATH, USER, LOGNAME and
46note SPARK_WINDOW_OWNER through /usr/bin/env until omega-mv has an execprog form that takes an environment.
47note There is no signal-handler form at the pin either: an interrupted gpu run leaves its lease to expire (20 minutes).
48note ---- storage (the shared part, regions and helpers, is tests/d8_lib.om). Regions here: 1 message, 4 OUTDIR,
49note 5 this program, 6 HELLO, 7 HELLO_CONTROL, 10 outside pid, 11 outside VmRSS, 12 outside driver MiB, 13 hold pid,
50note 14 failed bars, 15 lease id, 16 cores, 17 nvidia-smi, 18 spark-window, 20 child pid digits, 24 log path,
51note 25 outside path, 26 file content, 27 verdict or lease path, 28 rc digits, 31 cwd and sha256sum.
52global NV long 8
53global J long 8
54global E ulong 1
55global PF uchar 8
56global DE uchar 8192
57
58text TUse "usage: d8_process_tax dry-run OUTDIR HELLO HELLO_CONTROL | gpu OUTDIR HELLO HELLO_CONTROL | check-gpu OUTDIR\n"
59text TNL "\n"
60text TSp " "
61text TCm ", "
62text TCol ": "
63text TQm "?"
64text TPASS "PASS"
65text TFAIL "FAIL"
66text TNR "NOT_RUN"
67text TNRc "NOT_RUN: "
68text TMDry "dry-run"
69text TMHid "dry-run-hidden"
70text TMGpu "gpu"
71text TMChk "check-gpu"
72text TMIn "inside-window"
73text TDDry "build/d8-process-tax-dry-run"
74text TDGpu "build/d8-process-tax/"
75text TLog ".log"
76text TOut ".outside"
77text TCmd "# command: "
78text TUs "# utc start: "
79text TEx "# exit: "
80text TUe "# utc end: "
81text THold "hold (D8): pid "
82text TChk "checked 1048576 of 1048576 elements: 0 wrong, 0 never written"
83text TChkP "checked "
84text TNoChk "no check line"
85text TOvP "overhead (D8"
86text TNAv "not available"
87text TReG "overhead (D8): resident # KiB before open, # KiB after open, # KiB with buffers; own buffers # KiB; session driver allocations # KiB in #; open cost $ KiB, beyond own buffers $ KiB"
88text TReS "overhead (D8, simulator, no device opened): resident # KiB before buffers, # KiB with buffers; own buffers # KiB; beyond own buffers $ KiB"
89text TVmP "VmRSS:"
90text TkB " kB"
91text TPid "pid="
92text TVm "vmrss_kib="
93text TDrv "driver_mib="
94text TMiss "missing"
95text TProc "/proc/"
96text TStat "/status"
97text TRan "ran "
98text TRanE ": exit "
99text TRanV ", outside VmRSS "
100text TRanK " KiB"
101text TRanD ", driver "
102text TRanM " MiB"
103text TRunNR " run exited "
104text TRunNR2 " without a device (NOT_RUN): "
105text TB1ok "run: exit 0, 1048576 of 1048576 right, PASS"
106text TB1a "run: exit "
107text TB2a "line: "
108text TB2b " D8 lines, "
109text TB2c " well-formed (exactly one required)"
110text TB3n "outside: not judged without the line"
111text TB4n "driver: not judged without the line"
112text TB5n "tax: not judged without the line"
113text TB2r "line: resident "
114text TB2own " KiB, own "
115text TB2op " KiB, open "
116text TB2by ", beyond own "
117text TB2ok " KiB (sums agree)"
118text TB2f1 "line: printed open "
119text TB2f2 " / beyond "
120text TB2f3 " KiB disagree with its numbers, or own "
121text TB2f4 " KiB is off"
122text TB3a "outside: pid "
123text TB3b " VmRSS "
124text TB3c " KiB during the hold, line says "
125text TB3d " KiB (tolerance 4096)"
126text TB3f1 "outside: hold pid '"
127text TB3f2 "', started pid '"
128text TB3f3 "', VmRSS '"
129text TB3f4 "' KiB vs line "
130text TB4a "driver: pid "
131text TB4b " holds "
132text TB4c " MiB by the driver's report (session asked for "
133text TB4d " KiB)"
134text TB4f1 "driver: no per-process report for pid "
135text TB4f2 " ('"
136text TB4f3 "')"
137text TB5a "tax: not judged without the driver's report (resident part "
138text TB5b "tax: "
139text TB5c " KiB = resident "
140text TB5d " + driver beyond own buffers "
141text TB5e "; bar <= 262144 KiB"
142text TEx1 " ("
143text TEx2 "), expected "
144text TEx3 " by"
145text TEx4 ":\n"
146text TArr " -> "
147text TAsEx ", as expected\n"
148text TFl " (failed:"
149text TPar ")"
150text TNot ": NOT the expected "
151text TBar1 " B"
152text TSim "sim"
153text TGpuK "gpu"
154text TBalS " ballast seen: beyond own buffers +"
155text TBalS2 " KiB >= 524288 KiB\n"
156text TBalN " ballast NOT seen: beyond own buffers '"
157text TBalN2 "' KiB\n"
158text TBalG " ballast seen: open cost +"
159text TBalGN " ballast NOT seen: open cost '"
160text TBalGN2 "' KiB < 524288 KiB, the measurement is blind\n"
161text TMainH "main (gpu), the bar:\n"
162text TNoMain "no main.log in "
163text TNoMain2 ": the GPU run did not happen"
164text TMainNR "D8 PROCESS TAX: NOT_RUN (the GPU was not available inside the window)\n"
165text TTaxP "D8 PROCESS TAX: PASS (tax "
166text TTaxP2 " KiB <= 262144 KiB; both negative controls caught)\n"
167text TTaxF "D8 PROCESS TAX: FAIL (main "
168text TTaxF2 ", tax "
169text TTaxF3 " KiB"
170text TTaxF4 "; "
171text TTaxF5 " control expectation(s) not met)\n"
172text TNMain "main"
173text TNShort "n1-short"
174text TNBal "n2-ballast"
175text TSMain "sim-main"
176text TSShort "sim-short"
177text TSBal "sim-ballast"
178text THid "hidden-gpu"
179text TGood "overhead (D8): resident 2000 KiB before open, 3000 KiB after open, 15300 KiB with buffers; own buffers 12289 KiB; session driver allocations 12320 KiB in 4; open cost +1000 KiB, beyond own buffers +1011 KiB"
180text TBadS "overhead (D8): resident 2000 KiB before open, 3000 KiB after open, 15300 KiB with buffers; own buffers 12289 KiB; session driver allocations 12320 KiB in 4; open cost +1000 KiB, beyond own buffers +11 KiB"
181text TBall "overhead (D8): resident 2000 KiB before open, 527300 KiB after open, 539600 KiB with buffers; own buffers 12289 KiB; session driver allocations 12320 KiB in 4; open cost +525300 KiB, beyond own buffers +525311 KiB"
182text TSyn1 "# command: synthetic judge self-test (not a measurement)\nhello_gpu: c = a + b over 1048576 floats on the GPU, built with Omega's own kernel builder\n"
183text TSyn2 "hold (D8): pid 4242, 3000 ms with buffers allocated, for an outside reading of this process\n"
184text TSynOk "checked 1048576 of 1048576 elements: 0 wrong, 0 never written\nPASS\n"
185text TSynBad "checked 1048576 of 1048576 elements: 1 wrong, 1 never written\nFAIL\n"
186text TSynO1 "pid=4242\nvmrss_kib="
187text TSynO2 "\ndriver_mib="
188text T15310 "15310"
189text T539610 "539610"
190text T40 "40"
191text T5000 "5000"
192text T0 "0"
193text T1 "1"
194text T2 "2"
195text TSynG "syn-good"
196text TSynND "syn-no-driver"
197text TSynDT "syn-driver-tax"
198text TSynBS "syn-bad-sum"
199text TSynTL "syn-two-lines"
200text TSynNL "syn-no-line"
201text TSynE1 "syn-exit-1"
202text TSynNDv "syn-no-device"
203text TSynHd "GPU judge self-test on synthetic logs (not measurements):\n"
204text TVerHd "GPU verdict self-test on a synthetic recorded run (not a measurement):\n"
205text TSynW "/syn-window"
206text TVer "/verdict.txt"
207text TVerB "/verdict-blind.txt"
208text TVGood " good run with both controls caught -> exit "
209text TVBlind " ballast control not seen (a blind measurement) -> exit "
210text TVNot ", NOT the expected "
211text TDryP "D8 DRY RUN: PASS (host simulator, device-hidden refusal, hold bound, default-build ballast refusal, judge and verdict self-tests; the chip row stays NOT_RUN until gpu runs in a window)\n"
212text TDryF "D8 DRY RUN: FAIL ("
213text TDryF2 " expectation(s) not met)\n"
214text TBwrap "/usr/bin/bwrap"
215text TNice "/usr/bin/nice"
216text TTask "/usr/bin/taskset"
217text TEnvB "/usr/bin/env"
218text TDevB "--dev-bind"
219text TDev "--dev"
220text TDevD "/dev"
221text TProcA "--proc"
222text TProcD "/proc"
223text TDDash "--"
224text TN "-n"
225text T10 "10"
226text TC "-c"
227text TNoBw "bwrap is needed to hide the GPU devices for the dry run"
228text TDevVis "GPU device nodes are visible; the dry run must not see them"
229text TNvPre "nvidia"
230text TCoreV "D8_CORES="
231text TCoreD "16,17"
232text TSimA "--sim"
233text TH1000 "--hold-ms=1000"
234text TH3000 "--hold-ms=3000"
235text TH60001 "--hold-ms=60001"
236text TShort "--bug=short"
237text TBal512 "--d8-ballast-mib=512"
238text TBal64 "--d8-ballast-mib=64"
239text TBound "hold-bound"
240text TBGate "default-build-ballast"
241text TGateH "hello_gpu --sim "
242text TGateA " -> exit "
243text TGateE ", NOT the expected 2\n"
244text TSmiQ "--query-compute-apps=pid,used_memory"
245text TSmiF "--format=csv,noheader,nounits"
246text TSmiG "--query-gpu=name,driver_version"
247text TSmiF2 "--format=csv,noheader"
248text TSpark "spark-window"
249text TSmi "nvidia-smi"
250text TGit "git"
251text TSha "sha256sum"
252text TNoCtl "no /dev/nvidiactl here (device-hidden sandbox?)"
253text TCtl "/dev/nvidiactl"
254text TNoSw "spark-window is not installed: no lease, no run"
255text TNoSmi "nvidia-smi is not installed: B4 cannot be read"
256text TNoGit "git is not installed: env.txt cannot name the commit"
257text TNoSha "sha256sum is not installed: env.txt cannot name the binaries"
258text TEnvT "env.txt"
259text TLeaseT "lease.txt"
260text TWinT "window.log"
261text TCapT "capture.tmp"
262text TVerT "verdict.txt"
263text TGHead "git HEAD: "
264text TGStat "git status (outside evidence/): "
265text TGStat2 " changed files\n"
266text TShaH "hello_gpu sha256: "
267text TShaC "hello_gpu_control sha256: "
268text TDrvE "driver: "
269text TKern "kernel: "
270text TKernP "/proc/sys/kernel/osrelease"
271text TCores "cores: "
272text TUnpin "unpinned"
273text TBarE "bar: tax <= 262144 KiB, outside VmRSS tolerance 4096 KiB, ballast 512 MiB, hold 3000 ms\n"
274text TRevP "rev-parse"
275text THEAD "HEAD"
276text TStatus "status"
277text TPorc "--porcelain"
278text TDot "."
279text TNoEv ":!evidence"
280text TOpenR "open-request "
281text TOpen "open"
282text TName "d8-process-tax"
283text TLedg "--ledger"
284text TDRA "DRA-158"
285text TLeas "--lease"
286text T20 "20"
287text TGb "--gb10"
288text TExcl "exclusive"
289text TQuiet "--quiet"
290text TNone "none"
291text TWait "--wait"
292text TId "id"
293text TRun "run"
294text TClose "close"
295text TLease "lease "
296text TStart " start "
297text TWrc "window run rc="
298text TEnd " end "
299text TClosed "closed "
300text TNoLease "no spark-window lease"
301text TInNR "not inside an exclusive spark-window lease"
302text TSwV "SPARK_WINDOW="
303text TLockV "AIEN_GB10_LOCK_HELD="
304text THomeV "HOME="
305text TUserV "USER="
306text TLognV "LOGNAME="
307text TOwnV "SPARK_WINDOW_OWNER="
308
309fn lexit r ulong to void
310bclr r
311p = ulong 0
312while lt p get Ln 0 bound 999999
313e = lend p
314if lpre p e TEx
315q = add p len TEx
316ok = true
317while lt q e bound 4096
318c = get L q
319if or lt c 48 gt c 57
320ok = false
321end
322q = add q 1
323end
324if ok
325bclr r
326lcopy add p len TEx e r
327end
328end
329p = add e 1
330end
331end
332
333note the digits of "hold (D8): pid [0-9]*,..." lines into region r
334fn lhold r ulong to void
335bclr r
336k = ulong 0
337p = ulong 0
338while lt p get Ln 0 bound 999999
339e = lend p
340if lpre p e THold
341q = add p len THold
342while lt q e bound 4096
343c = get L q
344if or lt c 48 gt c 57
345break
346end
347q = add q 1
348end
349if lt q e
350if eq get L q 44
351if gt k 0
352bc r 10
353end
354lcopy add p len THold q r
355k = add k 1
356end
357end
358end
359p = add e 1
360end
361end
362
363note line [p, e) against a template: # is [0-9]+, $ is [+-][0-9]+; the numbers go to NV
364fn ltpl p ulong e ulong t view uchar * to bool
365k = ulong 0
366for i ulong len t
367c = get t i
368if or eq c 35 eq c 36
369ng = false
370if eq c 36
371if ge p e
372ret false
373end
374c = get L p
375if eq c 45
376ng = true
377else
378if ne c 43
379ret false
380end
381end
382p = add p 1
383end
384v = long 0
385d = ulong 0
386while lt p e bound 4096
387c = get L p
388if or lt c 48 gt c 57
389break
390end
391if ge d 18
392ret false
393end
394v = add mul v 10 long sub c 48
395d = add d 1
396p = add p 1
397end
398if eq d 0
399ret false
400end
401if ng
402v = neg v
403end
404put NV k v
405k = add k 1
406else
407if ge p e
408ret false
409end
410if ne get L p c
411ret false
412end
413p = add p 1
414end
415end
416ret eq p e
417end
418
419note lines matching the D8 template of kind (1 gpu, 0 sim); NV holds the last match
420fn lcntd8 kind ulong to ulong
421c = ulong 0
422p = ulong 0
423while lt p get Ln 0 bound 999999
424e = lend p
425if eq kind 1
426if ltpl p e TReG
427c = add c 1
428end
429else
430if ltpl p e TReS
431c = add c 1
432end
433end
434p = add e 1
435end
436ret c
437end
438
439note ---- output rows
440fn padto r ulong w ulong to void
441while lt get Bn r w bound 4096
442bc r 32
443end
444end
445
446note row: bar b, the message in region 1, ok
447fn row b ulong ok bool to void
448bs 2 TSp
449bt 2 TSp
450bc 2 66
451bu 2 b
452padto 2 5
453bt 2 TSp
454bb 2 1
455padto 2 80
456bt 2 TSp
457if ok
458bt 2 TPASS
459else
460bt 2 TFAIL
461bt 14 TBar1
462bu 14 b
463put J 7 or get J 7 long shl ulong 1 b
464end
465bt 2 TNL
466bout 1 2
467end
468
469fn brc r ulong to void
470if eq get Bn 28 0
471bt r TQm
472else
473bb r 28
474end
475end
476
477note ---- the judge. kind 1 gpu, 0 sim. J: 0 verdict (0 PASS, 1 FAIL, 2 NOT_RUN), 1 open set, 2 open, 3 beyond
478note set, 4 beyond, 5 tax set, 6 tax, 7 failed bars (bit b). NV after B2: before, open_kib, with, own, drv_alloc.
479fn judge12 kind ulong to bool
480x = fload 24
481lexit 28
482if or bist 28 T2 gt lcnt TNR 0 0
483bs 2 TRunNR
484brc 2
485bt 2 TRunNR2
486lfirst2 TNAv TNR 2
487bt 2 TNL
488bout 1 2
489put J 0 2
490ret false
491end
492ok = and and bist 28 T0 gt lcnt TChk 0 0 and gt lcnt TPASS 0 0 eq lcnt TFAIL 0 0
493if ok
494bs 1 TB1ok
495row 1 true
496else
497bs 1 TB1a
498brc 1
499bt 1 TCm
500if not lfirst TChkP 1
501bt 1 TNoChk
502end
503row 1 false
504end
505n = lcntd8 kind
506total = lcnt TOvP 1
507if or ne n 1 ne total 1
508bs 1 TB2a
509bu 1 total
510bt 1 TB2b
511bu 1 n
512bt 1 TB2c
513row 2 false
514bs 1 TB3n
515row 3 false
516if eq kind 1
517bs 1 TB4n
518row 4 false
519end
520bs 1 TB5n
521row 5 false
522put J 0 1
523ret false
524end
525ret true
526end
527
528fn judge2 kind ulong to void
529before = get NV 0
530okb = get NV 1
531with = get NV 2
532ownb = get NV 3
533opc = get NV 6
534by = get NV 7
535if eq kind 0
536okb = before
537with = get NV 1
538ownb = get NV 2
539by = get NV 3
540opc = long 0
541put NV 4 0
542end
543put NV 1 okb
544put NV 2 with
545put NV 3 ownb
546ownok = eq ownb 12288
547if eq kind 1
548ownok = and ge ownb 12288 le ownb 12352
549end
550ownok = and ownok gt before 0
551ownok = and ownok gt with 0
552ownok = and ownok eq opc sub okb before
553ownok = and ownok eq by sub sub with before ownb
554if ownok
555bs 1 TB2r
556bl 1 before
557bt 1 TSl
558bl 1 okb
559bt 1 TSl
560bl 1 with
561bt 1 TB2own
562bl 1 ownb
563bt 1 TB2op
564bl 1 opc
565bt 1 TB2by
566bl 1 by
567bt 1 TB2ok
568row 2 true
569else
570bs 1 TB2f1
571bl 1 opc
572bt 1 TB2f2
573bl 1 by
574bt 1 TB2f3
575bl 1 ownb
576bt 1 TB2f4
577row 2 false
578end
579put J 1 1
580put J 2 opc
581put J 3 1
582put J 4 by
583end
584
585fn judge3 to void
586x = fload 25
587lvals TPid 10
588lvals TVm 11
589lvals TDrv 12
590x = fload 24
591lhold 13
592with = get NV 2
593vm = bnum 11
594ok = false
595if and and gt get Bn 13 0 beq 13 10 ge vm 0
596d = sub vm with
597if lt d 0
598d = neg d
599end
600ok = le d 4096
601end
602if ok
603bs 1 TB3a
604bb 1 10
605bt 1 TB3b
606bb 1 11
607bt 1 TB3c
608bl 1 with
609bt 1 TB3d
610row 3 true
611else
612bs 1 TB3f1
613bb 1 13
614bt 1 TB3f2
615bb 1 10
616bt 1 TB3f3
617bb 1 11
618bt 1 TB3f4
619bl 1 with
620row 3 false
621end
622end
623
624fn judge45 kind ulong to void
625opc = get J 2
626rss = get J 4
627if gt opc rss
628rss = opc
629end
630if lt rss 0
631rss = long 0
632end
633drv = bnum 12
634dp = long 0
635if eq kind 1
636if ge drv 0
637bs 1 TB4a
638bb 1 10
639bt 1 TB4b
640bb 1 12
641bt 1 TB4c
642bl 1 get NV 4
643bt 1 TB4d
644row 4 true
645dp = sub mul drv 1024 get NV 3
646if lt dp 0
647dp = long 0
648end
649else
650bs 1 TB4f1
651bb 1 10
652bt 1 TB4f2
653bb 1 12
654bt 1 TB4f3
655row 4 false
656end
657end
658tax = add rss dp
659put J 5 1
660put J 6 tax
661if and eq kind 1 lt drv 0
662bs 1 TB5a
663bl 1 rss
664bt 1 TB4d
665row 5 false
666else
667bs 1 TB5b
668bl 1 tax
669bt 1 TB5c
670bl 1 rss
671bt 1 TB5d
672bl 1 dp
673bt 1 TB5e
674row 5 le tax 262144
675end
676end
677
678fn judge kind ulong nm view uchar * to void
679for i ulong 8
680put J i 0
681end
682bclr 14
683bpath 24 nm TLog
684bpath 25 nm TOut
685if not judge12 kind
686ret
687end
688judge2 kind
689judge3
690judge45 kind
691if eq get J 7 0
692put J 0 0
693else
694put J 0 1
695end
696end
697
698fn bverd r ulong v long to void
699if eq v 0
700bt r TPASS
701end
702if eq v 1
703bt r TFAIL
704end
705if eq v 2
706bt r TNR
707end
708end
709
710fn bkind r ulong kind ulong to void
711if eq kind 1
712bt r TGpuK
713else
714bt r TSim
715end
716end
717
718fn bbars r ulong mask long to void
719for b ulong 6
720if ne and mask long shl ulong 1 b 0
721bt r TBar1
722bu r b
723end
724end
725end
726
727note expect: want 0 PASS, 1 FAIL, 2 NOT_RUN; a FAIL expectation names the bars (bit b) that must be among the failed
728fn expect nm view uchar * kind ulong want long mask long to void
729bs 2 nm
730bt 2 TEx1
731bkind 2 kind
732bt 2 TEx2
733bverd 2 want
734if ne mask 0
735bt 2 TEx3
736bbars 2 mask
737end
738bt 2 TEx4
739bout 1 2
740judge kind nm
741v = get J 0
742bs 2 TArr
743bverd 2 v
744if and eq v want eq and get J 7 mask mask
745bt 2 TAsEx
746else
747if gt get Bn 14 0
748bt 2 TFl
749bb 2 14
750bt 2 TPar
751end
752bt 2 TNot
753bverd 2 want
754if ne mask 0
755bt 2 TEx3
756bbars 2 mask
757end
758bt 2 TNL
759put E 0 add get E 0 1
760end
761bout 1 2
762end
763
764fn notrun t view uchar * to void
765bs 2 TNRc
766bt 2 t
767bt 2 TNL
768bout 1 2
769exit 2
770end
771
772note ---- check-gpu
773fn checkgpu to int
774bpath 24 TNMain TLog
775if not bexists 24
776bs 2 TNRc
777bt 2 TNoMain
778bb 2 4
779bt 2 TNoMain2
780bt 2 TNL
781bout 1 2
782ret 2
783end
784put E 0 0
785say TMainH
786judge 1 TNMain
787mv = get J 0
788tset = get J 5
789tax = get J 6
790bs 2 TArr
791bverd 2 mv
792bt 2 TNL
793bout 1 2
794if eq mv 2
795say TMainNR
796ret 2
797end
798expect TNShort 1 1 2
799expect TNBal 1 1 32
800if and eq get J 1 1 ge get J 2 524288
801bs 2 TBalG
802bl 2 get J 2
803bt 2 TBalS2
804else
805bs 2 TBalGN
806if eq get J 1 1
807bl 2 get J 2
808end
809bt 2 TBalGN2
810put E 0 add get E 0 1
811end
812bout 1 2
813if and eq mv 0 eq get E 0 0
814bs 2 TTaxP
815bl 2 tax
816bt 2 TTaxP2
817bout 1 2
818ret 0
819end
820bs 2 TTaxF
821bverd 2 mv
822if eq tset 1
823bt 2 TTaxF2
824bl 2 tax
825bt 2 TTaxF3
826end
827bt 2 TTaxF4
828bu 2 get E 0
829bt 2 TTaxF5
830bout 1 2
831ret 1
832end
833
834note ---- measure: runs AL and reads it from outside during its hold. kind 1 gpu. Writes NAME.log and NAME.outside.
835note The driver's report for the pid, field 2 of nvidia-smi's "pid, used_memory" rows, into region 12.
836fn smiread pid long to void
837bclr 12
838x = pipefds PF 0 8 524288
839if ne x 0
840ret
841end
842rfd = int or long get PF 0 shl long get PF 1 8
843wfd = int or long get PF 4 shl long get PF 5 8
844alclr
845alb 17
846alt TSmiQ
847alt TSmiF
848c = spawn 2 0 wfd
849x = fclose wfd
850n = ulong 0
851while lt n len L bound 999999
852k = read rfd L n sub len L n
853if le k 0
854break
855end
856n = add n ulong k
857end
858x = fclose rfd
859w = reap c 0
860put Ln 0 n
861bclr 20
862bu 20 ulong pid
863p = ulong 0
864while lt p n bound 999999
865e = lend p
866q = p
867while lt q e bound 4096
868if eq get L q 44
869break
870end
871q = add q 1
872end
873bclr 3
874lcopy p q 3
875if lt q e
876if beq 3 20
877q = add q 1
878while lt q e bound 4096
879if ne get L q 32
880break
881end
882q = add q 1
883end
884s = q
885while lt q e bound 4096
886if eq get L q 44
887break
888end
889q = add q 1
890end
891lcopy s q 12
892ret
893end
894end
895p = add e 1
896end
897end
898
899note VmRSS of /proc/PID/status (sed 's/^VmRSS:[[:space:]]*\([0-9]*\) kB$/\1/p') into region 11
900fn vmread pid long to void
901bs 30 TProc
902bu 30 ulong pid
903bt 30 TStat
904bclr 11
905if not fload 30
906ret
907end
908p = ulong 0
909while lt p get Ln 0 bound 999999
910e = lend p
911if lpre p e TVmP
912q = add p len TVmP
913while lt q e bound 4096
914c = get L q
915if and ne c 32 ne c 9
916break
917end
918q = add q 1
919end
920s = q
921while lt q e bound 4096
922c = get L q
923if or lt c 48 gt c 57
924break
925end
926q = add q 1
927end
928if leq q e TkB
929lcopy s q 11
930end
931end
932p = add e 1
933end
934end
935
936fn holdseen to bool
937x = fload 24
938ret gt lcnt THold 1 0
939end
940
941fn measure nm view uchar * kind ulong to void
942bpath 24 nm TLog
943bpath 25 nm TOut
944bs 26 TCmd
945bcmd 26
946bt 26 TNL
947bt 26 TUs
948bstamp 26 0
949bt 26 TNL
950bfile 24 26 578
951pid = spawn 1 24 0
952rc = neg long 1
953for i ulong 600
954if holdseen
955break
956end
957rc = reap pid 1
958if ge rc 0
959break
960end
961x = sleepns 100000000
962end
963bs 11 TMiss
964bs 12 TMiss
965if holdseen
966if lt rc 0
967rc = reap pid 1
968end
969end
970if holdseen
971if lt rc 0
972vmread pid
973if eq get Bn 11 0
974bs 11 TMiss
975end
976if eq kind 1
977for t ulong 3
978smiread pid
979if gt get Bn 12 0
980break
981end
982bs 12 TMiss
983x = sleepns 300000000
984end
985end
986end
987end
988if lt rc 0
989rc = reap pid 0
990end
991bs 26 TEx
992bl 26 rc
993bt 26 TNL
994bt 26 TUe
995bstamp 26 0
996bt 26 TNL
997bfile 24 26 1089
998bs 26 TPid
999bl 26 pid
1000bt 26 TNL
1001bt 26 TVm
1002bb 26 11
1003bt 26 TNL
1004bt 26 TDrv
1005bb 26 12
1006bt 26 TNL
1007bfile 25 26 578
1008bs 2 TRan
1009bt 2 nm
1010bt 2 TRanE
1011bl 2 rc
1012bt 2 TRanV
1013bb 2 11
1014bt 2 TRanK
1015if eq kind 1
1016bt 2 TRanD
1017bb 2 12
1018bt 2 TRanM
1019end
1020bt 2 TNL
1021bout 1 2
1022end
1023
1024note ---- dry run
1025note any /dev entry named nvidia* (compgen -G '/dev/nvidia*')
1026fn devvis to bool
1027fd = fopen TDevD 0 len TDevD 0 0
1028if lt fd 0
1029ret false
1030end
1031seen = false
1032while true bound 4096
1033n = getdnts int fd DE 0 len DE
1034if le n 0
1035break
1036end
1037p = ulong 0
1038while lt p ulong n bound 8192
1039rl = add ulong get DE add p 16 shl ulong get DE add p 17 8
1040ok = true
1041for i ulong len TNvPre
1042if ne get DE add add p 19 i get TNvPre i
1043ok = false
1044end
1045end
1046if ok
1047seen = true
1048end
1049if eq rl 0
1050break
1051end
1052p = add p rl
1053end
1054end
1055x = fclose int fd
1056ret seen
1057end
1058
1059fn cores to bool
1060if envget TCoreV 16
1061ret gt get Bn 16 0
1062end
1063bs 16 TCoreD
1064ret true
1065end
1066
1067fn alpin to void
1068alt TNice
1069alt TN
1070alt T10
1071if cores
1072alt TTask
1073alt TC
1074alb 16
1075end
1076end
1077
1078note a hello run that must refuse with exit 2 (the hold bound, the ballast flag outside the control build)
1079fn refuse nm view uchar * arg view uchar * to void
1080alclr
1081alb 6
1082alt TSimA
1083alt arg
1084bpath 24 nm TLog
1085bs 26 TCmd
1086bcmd 26
1087bt 26 TNL
1088bfile 24 26 578
1089rc = runwait 1 24
1090bs 2 nm
1091bt 2 TCol
1092bt 2 TGateH
1093bt 2 arg
1094bt 2 TGateA
1095bl 2 rc
1096if eq rc 2
1097bt 2 TAsEx
1098else
1099bt 2 TGateE
1100put E 0 add get E 0 1
1101end
1102bout 1 2
1103end
1104
1105note synthetic GPU logs for the judge's self-test. line 0 none, 1 good, 2 bad sum, 3 two lines, 4 ballast
1106fn synlog p ulong line ulong bad bool rc view uchar * to void
1107bs 26 TSyn1
1108if eq line 1
1109bt 26 TGood
1110bt 26 TNL
1111end
1112if eq line 2
1113bt 26 TBadS
1114bt 26 TNL
1115end
1116if eq line 3
1117bt 26 TGood
1118bt 26 TNL
1119bt 26 TGood
1120bt 26 TNL
1121end
1122if eq line 4
1123bt 26 TBall
1124bt 26 TNL
1125end
1126bt 26 TSyn2
1127if bad
1128bt 26 TSynBad
1129else
1130bt 26 TSynOk
1131end
1132bt 26 TEx
1133bt 26 rc
1134bt 26 TNL
1135bfile p 26 578
1136end
1137
1138fn synout p ulong vm view uchar * drv view uchar * to void
1139bs 26 TSynO1
1140bt 26 vm
1141bt 26 TSynO2
1142bt 26 drv
1143bt 26 TNL
1144bfile p 26 578
1145end
1146
1147note drv 0 "40", 1 missing, 2 "5000"; rc 0, 1 or 2
1148fn syn nm view uchar * line ulong drv ulong rc ulong to void
1149bpath 24 nm TLog
1150if eq rc 0
1151synlog 24 line false T0
1152end
1153if eq rc 1
1154synlog 24 line false T1
1155end
1156if eq rc 2
1157synlog 24 line false T2
1158end
1159bpath 25 nm TOut
1160if eq drv 0
1161synout 25 T15310 T40
1162end
1163if eq drv 1
1164synout 25 T15310 TMiss
1165end
1166if eq drv 2
1167synout 25 T15310 T5000
1168end
1169end
1170
1171note check-gpu on OUTDIR/syn-window in a child, stdout to the verdict file; the exit code
1172fn verdict vf view uchar * to long
1173bclr 27
1174bb 27 4
1175bt 27 TSynW
1176bt 27 vf
1177pid = fork
1178if lt pid 0
1179bfail
1180end
1181if eq pid 0
1182f = bopen 27 578
1183if lt f 0
1184exit 90
1185end
1186x = dupfd int f 1 0
1187bt 4 TSynW
1188exit checkgpu
1189end
1190ret reap pid 0
1191end
1192
1193fn vline t view uchar * rc long want long to void
1194bs 2 t
1195bl 2 rc
1196if eq rc want
1197bt 2 TAsEx
1198else
1199bt 2 TVNot
1200bl 2 want
1201bt 2 TNL
1202put E 0 add get E 0 1
1203end
1204bout 1 2
1205end
1206
1207note path region 30 = OUTDIR/syn-window/ nm sx
1208fn swpath nm view uchar * sx view uchar * to void
1209bclr 30
1210bb 30 4
1211bt 30 TSynW
1212bt 30 TSl
1213bt 30 nm
1214bt 30 sx
1215end
1216
1217fn selftest to void
1218say TSynHd
1219syn TSynG 1 0 0
1220syn TSynND 1 1 0
1221syn TSynDT 1 2 0
1222syn TSynBS 2 0 0
1223syn TSynTL 3 0 0
1224syn TSynNL 0 0 0
1225syn TSynE1 1 0 1
1226syn TSynNDv 0 1 2
1227expect TSynG 1 0 0
1228expect TSynND 1 1 48
1229expect TSynDT 1 1 32
1230expect TSynBS 1 1 4
1231expect TSynTL 1 1 4
1232expect TSynNL 1 1 4
1233expect TSynE1 1 1 2
1234expect TSynNDv 1 2 0
1235say TVerHd
1236bclr 30
1237bb 30 4
1238bt 30 TSynW
1239x = makedir B mul ulong 30 4096 get Bn 30 493
1240swpath TNMain TLog
1241synlog 30 1 false T0
1242swpath TNMain TOut
1243synout 30 T15310 T40
1244swpath TNShort TOut
1245synout 30 T15310 T40
1246swpath TNShort TLog
1247synlog 30 1 true T1
1248swpath TNBal TLog
1249synlog 30 4 false T0
1250swpath TNBal TOut
1251synout 30 T539610 T40
1252vline TVGood verdict TVer 0
1253swpath TNBal TLog
1254synlog 30 1 false T0
1255swpath TNBal TOut
1256synout 30 T15310 T40
1257vline TVBlind verdict TVerB 1
1258end
1259
1260fn dryrun hidden bool to int
1261if not hidden
1262if devvis
1263if ne faccess TBwrap 0 len TBwrap 1 0
1264notrun TNoBw
1265end
1266alclr
1267alpin
1268alt TBwrap
1269alt TDevB
1270alt TSl
1271alt TSl
1272alt TDev
1273alt TDevD
1274alt TProcA
1275alt TProcD
1276alt TDDash
1277alb 5
1278alt TMHid
1279alb 4
1280alb 6
1281alb 7
1282put AL 0 uchar get AP 1
1283put AL 1 0
1284x = execprog AL 0 get AP 0
1285bfail
1286end
1287end
1288if devvis
1289notrun TDevVis
1290end
1291mkdirp 4
1292alclr
1293alb 6
1294alt TSimA
1295alt TH1000
1296measure TSMain 0
1297alclr
1298alb 7
1299alt TSimA
1300alt TShort
1301alt TH1000
1302measure TSShort 0
1303alclr
1304alb 7
1305alt TSimA
1306alt TBal512
1307alt TH1000
1308measure TSBal 0
1309alclr
1310alb 6
1311alt TH1000
1312measure THid 1
1313put E 0 0
1314expect TSMain 0 0 0
1315expect TSShort 0 1 2
1316expect TSBal 0 1 32
1317if and eq get J 3 1 ge get J 4 524288
1318bs 2 TBalS
1319bl 2 get J 4
1320bt 2 TBalS2
1321else
1322bs 2 TBalN
1323if eq get J 3 1
1324bl 2 get J 4
1325end
1326bt 2 TBalN2
1327put E 0 add get E 0 1
1328end
1329bout 1 2
1330expect THid 1 2 0
1331refuse TBound TH60001
1332refuse TBGate TBal64
1333selftest
1334if eq get E 0 0
1335say TDryP
1336ret 0
1337end
1338bs 2 TDryF
1339bu 2 get E 0
1340bt 2 TDryF2
1341bout 1 2
1342ret 1
1343end
1344
1345note ---- inside the window and the gpu run
1346fn inside to int
1347if not envget TSwV 3
1348notrun TInNR
1349end
1350if eq get Bn 3 0
1351notrun TInNR
1352end
1353if not envget TLockV 3
1354notrun TInNR
1355end
1356if not bist 3 T1
1357notrun TInNR
1358end
1359alclr
1360alb 6
1361alt TH3000
1362measure TNMain 1
1363alclr
1364alb 7
1365alt TShort
1366alt TH3000
1367measure TNShort 1
1368alclr
1369alb 7
1370alt TBal512
1371alt TH3000
1372measure TNBal 1
1373ret 0
1374end
1375
1376fn alenv to void
1377alclr
1378alt TEnvB
1379envkv THomeV
1380envkv TPathV
1381envkv TUserV
1382envkv TLognV
1383envkv TOwnV
1384alb 18
1385end
1386
1387note runs AL with stdout and stderr to region 29's file; region 3 gets the output without trailing newlines
1388fn shafield r ulong to void
1389for i ulong get Bn 3
1390c = get B add mul ulong 3 4096 i
1391if eq c 32
1392break
1393end
1394bc r c
1395end
1396bt r TNL
1397end
1398
1399note env.txt: the commit, the binaries, the driver, the kernel, the pin and the bar. git and sha256sum are in 19/31.
1400fn envtxt to void
1401bpath1 29 TCapT
1402bs 26 TGHead
1403alclr
1404alb 19
1405alt TRevP
1406alt THEAD
1407x = capture
1408bb 26 3
1409bt 26 TNL
1410bt 26 TGStat
1411alclr
1412alb 19
1413alt TStatus
1414alt TPorc
1415alt TDDash
1416alt TDot
1417alt TNoEv
1418x = capture
1419c = ulong 0
1420if gt get Bn 3 0
1421c = ulong 1
1422end
1423for i ulong get Bn 3
1424if eq get B add mul ulong 3 4096 i 10
1425c = add c 1
1426end
1427end
1428bu 26 c
1429bt 26 TGStat2
1430bt 26 TShaH
1431alclr
1432alb 31
1433alb 6
1434x = capture
1435shafield 26
1436bt 26 TShaC
1437alclr
1438alb 31
1439alb 7
1440x = capture
1441shafield 26
1442bt 26 TDrvE
1443alclr
1444alb 17
1445alt TSmiG
1446alt TSmiF2
1447x = capture
1448bb 26 3
1449bt 26 TNL
1450bt 26 TKern
1451bs 30 TKernP
1452if fload 30
1453n = get Ln 0
1454while gt n 0 bound 4096
1455if ne get L sub n 1 10
1456break
1457end
1458n = sub n 1
1459end
1460lcopy 0 n 26
1461end
1462bt 26 TNL
1463bt 26 TCores
1464if cores
1465bb 26 16
1466else
1467bt 26 TUnpin
1468end
1469bt 26 TNL
1470bt 26 TBarE
1471bpath1 30 TEnvT
1472bfile 30 26 578
1473end
1474
1475fn lnote p ulong t view uchar * t2 view uchar * to void
1476bs 26 t
1477bb 26 15
1478bt 26 t2
1479bstamp 26 1
1480bt 26 TNL
1481bfile p 26 1089
1482end
1483
1484fn gpurun to int
1485if not bexists 30
1486notrun TNoCtl
1487end
1488if not which TSpark
1489notrun TNoSw
1490end
1491bclr 18
1492bb 18 19
1493if not which TSmi
1494notrun TNoSmi
1495end
1496bclr 17
1497bb 17 19
1498if not which TSha
1499notrun TNoSha
1500end
1501bclr 31
1502bb 31 19
1503if not which TGit
1504notrun TNoGit
1505end
1506mkdirp 4
1507envtxt
1508bpath1 27 TLeaseT
1509bs 26 TOpenR
1510bstamp 26 1
1511bt 26 TNL
1512bfile 27 26 578
1513alenv
1514alt TOpen
1515alt TName
1516alt TLedg
1517alt TDRA
1518alt TLeas
1519alt T20
1520alt TGb
1521alt TExcl
1522alt TQuiet
1523alt TNone
1524alt TWait
1525rc = runwait 1 27
1526bpath1 29 TCapT
1527alenv
1528alt TId
1529rc = capture
1530bclr 15
1531if eq rc 0
1532bb 15 3
1533end
1534if eq get Bn 15 0
1535catfile 27
1536notrun TNoLease
1537end
1538lnote 27 TLease TStart
1539bpath1 29 TWinT
1540alenv
1541alt TRun
1542alpin
1543alb 5
1544alt TMIn
1545alb 4
1546alb 6
1547alb 7
1548bclr 3
1549bfile 29 3 578
1550pid = spawn 1 29 0
1551t0 = monons
1552rc = neg long 1
1553while lt rc 0 bound 999999
1554rc = reap pid 1
1555if lt rc 0
1556if gt sub monons t0 1080000000000
1557x = killpid int pid 15
1558rc = reap pid 0
1559rc = long 124
1560else
1561x = sleepns 100000000
1562end
1563end
1564end
1565bs 26 TWrc
1566bl 26 rc
1567bt 26 TEnd
1568bstamp 26 1
1569bt 26 TNL
1570bfile 27 26 1089
1571alenv
1572alt TClose
1573alb 15
1574rc = runwait 1 27
1575bs 3 TClosed
1576lnote 27 TClosed TSp
1577catfile 29
1578bpath1 27 TVerT
1579pid = fork
1580if lt pid 0
1581bfail
1582end
1583if eq pid 0
1584f = bopen 27 578
1585if lt f 0
1586exit 90
1587end
1588x = dupfd int f 1 0
1589exit checkgpu
1590end
1591v = reap pid 0
1592catfile 27
1593ret int v
1594end
1595
1596fn main to int
1597c = argcnt
1598if lt c 3
1599r = write 2 TUse 0 len TUse
1600ret 2
1601end
1602barg 0 5
1603barg 1 3
1604barg 2 4
1605if ne get B mul ulong 5 4096 47
1606k = cwd B mul ulong 31 4096 4095
1607if le k 0
1608bfail
1609end
1610put Bn 31 sub ulong k 1
1611bt 31 TSl
1612bb 31 5
1613bclr 5
1614bb 5 31
1615end
1616if ge c 5
1617barg 3 6
1618barg 4 7
1619end
1620if bist 3 TMChk
1621ret checkgpu
1622end
1623if lt c 5
1624r = write 2 TUse 0 len TUse
1625ret 2
1626end
1627if bist 3 TMDry
1628if eq get Bn 4 0
1629bs 4 TDDry
1630end
1631ret dryrun false
1632end
1633if bist 3 TMHid
1634ret dryrun true
1635end
1636if bist 3 TMIn
1637ret inside
1638end
1639if bist 3 TMGpu
1640if eq get Bn 4 0
1641bs 4 TDGpu
1642bstamp 4 2
1643end
1644bs 30 TCtl
1645ret gpurun
1646end
1647r = write 2 TUse 0 len TUse
1648ret 2
1649end