nx_f32_q4k_matmul.nx
buildroot/runtime/nx_f32_q4k_matmul.nx
about
nx_f32_q4k_matmul.nx -- lazy-dequant matmul, B is Q4_K bytes. C[m,n] = A[m,k] @ dequant(B[k,n]).
Per B-row k_idx: dequant -> row_scratch[n], then C[i,:] += A[i,k_idx]*row_scratch. Inner = sovereign SSE.
SOVEREIGN MULTICORE (2026-06-18, operator "no 3rd party from the hardware rung up"): fork-parallel by OUTPUT
COLUMN (super-block-aligned) -- each worker dequants ONLY its column slice (no redundant dequant; ~Ncore x)
and writes disjoint columns of a SHARED temp; parent joins + copies into C. Column-split parallelizes the
single-token decode (m=1) too, unlike a row-split. Pure syscalls (sys_fork/mmap_shared/wait4) -- NO
libvulkan/CUDA/Mesa/pthread. Pattern proven in nx_par_matmul (6.78x, bit-identical).
genealogy_id: ggml_q4k_dot_canon + sovereign_fork_parallel_columnsplit
lineage_id: substrate_f32_q4k_matmul_v2_parallel
dependencies 10 imports · 8 importers
imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_gguf_load.nxnx_q4k_to_f32.nxnx_f32.nxnx_thread_pool.nxnx_q4k_matmul.nxnx_dequant_iter.nxnx_f32_cvt.nx
imported by: nx_f32_lazy_weight.nxnx_f32_lazy_weight_test.nxnx_f32_q4k_matmul_test.nxnx_q4k_fused_fidelity_gate.nxnx_q4k_fused_vs_x4_gate.nxnx_q4k_matmul_mt_gate.nxnx_q4k_matmul_rate.nxnx_q4k_matmul_x4_gate.nx
structs
| 139 | struct NxFq4mCtx |
consts
| 23 | const NX_FQ4M_OK: nx_int = 0 |
| 24 | const NX_FQ4M_ERR_BAD_DIM: nx_int = 1 |
| 25 | const NX_FQ4M_ERR_NULL: nx_int = 2 |
| 26 | const NX_FQ4M_ERR_ALIGN: nx_int = 3 |
| 27 | const NX_FQ4M_ERR_POOL_WAIT: nx_int = 4 |
| 28 | const NX_FQ4M_N_VERDICTS: nx_int = 5 |
| 29 | const FQ4M_NW: i64 = 8 // worker forks |
| 30 | const FQ4M_PAR_MIN_MAC: i64 = 1000000000000000 // fork DISABLED: per-matmul fork net-SLOWER in the forward (fork overhead > gain). Pool (fork-once) is the fix. Serial path (fq4m_cols full-range) = proven-correct. |
| 151 | const NX_FQ4M_CTX_BYTES: i64 = 72 |
| 449 | const FQ4M_SB_VALS: i64 = 32 |
functions
| 36 | func nx_fq4m_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 48 | func fq4m_rows(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, m: nx_int, k: nx_int, n: nx_int, jlo: nx_int, jhi: nx_int) -> i64 called by 2: nx_f32_q4k_matmul_nx_fq4m_task calls 4: sys_mmap_fq4m_pack_anx_q4k_to_f32_packedsys_munmap |
| 102 | func nx_f32_q4k_matmul(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 153 | func _nx_fq4m_task(ctx_i: i64) -> i64 calls 1: fq4m_rows |
| 159 | func nx_f32_q4k_matmul_pool(pool: *NxThreadPool, A: *i64, B_bytes: *u8, called by 3: nx_f32_q4k_matmul_mtmainmain calls 5: sys_mmapnx_pool_n_completednx_pool_submitnx_pool_waitsys_munmap |
| 200 | func nx_f32_q4k_matmul_mt(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, called by 2: mainmain calls 5: nx_hw_worker_countnx_f32_q4k_matmulnx_pool_newnx_f32_q4k_matmul_poolnx_pool_shutdown |
| 230 | func _fq4m_pack_a(A: *i64, count: i64, out_p: *u8) -> i64 |
| 244 | func fq4m_rows_x4(pa: *u8, B_bytes: *u8, B_offset: i64, C: *i64, |
| 275 | func _nx_fq4m_task_x4(ctx_i: i64) -> i64 calls 1: fq4m_rows_x4 |
| 282 | func nx_f32_q4k_matmul_x4(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 300 | func nx_f32_q4k_matmul_pool_x4(pool: *NxThreadPool, A: *i64, B_bytes: *u8, called by 1: main calls 6: sys_mmap_fq4m_pack_anx_pool_n_completednx_pool_submitnx_pool_waitsys_munmap |
| 373 | func fq4m_rows_fused(pq: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 452 | func fq4m_sumA(A: *i64, k: nx_int, out_sum: *i64) -> i64 called by 1: nx_f32_q4k_matmul_i8simd |
| 465 | func fq4m_rows_i8simd(pa: *u8, A: *i64, sumA: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 515 | func nx_f32_q4k_matmul_i8simd(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 551 | func fq4m_fill_q24(cache: *u8, B_bytes: *u8, B_offset: i64, |
| 595 | func _fq4m_q24_at(cache: *u8, idx: i64) -> i64 |
| 604 | func fq4m_rows_cached_q24(pq: *i64, cache: *u8, C: *i64, called by 2: _nx_fq4m_task_cached_q24main calls 5: sys_mmap_fq4m_q24_atnx_q20_to_f32nx_q4km_q20_to_q10sys_munmap |
| 630 | func _nx_fq4m_task_fill_q24(ctx_i: i64) -> i64 calls 1: fq4m_fill_q24 |
| 635 | func _nx_fq4m_task_cached_q24(ctx_i: i64) -> i64 calls 1: fq4m_rows_cached_q24 |
| 641 | func _fq4m_pack_q10(A: *i64, count: i64, out_q: *i64) -> i64 called by 4: _lw_cached_matmulnx_f32_q4k_matmul_fusednx_f32_q4k_matmul_pool_fusedmain calls 1: nx_f32_to_q20 |
| 649 | func nx_f32_q4k_matmul_fused(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64, |
| 665 | func _nx_fq4m_task_fused(ctx_i: i64) -> i64 calls 1: fq4m_rows_fused |
| 673 | func nx_f32_q4k_matmul_pool_fused(pool: *NxThreadPool, A: *i64, B_bytes: *u8, |