code wiki / _hdl_build / _gpu_dxg_vidmem_gate.nx

_gpu_dxg_vidmem_gate.nx source

↩ module page · 121 lines · 9472 B

1// _gpu_dxg_vidmem_gate.nx -- SOVEREIGN-GPU ladder R4b (read the REAL VRAM budget of the 5080). 2// 3// R4a created a GPU context. R4b reads the discrete adapter's REAL video-memory budget via 4// LX_DXQUERYVIDEOMEMORYINFO -- an UNFAKEABLE number (~14.9 GiB on the 16GB 5080) proving we read actual 5// GPU state off the silicon, not just opaque handle slots. This is the memory-sizing prerequisite for 6// real GPU allocations (R4c) and the GEMM working set (R6). 7// 8// ABI (recon-pinned LIVE, _gpu_dxg_r4b_recon: no uapi header -> size-swept, only _IOC_SIZE=56 recognized; 9// OUT field offsets located by buffer dump): 10// LX_DXQUERYVIDEOMEMORYINFO = _IOWR(0x47, 0x0a, 56) = 0xC038470A 11// struct (56B): process @0 (u64, 0=current, IN); adapter @8 (d3dkmthandle, IN); memory_segment_group @12 12// (u32, IN: 0=LOCAL/VRAM, 1=NON_LOCAL/shared-sysmem); budget @16 (u64, OUT); current_usage @24 (OUT); 13// current_reservation @32 (OUT); available_for_reservation @40 (OUT); physical_adapter_index @48 (IN). 14// 15// GREEN iff (author=organ, from REAL device returns): 16// A) enum ret==0 AND exactly ONE discrete hw adapter (R1 identity); 17// B) query(discrete, LOCAL) ret==0 AND budget in [4 GiB, 32 GiB] (a real discrete-GPU-class VRAM budget, 18// NOT hardcoded to the exact byte count -- bounds, so it stays valid across host-reservation drift); 19// C) query(discrete, NON_LOCAL) ret==0 AND its budget != the LOCAL budget 20// (DISCRIMINATION: the segment_group field is genuinely honored -> not a stuck constant); 21// D) TAMPER: T1 bogus adapter(0xdeadbeef) -> ret!=0 AND budget stays 0 (no data w/o a real adapter); 22// T2 wrong _IOC_SIZE(48) -> -ENOTTY; T3 on a non-dxg fd -> -ENOTTY. 23// Marker -> knowledge/status/gpu_dxg.log (DXGVRAMGATE). raw syscalls only. NO-WAVE: reads memory STATE 24// (a budget), NOT throughput -- zero speedup/exceed claimed (that is R7). 25// license_tier: ORIGINAL 26import "nx_syscalls.nx" 27 28const ENUM2_CODE: i64 = 0xC0104714 29const QAI_CODE: i64 = 0xC0184709 30const QVM_CODE: i64 = 0xC038470A // LX_DXQUERYVIDEOMEMORYINFO (_IOWR(0x47,0x0a,56), recon-pinned) 31const QVM_BADSZ: i64 = 0xC030470A // wrong _IOC_SIZE=48 -> -ENOTTY tamper 32const GIB: i64 = 1073741824 33 34func p(s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(1,s,nn); return 0 } 35func fp(fd: i64, s: *u8) -> i64 { var nn: i64=0; while s[nn]!=(0 as u8){nn=nn+1} sys_write(fd,s,nn); return 0 } 36func 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;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 } 37func fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;fp(fd,"-" as *u8)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;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(fd,bb,k); return 0 } 38func x(v: i64) -> i64 { p("0x" as *u8); let bb:*u8=sys_mmap(20); var k:i64=0; var m:i64=v; if m==0{bb[0]=48;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 } 39func rd32(buf: *u8, off: i64) -> i64 { return (buf[off] as i64)|((buf[off+1] as i64)<<8)|((buf[off+2] as i64)<<16)|((buf[off+3] as i64)<<24) } 40func rd64(buf: *u8, off: i64) -> i64 { let q: *i64 = (buf as i64 + off) as *i64; return q[0] } 41 42func query_type(fd: i64, handle: i64, qtype: i64, psize: i64, outv: *i64) -> i64 { 43 let priv: *u8 = sys_mmap(64); var zz: i64 = 0; while zz < 64 { priv[zz] = 0 as u8; zz = zz + 1 } 44 let req: *u8 = sys_mmap(64); var y: i64 = 0; while y < 64 { req[y] = 0 as u8; y = y + 1 } 45 let h: *i64 = (req as i64 + 0) as *i64; h[0] = (handle & 0xffffffff) | ((qtype & 0xffffffff) << 32) 46 let pd: *i64 = (req as i64 + 8) as *i64; pd[0] = priv as i64 47 let pds: *i64 = (req as i64 + 16) as *i64; pds[0] = psize & 0xffffffff 48 let ret: i64 = sys_ioctl(fd, QAI_CODE, req as i64); outv[0] = rd32(priv, 0); return ret 49} 50// query video memory; OUT budget -> outb[0], available -> outa[0]. buffer pre-zeroed (budget write-back proof). 51func query_vidmem(fd: i64, code: i64, adapter: i64, segment: i64, outb: *i64, outa: *i64) -> i64 { 52 let buf: *u8 = sys_mmap(512); var bz: i64 = 0; while bz < 512 { buf[bz] = 0 as u8; bz = bz + 1 } 53 let a8: *i64 = (buf as i64 + 8) as *i64; a8[0] = adapter & 0xffffffff // adapter @8; process @0 = 0 54 let sg: *i64 = (buf as i64 + 12) as *i64; sg[0] = segment & 0xffffffff // memory_segment_group @12 55 let ret: i64 = sys_ioctl(fd, code, buf as i64) 56 outb[0] = rd64(buf, 16); outa[0] = rd64(buf, 40); return ret 57} 58 59func main() -> i64 { 60 p("=== SOVEREIGN-GPU R4b gate (raw /dev/dxg LX_DXQUERYVIDEOMEMORYINFO -> the real 5080 VRAM budget) ===\n" as *u8) 61 let fd: i64 = sys_openat_rd("/dev/dxg" as *u8) 62 if fd < 0 { p("open(/dev/dxg) failed\n" as *u8); sys_exit(1); return 1 } 63 let ainfo: *u8 = sys_mmap(4096); var z: i64 = 0; while z < 4096 { ainfo[z] = 0 as u8; z = z + 1 } 64 let ereq: *u8 = sys_mmap(64); ereq[0] = 8 as u8; let r8: *i64 = (ereq as i64 + 8) as *i64; r8[0] = ainfo as i64 65 let eret: i64 = sys_ioctl(fd, ENUM2_CODE, ereq as i64); let nc: i64 = rd32(ereq, 0) 66 let v: *i64 = sys_mmap(16); var n_discrete: i64 = 0; var disc_eh: i64 = 0 67 var ai: i64 = 0 68 while ai < nc { 69 let base: i64 = ai * 20; let eh: i64 = rd32(ainfo, base) 70 let qret: i64 = query_type(fd, eh, 15, 4, v); let t: i64 = v[0] 71 if qret == 0 { if ((t>>4)&1) == 1 { if ((t>>2)&1) == 0 { n_discrete = n_discrete + 1; disc_eh = eh } } } 72 ai = ai + 1 73 } 74 p(" enum ret=" as *u8); n(eret); p(" discrete_count=" as *u8); n(n_discrete); p(" discrete_handle=" as *u8); x(disc_eh); p("\n" as *u8) 75 76 // REAL: LOCAL (VRAM) budget + NON_LOCAL (shared) budget. 77 let bl: *i64 = sys_mmap(16); let al: *i64 = sys_mmap(16) 78 let bnl: *i64 = sys_mmap(16); let anl: *i64 = sys_mmap(16) 79 let r_loc: i64 = query_vidmem(fd, QVM_CODE, disc_eh, 0, bl, al) 80 let r_nl: i64 = query_vidmem(fd, QVM_CODE, disc_eh, 1, bnl, anl) 81 p(" LOCAL ret=" as *u8); n(r_loc); p(" budget=" as *u8); n(bl[0]); p(" (=~ MB " as *u8); n(bl[0]/1048576); p(") avail_for_reservation=" as *u8); n(al[0]); p("\n" as *u8) 82 p(" NONLOC ret=" as *u8); n(r_nl); p(" budget=" as *u8); n(bnl[0]); p(" (=~ MB " as *u8); n(bnl[0]/1048576); p(")\n" as *u8) 83 84 // ---- TAMPER matrix ---- 85 let tb: *i64 = sys_mmap(16); let ta: *i64 = sys_mmap(16) 86 let t1: i64 = query_vidmem(fd, QVM_CODE, 0xdeadbeef, 0, tb, ta); let t1b: i64 = tb[0] // bogus adapter 87 let t2: i64 = query_vidmem(fd, QVM_BADSZ, disc_eh, 0, tb, ta) // wrong _IOC_SIZE 88 let nfd: i64 = sys_openat_rd("/dev/null" as *u8) 89 let t3: i64 = query_vidmem(nfd, QVM_CODE, disc_eh, 0, tb, ta) // non-dxg fd 90 if nfd >= 0 { sys_close(nfd) } 91 p(" [tamper] bogus-adapter ret=" as *u8); n(t1); p(" budget=" as *u8); n(t1b) 92 p(" | wrong-size ret=" as *u8); n(t2); p(" | non-dxg-fd ret=" as *u8); n(t3); p("\n" as *u8) 93 sys_close(fd) 94 95 var bounds_ok: i64 = 0; if bl[0] >= (4*GIB) { if bl[0] <= (32*GIB) { bounds_ok = 1 } } 96 var discrim: i64 = 0; if r_nl == 0 { if bnl[0] != bl[0] { discrim = 1 } } 97 var tamper_ok: i64 = 0; if t1 != 0 { if t1b == 0 { if t2 != 0 { if t3 != 0 { tamper_ok = 1 } } } } 98 99 var pass: i64 = 0 100 if eret == 0 { if n_discrete == 1 { if r_loc == 0 { if bounds_ok == 1 { if discrim == 1 { if tamper_ok == 1 { pass = 1 } } } } } } 101 102 p(" checks: enum=" as *u8); n(eret==0); p(" discrete_count=" as *u8); n(n_discrete); p(" local_ok=" as *u8); n(r_loc==0) 103 p(" budget_in_bounds[4..32GiB]=" as *u8); n(bounds_ok); p(" segment_discriminates=" as *u8); n(discrim); p(" tamper_ok=" as *u8); n(tamper_ok); p("\n" as *u8) 104 105 let lfd: i64 = sys_openat_append("knowledge/status/gpu_dxg.log" as *u8, 0x1a4) 106 if pass == 1 { 107 p("DXGVRAMGATE verdict=GREEN reason=raw-/dev/dxg-LX_DXQUERYVIDEOMEMORYINFO-reads-the-real-5080-VRAM-budget (LOCAL budget in discrete-GPU-class bounds 4..32GiB; NON_LOCAL budget differs = segment field honored; bogus-adapter writes no budget; wrong-size/non-dxg -ENOTTY; wrapper-free) SCOPE=memory-STATE-introspection-only-NO-throughput; allocation=R4c\n" as *u8) 108 if lfd >= 0 { 109 fp(lfd, "DXGVRAMGATE verdict=GREEN rung=R4b-vram-budget-query device=discrete-RTX5080 via=raw-/dev/dxg-LX_DXQUERYVIDEOMEMORYINFO(0xC038470A,size56,budget@16) local_budget_bytes=" as *u8); fn(lfd, bl[0]) 110 fp(lfd, " (~MB " as *u8); fn(lfd, bl[0]/1048576); fp(lfd, ") available_for_reservation_bytes=" as *u8); fn(lfd, al[0]) 111 fp(lfd, " nonlocal_budget_bytes=" as *u8); fn(lfd, bnl[0]) 112 fp(lfd, " bounds_ok=1 segment_discriminates=1 tamper=rejected(bogus-adapter-no-budget+wrong-IOC_SIZE-ENOTTY+non-dxg-ENOTTY) wrapper-free scope=memory-state-introspection-only-NO-throughput next=R4c-LX_DXCREATEALLOCATION\n" as *u8) 113 sys_close(lfd) 114 } 115 sys_exit(0); return 0 116 } 117 p("DXGVRAMGATE verdict=RED (one of enum/discrete/local-query/bounds/segment-discriminate/tamper not satisfied)\n" as *u8) 118 if lfd >= 0 { fp(lfd, "DXGVRAMGATE verdict=RED see-console\n" as *u8); sys_close(lfd) } 119 sys_exit(1) 120 return 1 121}