code wiki / _hdl_build / nx_vram_gov_gate.nx
nx_vram_gov_gate.nx source
↩ module page · 49 lines · 3291 B
1// nx_vram_gov_gate.nx -- proves the sovereign VRAM coexistence governor (nx_vram_gov). Native, fast.
2// never-OOM admission, reject over-budget, release frees, priority eviction; the 16GB-shared scenario.
3import "nx_syscalls.nx"
4import "nx_gate_emit_lib.nx"
5import "nx_vram_gov.nx"
6import "nx_gate_verdict.nx"
7
8func main() -> i64 {
9 g_puts("nx_vram_gov gate (16GB-shared coexistence governor, never-OOM)\n" as *u8)
10 var pass: i64 = 0; var total: i64 = 0
11 let MAXT: i64 = 8
12 let gov: *i64 = sys_mmap((3 + MAXT*3) * 8) as *i64
13 vg_init(gov, 16000) // RTX 5080: 16 GB = 16000 MB
14
15 // image-gen (13.4 GB, prio 5) + companion (2 GB, prio 5) fit
16 let a1: i64 = vg_admit(gov, MAXT, 1, 13400, 5) // image-gen
17 let a2: i64 = vg_admit(gov, MAXT, 2, 2000, 5) // companion-LLM
18 pass = pass + g_check("two services fit the 16GB budget (admitted)" as *u8, (a1 == 1) & (a2 == 1) & (vg_used(gov) == 15400)); total=total+1
19
20 // a 3rd that would exceed the budget is REJECTED (never OOM)
21 let a3: i64 = vg_admit(gov, MAXT, 3, 1000, 3) // game-engine -> 16400 > 16000
22 g_puts(" [measure] used=" as *u8); g_pn(vg_used(gov)); g_puts("/16000 MB after rejecting over-budget request\n" as *u8)
23 pass = pass + g_check("over-budget request REJECTED, used never exceeds budget (never-OOM)" as *u8, (a3 == 0) & (vg_used(gov) <= 16000)); total=total+1
24
25 // release the companion -> room frees
26 vg_release(gov, 2)
27 let a4: i64 = vg_admit(gov, MAXT, 3, 1000, 3) // now the game fits (13400+1000=14400)
28 pass = pass + g_check("release frees VRAM, the queued service then fits" as *u8, (a4 == 1) & (vg_used(gov) == 14400)); total=total+1
29
30 // a HIGH-priority request that doesn't fit evicts LOWER-priority tenants to make room
31 let a5: i64 = vg_admit_evict(gov, MAXT, 9, 8000, 9) // prio 9; evicts game(prio3) then image-gen(prio5)
32 g_puts(" [measure] after high-prio admit_evict: used=" as *u8); g_pn(vg_used(gov)); g_puts(" tenants=" as *u8); g_pn(vg_count(gov)); g_puts("\n" as *u8)
33 pass = pass + g_check("high-priority request evicts lower-priority to fit (never-OOM)" as *u8, (a5 == 1) & (vg_used(gov) <= 16000) & (vg_find(gov, 9) >= 0)); total=total+1
34
35 // a low-priority request can NOT evict higher-priority (no priority inversion)
36 let a6: i64 = vg_admit_evict(gov, MAXT, 10, 12000, 1) // prio 1, doesn't fit (8000+12000>16000), can't evict prio9
37 pass = pass + g_check("low-priority can't evict higher-priority (rejected, no inversion)" as *u8, (a6 == 0) & (vg_find(gov, 9) >= 0)); total=total+1
38
39 g_puts("---- vram-gov gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
40 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
41 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
42 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
43 let ctr__dry: *i64 = gv_ctr()
44 ctr__dry[0] = pass
45 ctr__dry[1] = total
46 let rc__dry: i64 = gv_verdict("VRAM-GOV-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
47 sys_exit(rc__dry)
48 return rc__dry
49}