code wiki / (root) / nx_native_matmul_long_bench.nx

nx_native_matmul_long_bench.nx source

↩ module page · 55 lines · 1627 B

1// nx_native_matmul_long_bench.nx -- LONG matmul bench for Stabilizer signal. 2// 3// The 256x256 version (nx_native_matmul_bench.nx) ran ~0.1s and the 4// paired Stabilizer found CI 0.41-10.73x (no defensible signal -- 5// runtime too short relative to WSL+gcc-O0 layout noise floor of 6// 79%). This version scales to 512x512 (= 8x ops, 134M mul-adds). 7// Target runtime: ~0.5s gcc-O0, ~1.5-3s Nishi -- enough multiples of 8// timing granularity to escape coarse-grained noise. 9// 10// Per [[reference-berger-performance-matters-talk-archived]]: runtime 11// must be much larger than measurement granularity for the noise 12// floor as a fraction of mean to shrink to defensible levels. 13 14import "nx_syscalls.nx" 15 16func main() -> i64 { 17 let N: i64 = 512 // 512x512 = 134M multiply-adds 18 19 let bufA: *u8 = sys_mmap(N * N * 8) 20 let bufB: *u8 = sys_mmap(N * N * 8) 21 let bufC: *u8 = sys_mmap(N * N * 8) 22 let A: *i64 = bufA as *i64 23 let B: *i64 = bufB as *i64 24 let C: *i64 = bufC as *i64 25 26 var i: i64 = 0 27 while i < N { 28 var j: i64 = 0 29 while j < N { 30 A[i * N + j] = (i + j) & 255 31 B[i * N + j] = (i * j + 1) & 255 32 C[i * N + j] = 0 33 j = j + 1 34 } 35 i = i + 1 36 } 37 38 var ii: i64 = 0 39 while ii < N { 40 var jj: i64 = 0 41 while jj < N { 42 var sum: i64 = 0 43 var k: i64 = 0 44 while k < N { 45 sum = sum + A[ii * N + k] * B[k * N + jj] 46 k = k + 1 47 } 48 C[ii * N + jj] = sum 49 jj = jj + 1 50 } 51 ii = ii + 1 52 } 53 54 return C[0] 55}