code wiki / _hdl_build / nx_gpu_power.nx
nx_gpu_power.nx source
↩ module page · 30 lines · 1905 B
1// nx_gpu_power.nx -- sovereign GPU POWER + THERMAL GOVERNOR (operator 2026-06-20: "fix the energy and heat output
2// if we need to as nvidia fries their gpus"). NEVER-FRY BY CONSTRUCTION (rule #26) + resource-aware (rule #21):
3// clamps the power cap to the hardware [min,max], DERATES under thermal stress, and EMERGENCY-caps to minimum at the
4// critical temperature. Also yields the LOCKED CLOCKS the benchmark methodology needs (reproducible measurement).
5//
6// The governor LOGIC is pure INTEGER (no-float, deterministic) -- gated locally. APPLYING the cap = the device
7// shim's RM_CONTROL power-limit command (nx_nv on native-Linux, RM NV2080_CTRL_CMD_PERF; or nvidia-smi -pl as the
8// incumbent, admin) = TODO_DEVICE. Real 5080 range probed: pmin=5W, pmax=175W, default=80W. Pure funcs, no main.
9// license_tier: ORIGINAL
10import "nx_syscalls.nx"
11
12// SAFE power cap (watts) from the request + hardware range + thermal state. Integer/deterministic.
13func nx_power_governor(requested_w: i64, pmin: i64, pmax: i64, temp_c: i64, temp_warn: i64, temp_crit: i64) -> i64 {
14 var cap: i64 = requested_w
15 if cap < pmin { cap = pmin }
16 if cap > pmax { cap = pmax }
17 // NEVER-FRY: at/above the critical temperature, slam to minimum power.
18 if temp_c >= temp_crit { return pmin }
19 // thermal derate: in the [warn, crit) band, reduce the cap toward pmin proportionally to how hot we are.
20 if temp_c >= temp_warn {
21 let band: i64 = temp_crit - temp_warn
22 let into: i64 = temp_c - temp_warn
23 let reduce: i64 = ((cap - pmin) * into) / band
24 cap = cap - reduce
25 if cap < pmin { cap = pmin }
26 }
27 return cap
28}
29// a safe LOCKED-CLOCK target (MHz) for reproducible benchmarks: a fraction of max, never above max.
30func nx_clock_lock_target(max_mhz: i64, percent: i64) -> i64 { var c: i64 = (max_mhz * percent) / 100; if c > max_mhz { c = max_mhz } return c }