code wiki / _hdl_build / nx_gpu_q4k_gate.nx

nx_gpu_q4k_gate.nx

buildroot/runtime/_hdl_build/nx_gpu_q4k_gate.nx

16096 B335 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic gpu
docsdependenciesstructsconstsfunctions

about

nx_gpu_q4k_gate.nx -- proves a SOVEREIGN organ can drive the GPU. WHY THIS EXISTS (2026-08-01): Q4_K matvec was measured correct on the RTX 5080 at 362 GB/s DRAM-resident (=> ~42 tok/s for a 14B, against 1.06 tok/s for today's 0.5B CPU seat). But NishiLang emits STATIC ELF with syscalls only -- it has no dlopen, so it cannot link libcuda. The GPU therefore lives behind nx_gpu_q4kd (a small C daemon holding weights resident in VRAM) and we reach it over TCP, which this language already speaks. This gate is the proof that the sovereign side can actually drive it -- not that the daemon works in isolation. ★ THE COMPARISON IS BIT-EXACT, ON PURPOSE. GPU and CPU reduce in different orders, so a float comparison would normally need a tolerance -- and a tolerance is a place for a wrong answer to hide. Instead the test data is chosen so EVERY product is a small integer: d=1.0, dmin=0, all sub-block scales=1, x integral. Integer-valued f32 addition is exact in ANY order, so the GPU result must equal the expected value BIT FOR BIT. No tolerance, nothing to tune. EXIT CONTRACT: 0 = all teeth pass. 1 = a tooth failed. 2 = could not reach the daemon (refuses to report GREEN when it never measured -- absence of findings and absence of measurement must never render identically). nx_gpu_q4k_gate [port] default 18140 expect_exit: 0 license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_gpu_q4k_gate.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gq_w sys_write gq_connect sys_socket sys_mmap sys_connect sys_close gq_n sys_write ↻ sys_mmap ↻ sys_exit sys_mmap ↻ gq_put32 gq_writen sys_write ↻ gq_readn sys_read gq_get32 gq_set_q gq_i2f sys_close ↻

structs

none

consts

23const GQ_PORT: i64 = 18140
24const GQ_N: i64 = 8 // rows; must be a multiple of 8 (one warp per row, 8 warps/block)
25const GQ_K: i64 = 256 // one Q4_K super-block per row
26const GQ_BPB: i64 = 144 // bytes per super-block -- from runtime/nx_dequant_iter.nx
27const GQ_OP_PING: i64 = 0
28const GQ_OP_REGISTER: i64 = 1
29const GQ_OP_MATVEC: i64 = 2

functions

31func gq_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
32func gq_n(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
43func gq_put32(b: *u8, off: i64, v: i64) -> i64
called by 1: main
50func gq_get32(b: *u8, off: i64) -> i64
called by 1: main
56func gq_i2f(v: i64) -> i64
called by 1: main
67func gq_readn(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main calls 1: sys_read
79func gq_writen(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main calls 1: sys_write
92func gq_connect(port: i64) -> i64
112func gq_set_q(qs: *u8, e: i64, q: i64) -> i64
called by 1: main
125func main(argc: i64, argv: *i64) -> i64