code wiki / _hdl_build / nx_device_probe.nx

nx_device_probe.nx source

↩ module page · 72 lines · 4614 B

1// nx_device_probe.nx -- R0-LIVE: CLOUD-AWARE sovereign compute-device discovery + HAL-shim ROUTING for the 2// "S-class exceed for ANY DEVICE" stack. Detects the device interface available in THIS environment and routes 3// to the right per-vendor sovereign shim: 4// /dev/dxg -> WSL2 GPU-PV (nx_dxg shim; control-plane only, EXECUTE walled by NVIDIA priv-data) 5// /dev/nvidiactl,/dev/nvidia0 -> native-Linux NVIDIA open-kernel-modules (GPFIFO+doorbell EXECUTE = BM-GPU-6 runnable) 6// /dev/kfd -> native-Linux AMD (AM/PM4 path, nx_pm4_asm) 7// /dev/dri/card0 -> generic DRM 8// On WSL2 (here) reports dxg + enumerates GPUs; on a rented native-Linux cloud GPU instance reports the native 9// path so the deploy runs BM-GPU-6 on real silicon (the brick-safe measured-exceed path, rule #26). 10// No hw writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_dxg.nx" 13const K_MAGIC_4096: i64 = 4096 14 15func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 } 16func n(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 } 17func dev_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 18 19func main() -> i64 { 20 p("=== nx_device_probe R0-LIVE: cloud-aware device discovery + HAL-shim routing (any device, any environment) ===\n" as *u8) 21 22 let has_dxg: i64 = dev_exists("/dev/dxg" as *u8) 23 let has_nvctl: i64 = dev_exists("/dev/nvidiactl" as *u8) 24 let has_nv0: i64 = dev_exists("/dev/nvidia0" as *u8) 25 let has_kfd: i64 = dev_exists("/dev/kfd" as *u8) 26 let has_dri: i64 = dev_exists("/dev/dri/card0" as *u8) 27 p(" device-iface present: dxg(WSL2-GPU-PV)=" as *u8); n(has_dxg) 28 p(" nvidiactl=" as *u8); n(has_nvctl); p(" nvidia0=" as *u8); n(has_nv0) 29 p(" kfd(AMD)=" as *u8); n(has_kfd); p(" dri/card0=" as *u8); n(has_dri); p("\n" as *u8) 30 31 // ---- HAL-shim ROUTING (which sovereign per-vendor path applies in this environment) ---- 32 if has_dxg == 1 { p(" ROUTE: ENV=WSL2 -> shim=nx_dxg (control-plane proven; EXECUTE walled by NVIDIA priv-data -> rent native-Linux cloud to EXECUTE)\n" as *u8) } 33 if has_nv0 == 1 { p(" ROUTE: ENV=native-Linux NVIDIA -> shim=open-kernel-module GPFIFO+doorbell -> BM-GPU-6 EXECUTE runnable HERE (the measured-exceed path)\n" as *u8) } 34 if has_kfd == 1 { p(" ROUTE: ENV=native-Linux AMD -> shim=AM/PM4 (nx_pm4_asm) -> AMD execute path runnable HERE\n" as *u8) } 35 36 // ---- on WSL2/dxg, enumerate the actual GPUs present (live discovery) ---- 37 var hw_render: i64 = 0 38 var discrete: i64 = 0 39 var integrated: i64 = 0 40 if has_dxg == 1 { 41 let fd: i64 = dxg_open() 42 let ainfo: *u8 = sys_mmap(K_MAGIC_4096) 43 let nc: i64 = dxg_enum(fd, ainfo) 44 p(" dxg adapters enumerated: " as *u8); n(nc); p("\n" as *u8) 45 let v: *i64 = sys_mmap(16) 46 var ai: i64 = 0 47 while ai < nc { 48 let base: i64 = ai * 20 49 let eh: i64 = dxg_rd32(ainfo, base) 50 let qret: i64 = dxg_query_type(fd, eh, 15, 4, v) 51 let t: i64 = v[0] 52 let f_render: i64 = t & 1 53 let f_sw: i64 = (t >> 2) & 1 54 let f_disc: i64 = (t >> 4) & 1 55 let f_integ: i64 = (t >> 5) & 1 56 p(" device[" as *u8); n(ai); p("] render=" as *u8); n(f_render); p(" discrete=" as *u8); n(f_disc); p(" integrated=" as *u8); n(f_integ); p("\n" as *u8) 57 if f_sw == 0 { if f_render == 1 { hw_render = hw_render + 1; if f_disc == 1 { discrete = discrete + 1 } if f_integ == 1 { integrated = integrated + 1 } } } 58 ai = ai + 1 59 } 60 sys_close(fd) 61 } 62 63 var any_iface: i64 = 0 64 if has_dxg == 1 { any_iface = 1 } 65 if has_nv0 == 1 { any_iface = 1 } 66 if has_kfd == 1 { any_iface = 1 } 67 if has_dri == 1 { any_iface = 1 } 68 p("DEVICEPROBE dxg_gpus_hw=" as *u8); n(hw_render); p(" discrete=" as *u8); n(discrete); p(" integrated=" as *u8); n(integrated) 69 p(" native_nvidia=" as *u8); n(has_nv0); p(" native_amd=" as *u8); n(has_kfd) 70 if any_iface == 1 { p(" verdict=GREEN (live device discovery + HAL-shim routing -- environment-aware, cloud-ready)\n" as *u8); sys_exit(0); return 0 } 71 p(" verdict=RED (no device interface present in this environment)\n" as *u8); sys_exit(1); return 1 72}