code wiki / _hdl_build / nx_vram_gov_gate.nx

nx_vram_gov_gate.nx source

↩ module page · 41 lines · 2849 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" 6 7func main() -> i64 { 8 g_puts("nx_vram_gov gate (16GB-shared coexistence governor, never-OOM)\n" as *u8) 9 var pass: i64 = 0; var total: i64 = 0 10 let MAXT: i64 = 8 11 let gov: *i64 = sys_mmap((3 + MAXT*3) * 8) as *i64 12 vg_init(gov, 16000) // RTX 5080: 16 GB = 16000 MB 13 14 // image-gen (13.4 GB, prio 5) + companion (2 GB, prio 5) fit 15 let a1: i64 = vg_admit(gov, MAXT, 1, 13400, 5) // image-gen 16 let a2: i64 = vg_admit(gov, MAXT, 2, 2000, 5) // companion-LLM 17 pass = pass + g_check("two services fit the 16GB budget (admitted)" as *u8, (a1 == 1) & (a2 == 1) & (vg_used(gov) == 15400)); total=total+1 18 19 // a 3rd that would exceed the budget is REJECTED (never OOM) 20 let a3: i64 = vg_admit(gov, MAXT, 3, 1000, 3) // game-engine -> 16400 > 16000 21 g_puts(" [measure] used=" as *u8); g_pn(vg_used(gov)); g_puts("/16000 MB after rejecting over-budget request\n" as *u8) 22 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 23 24 // release the companion -> room frees 25 vg_release(gov, 2) 26 let a4: i64 = vg_admit(gov, MAXT, 3, 1000, 3) // now the game fits (13400+1000=14400) 27 pass = pass + g_check("release frees VRAM, the queued service then fits" as *u8, (a4 == 1) & (vg_used(gov) == 14400)); total=total+1 28 29 // a HIGH-priority request that doesn't fit evicts LOWER-priority tenants to make room 30 let a5: i64 = vg_admit_evict(gov, MAXT, 9, 8000, 9) // prio 9; evicts game(prio3) then image-gen(prio5) 31 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) 32 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 33 34 // a low-priority request can NOT evict higher-priority (no priority inversion) 35 let a6: i64 = vg_admit_evict(gov, MAXT, 10, 12000, 1) // prio 1, doesn't fit (8000+12000>16000), can't evict prio9 36 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 37 38 g_puts("---- vram-gov gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 39 if pass == total { g_puts("verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 40 g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 41}