code wiki / _hdl_build / nx_gpu_q4k_gate.nx
nx_gpu_q4k_gate.nx
buildroot/runtime/_hdl_build/nx_gpu_q4k_gate.nx
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
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
structs
| none |
consts
| 23 | const GQ_PORT: i64 = 18140 |
| 24 | const GQ_N: i64 = 8 // rows; must be a multiple of 8 (one warp per row, 8 warps/block) |
| 25 | const GQ_K: i64 = 256 // one Q4_K super-block per row |
| 26 | const GQ_BPB: i64 = 144 // bytes per super-block -- from runtime/nx_dequant_iter.nx |
| 27 | const GQ_OP_PING: i64 = 0 |
| 28 | const GQ_OP_REGISTER: i64 = 1 |
| 29 | const GQ_OP_MATVEC: i64 = 2 |
functions
| 31 | func 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 } |
| 32 | func gq_n(v: i64) -> i64 |
| 43 | func gq_put32(b: *u8, off: i64, v: i64) -> i64 called by 1: main |
| 50 | func gq_get32(b: *u8, off: i64) -> i64 called by 1: main |
| 56 | func gq_i2f(v: i64) -> i64 called by 1: main |
| 67 | func gq_readn(fd: i64, buf: *u8, n: i64) -> i64 |
| 79 | func gq_writen(fd: i64, buf: *u8, n: i64) -> i64 |
| 92 | func gq_connect(port: i64) -> i64 |
| 112 | func gq_set_q(qs: *u8, e: i64, q: i64) -> i64 called by 1: main |
| 125 | func main(argc: i64, argv: *i64) -> i64 |