code wiki / (root) / nx_compute_opt2.nx

nx_compute_opt2.nx

buildroot/runtime/nx_compute_opt2.nx

5771 B95 linesdepth 2pulls 3 transitivereach 0 importersview sourcekind tooltopic compute
docsdependenciesstructsconstsfunctions

about

nx_compute_opt2.nx -- compute wall, step 2: stack the SAFE levers (cache locality + more cores). The naive GEMM inner loop reads B[l*n+j] -- a COLUMN walk, stride n, a cache miss per access. Transpose B once (Bt[j*k+l]=B[l*n+j]) so the inner loop reads CONTIGUOUSLY (stride 1) = the cache-blocking lever. Then run that cache-friendly kernel across all cores (fork + shared mem). Both pure-NishiLang, no compiler surgery. Measures naive-1-thread vs transposed-1-thread (the cache lever alone) vs transposed-multicore (cache + cores), proves every variant is bit-identical, and reports the cumulative gap reduction toward the silicon f32 peak. Sovereign: nx_f32_hw SSE + sys_fork/sys_mmap_shared/sys_wait4. KAT: all variants bit-identical; transposed faster than naive; multicore faster still. HONEST: cache + cores levers only; packed-SIMD (4-8x) + FMA (2x) still remain (compiler-side). No hw writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_f32_hw.nx nx_syscalls.nx nx_compute_opt2.nx

imports: nx_f32_hw.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main o2_puts sys_write sys_mmap_shared sys_mmap f32_of sys_now_us sys_mmap ↻ sys_clock_gettime_mono mm_naive mm_band_t sys_fork sys_exit sys_wait4 o2_num sys_mmap ↻ sys_write ↻

structs

none

consts

13const K_MAGIC_1842560: i64 = 1842560

functions

15func o2_puts(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
16func o2_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
19func mm_naive(a: *i64, b: *i64, c: *i64, sz: i64) -> i64
called by 1: main
25func mm_band_t(a: *i64, bt: *i64, c: *i64, sz: i64, w: i64, nw: i64) -> i64
called by 1: main
33func main() -> i64