code wiki / _hdl_build / nx_gpu_power_gate.nx
nx_gpu_power_gate.nx source
↩ module page · 40 lines · 3057 B
1// nx_gpu_power_gate.nx -- gate for the sovereign GPU power/thermal governor (nx_gpu_power) = the NEVER-FRY rung.
2// KATs the governor logic on the REAL 5080 range (pmin=5W, pmax=175W; thermal warn=75C, crit=90C): clamp,
3// thermal-derate, and the load-bearing EMERGENCY cap (at/above critical temp -> minimum power = can't fry).
4// Pure integer logic, locally verifiable; applying the cap = device shim RM_CONTROL / nvidia-smi (cloud/admin).
5// No hw writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_gpu_power.nx"
8
9func bp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func bn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
11func bd(v: i64) -> i64 { let p: *u8=sys_mmap(1); p[0]=(48+v) as u8; sys_write(1,p,1); return 0 }
12
13func chk(name: *u8, got: i64, ref: i64, st: *i64) -> i64 {
14 bp(" " as *u8); bp(name); bp(" -> " as *u8); bn(got); bp("W" as *u8)
15 if got==ref { bp(" == expect PASS\n" as *u8); st[0]=st[0]+1; return 0 }
16 bp(" != expect " as *u8); bn(ref); bp(" FAIL\n" as *u8); return 0
17}
18
19func main() -> i64 {
20 bp("=== sovereign GPU power/thermal governor (nx_gpu_power) -- NEVER-FRY by construction (rule #26) ===\n" as *u8)
21 bp(" real 5080 range: pmin=5W pmax=175W default=80W; policy warn=75C crit=90C\n" as *u8)
22 let st: *i64 = sys_mmap(8); st[0]=0
23 chk("cool 100W@50C (pass-through) " as *u8, nx_power_governor(100, 5, 175, 50, 75, 90), 100, st)
24 chk("clamp-to-max 200W@50C " as *u8, nx_power_governor(200, 5, 175, 50, 75, 90), 175, st)
25 chk("clamp-to-min 2W@50C " as *u8, nx_power_governor(2, 5, 175, 50, 75, 90), 5, st)
26 chk("derate 100W@82C (warn band) " as *u8, nx_power_governor(100, 5, 175, 82, 75, 90), 56, st)
27 chk("EMERGENCY 100W@92C NEVER-FRY " as *u8, nx_power_governor(100, 5, 175, 92, 75, 90), 5, st)
28
29 // negative control: a HOT GPU must NOT keep full power (the governor MUST reduce it)
30 var neg_ok: i64 = 0
31 if nx_power_governor(100, 5, 175, 92, 75, 90) < 100 { neg_ok = 1 }
32 bp(" NEG hot-GPU power reduced (not full): " as *u8); if neg_ok==1 { bp("PASS\n" as *u8) } else { bp("FAIL\n" as *u8) }
33 // locked-clock target for reproducible bench (75% of 3090MHz max)
34 bp(" locked-clock target 75% of 3090MHz = " as *u8); bn(nx_clock_lock_target(3090, 75)); bp("MHz\n" as *u8)
35
36 let pass: i64 = st[0]
37 bp("GPU-POWER-GATE passed " as *u8); bd(pass); bp("/5 neg=" as *u8); bd(neg_ok); bp("\n" as *u8)
38 if pass==5 { if neg_ok==1 { bp("verdict=GREEN (never-fry power/thermal governor: clamp + thermal-derate + EMERGENCY-cap-at-critical-temp, integer/deterministic. Apply via device-shim RM_CONTROL / nvidia-smi = device step)\n" as *u8); sys_exit(0); return 0 } }
39 bp("verdict=RED\n" as *u8); sys_exit(1); return 1
40}