code wiki / (root) / nx_f32_q4k_matmul.nx

nx_f32_q4k_matmul.nx

buildroot/runtime/nx_f32_q4k_matmul.nx

33011 B716 linesdepth 8pulls 21 transitivereach 69 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_le.nx nx_gguf_load.nx nx_q4k_to_f32.nx nx_f32.nx nx_thread_pool.nx nx_q4k_matmul.nx nx_dequant_iter.nx nx_f32_cvt.nx nx_f32_q4k_matmul.nx nx_f32_lazy_weight.nx nx_f32_lazy_weight_test.nx nx_f32_q4k_matmul_test.nx nx_q4k_fused_fidelity_gate.nx nx_q4k_fused_vs_x4_gate.nx nx_q4k_matmul_mt_gate.nx nx_q4k_matmul_rate.nx nx_q4k_matmul_x4_gate.nx

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

139struct NxFq4mCtx

consts

23const NX_FQ4M_OK: nx_int = 0
24const NX_FQ4M_ERR_BAD_DIM: nx_int = 1
25const NX_FQ4M_ERR_NULL: nx_int = 2
26const NX_FQ4M_ERR_ALIGN: nx_int = 3
27const NX_FQ4M_ERR_POOL_WAIT: nx_int = 4
28const NX_FQ4M_N_VERDICTS: nx_int = 5
29const FQ4M_NW: i64 = 8 // worker forks
30const 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.
151const NX_FQ4M_CTX_BYTES: i64 = 72
449const FQ4M_SB_VALS: i64 = 32

functions

36func nx_fq4m_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
48func 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
102func nx_f32_q4k_matmul(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
153func _nx_fq4m_task(ctx_i: i64) -> i64
calls 1: fq4m_rows
159func nx_f32_q4k_matmul_pool(pool: *NxThreadPool, A: *i64, B_bytes: *u8,
200func nx_f32_q4k_matmul_mt(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
230func _fq4m_pack_a(A: *i64, count: i64, out_p: *u8) -> i64
244func fq4m_rows_x4(pa: *u8, B_bytes: *u8, B_offset: i64, C: *i64,
275func _nx_fq4m_task_x4(ctx_i: i64) -> i64
calls 1: fq4m_rows_x4
282func nx_f32_q4k_matmul_x4(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
300func nx_f32_q4k_matmul_pool_x4(pool: *NxThreadPool, A: *i64, B_bytes: *u8,
373func fq4m_rows_fused(pq: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
452func fq4m_sumA(A: *i64, k: nx_int, out_sum: *i64) -> i64
465func fq4m_rows_i8simd(pa: *u8, A: *i64, sumA: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
515func nx_f32_q4k_matmul_i8simd(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
551func fq4m_fill_q24(cache: *u8, B_bytes: *u8, B_offset: i64,
595func _fq4m_q24_at(cache: *u8, idx: i64) -> i64
604func fq4m_rows_cached_q24(pq: *i64, cache: *u8, C: *i64,
630func _nx_fq4m_task_fill_q24(ctx_i: i64) -> i64
calls 1: fq4m_fill_q24
635func _nx_fq4m_task_cached_q24(ctx_i: i64) -> i64
641func _fq4m_pack_q10(A: *i64, count: i64, out_q: *i64) -> i64
649func nx_f32_q4k_matmul_fused(A: *i64, B_bytes: *u8, B_offset: i64, C: *i64,
665func _nx_fq4m_task_fused(ctx_i: i64) -> i64
calls 1: fq4m_rows_fused
673func nx_f32_q4k_matmul_pool_fused(pool: *NxThreadPool, A: *i64, B_bytes: *u8,