code wiki / (root) / nx_gen_linear_verify.nx

nx_gen_linear_verify.nx

buildroot/runtime/nx_gen_linear_verify.nx

18940 B415 linesdepth 6pulls 12 transitivereach 0 importersview sourcekind tooltopic gen
docsdependenciesstructsconstsfunctions

about

nx_gen_linear_verify.nx -- SOVEREIGN linear projection (matmul), verified vs a reference. y == x @ W^T This is the core compute of every diffusion and transformer architecture: qkv projection, attention out-projection, every FFN matrix, every text-encoder layer. It is also where the entire sovereignty gap lives -- correctness here was proven cheaply; THROUGHPUT is the wall. Usage: nx_gen_linear_verify <model_id> <x_name> <w_name> <y_name> [rows] [pass_idx] [accum] [nworkers] Names are ABSOLUTE fixture names -- weights carry their own checkpoint name ("model.diffusion_model.layers.0.attention.qkv.weight"), so nothing here is tied to one architecture or one block. Shapes are read from the manifest, never assumed. LAYOUT (ggml): ggml_mul_mat(w, x) with w[ne0=in, ne1=out] and x[ne0=in, ne1=tokens] gives y[ne0=out, ne1=tokens]. ne[0] is the contiguous dim, so y[t][o] = sum_i x[t*in + i] * w[o*in + i] TWO REFERENCE TIERS (measured 2026-08-06, not a stylistic choice): The oracle's mul_mat on a Q8_0 weight does NOT compute dequant(W) @ x -- it quantizes the ACTIVATIONS too and runs a blocked integer dot. An exact f64 reference deviates from the oracle by ~0.52% median / 43% max on the Z-Image qkv projection. So grade against - `<y>.exact` (f64 reference) -> "is our arithmetic right", tight band - `<y>` (the oracle itself) -> only at a loose band; it is the LOWER-precision side * A TOLERANCE IS A CLAIM ABOUT THE REFERENCE'S PRECISION, NOT THE IMPLEMENTATION'S. ACCUM MODES -- every one stays A/B-able, because a speed or accuracy claim that cannot be re-measured against its predecessor is an opinion: 0 naive sequential f32 1 Kahan compensated 2 __f32x8_dot (8-wide, but horizontally reduces EVERY 8 elements) 3 __f32x8_dot + Kahan on the chunk sum 4 __f32x8_fma (fused 8-wide multiply-add into a 32-byte accumulator, hsum ONCE) 5 __f32x8_fma + multicore (forked workers over an out_dim band, shared result buffer) 6 __f32x8_fma x4 independent accumulators (breaks the FMA latency chain) 7 mode 6 + multicore 8 Q8_0 dequant-dot (int8 weight x f32 activation via __f32_i8dot32a) -- reads the RAW quantized weight, 3.77x less memory traffic than the f32 weight 9 mode 8 + multicore 10 Q8_0 with per-block f16 scales pre-decoded once (software f16 decode out of the hot loop)

dependencies 9 imports · 0 importers

nx_syscalls.nx nx_le.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f16.nx nx_strconv.nx nx_genfix.nx nx_genver.nx nx_gen_linear_verify.nx

imports: nx_syscalls.nxnx_le.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f16.nxnx_strconv.nxnx_genfix.nxnx_genver.nx

imported by: nobody (leaf or entry point)

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

main nx_genver_emit sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ nx_strconv_format_i64 sys_write ↻ zl_strlen sys_mmap ↻ nx_strconv_parse_i64 nx_ascii_is_digit nx_genfix_dims sys_mmap ↻ _gf_read_manifest sys_mmap ↻ _gf_cpyz nx_genfix_root sys_openat_rd sys_read sys_close nx_genfix_load _gf_path sys_mmap ↻ _gf_cpyz ↻ nx_genfix_root ↻ _gf_cpy sys_openat_rd ↻ sys_mmap ↻

structs

none

consts

none

functions

59func zl_strlen(s: *u8) -> i64
called by 1: main
71func zl_band(mode: i64, x: *u8, w: *u8, res: *i64, scales: *i64,
256func main(argc: i64, argv: *i64) -> i64