code wiki / _hdl_build / nx_nv_gate.nx

nx_nv_gate.nx source

↩ module page · 54 lines · 3824 B

1// nx_nv_gate.nx -- gate for the native-Linux NVIDIA executor (nx_nv). Verifies the LOCALLY-verifiable core 2// bit-exact (the GPFIFO entry encoder, real hardware format per tinygrad ops_nv.py) + reports the device-iface 3// status (on WSL2 the /dev/nvidia* nodes are ABSENT -> the EXECUTE is honestly CLOUD-PENDING, run on a rented 4// native-Linux GPU instance = BM-GPU-6). No hw writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_nv.nx" 7import "nx_gate_verdict.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 bx(v: i64) -> i64 { bp("0x" as *u8); let bb:*u8=sys_mmap(20); var k:i64=0; var m:i64=v; if m==0{bb[0]=48 as u8;k=1} while m>0{ let d:i64=m&15; if d<10{bb[k]=(48+d) as u8}else{bb[k]=(87+d) as u8}; m=(m>>4); k=k+1 } var i:i64=0; let o:*u8=sys_mmap(20); while i<k{o[i]=bb[k-1-i];i=i+1} sys_write(1,o,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(" gpfifo_entry " as *u8); bp(name); bp(" -> " as *u8); bx(got) 15 if got==ref { bp(" == hw-format ref PASS\n" as *u8); st[0]=st[0]+1; return 0 } 16 bp(" != ref " as *u8); bx(ref); bp(" FAIL\n" as *u8); return 0 17} 18 19func main() -> i64 { 20 bp("=== native-Linux NVIDIA executor (nx_nv) -- GPFIFO entry encoder bit-exact + device-iface routing ===\n" as *u8) 21 22 // device-iface: on WSL2 absent -> EXECUTE is cloud-pending; on a native/cloud instance these open. 23 let ctl: i64 = nv_open_ctl() 24 var have_ctl: i64 = 0 25 if ctl >= 0 { have_ctl = 1; sys_close(ctl) } 26 bp(" /dev/nvidiactl present=" as *u8); bd(have_ctl) 27 if have_ctl == 1 { bp(" -> native-Linux: BM-GPU-6 EXECUTE runnable HERE\n" as *u8) } else { bp(" -> WSL2/no-native: EXECUTE cloud-pending (rent a native-Linux GPU instance)\n" as *u8) } 28 29 // ---- locally-verifiable: the GPFIFO entry encoder (real hardware format, tinygrad-confirmed) ---- 30 let st: *i64 = sys_mmap(8); st[0]=0 31 chk("va=0x32c000 len=6 " as *u8, nv_gpfifo_entry(0x32c000, 6), 0x1a000032c000, st) 32 chk("va=0x33c000 len=4 " as *u8, nv_gpfifo_entry(0x33c000, 4), 0x12000033c000, st) 33 chk("va=0x400000 len=2 " as *u8, nv_gpfifo_entry(0x400000, 2), 0xa0000400000, st) 34 chk("va=0x500000 len=1 " as *u8, nv_gpfifo_entry(0x500000, 1), 0x60000500000, st) 35 // alignment: a non-4-aligned VA must have its low 2 bits cleared (== the aligned entry) 36 chk("va=0x32c001 align " as *u8, nv_gpfifo_entry(0x32c001, 6), 0x1a000032c000, st) 37 38 // negative control: distinct VA -> distinct entry (proves the encoder reads the address) 39 var neg_ok: i64 = 0 40 if nv_gpfifo_entry(0x32c000, 6) != nv_gpfifo_entry(0x33c000, 6) { neg_ok = 1 } 41 bp(" NEG distinct-va distinct-entry: " as *u8); if neg_ok==1 { bp("PASS\n" as *u8) } else { bp("FAIL\n" as *u8) } 42 43 let pass: i64 = st[0] 44 bp("NV-EXECUTOR-GATE entry_encoder " as *u8); bd(pass); bp("/5 neg=" as *u8); bd(neg_ok); bp(" doorbell_off=" as *u8); bx(0x90); bp(" execute=" as *u8); if have_ctl==1 { bp("native-runnable" as *u8) } else { bp("CLOUD-PENDING" as *u8) }; bp("\n" as *u8) 45 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 46 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 47 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 48 let ctr__dry: *i64 = gv_ctr() 49 ctr__dry[0] = pass 50 ctr__dry[1] = 5 51 let rc__dry: i64 = gv_verdict("NV-GATE" as *u8, ctr__dry, "GPFIFO entry encoder bit-exact [tinygrad-confirmed format]; doorbell offset 0x90; full RM object tree + real EXECUTE = cloud-pending on native-Linux silicon)" as *u8) 52 sys_exit(rc__dry) 53 return rc__dry 54}