code wiki / _hdl_build / nx_fnet_mix_gate.nx

nx_fnet_mix_gate.nx

buildroot/runtime/_hdl_build/nx_fnet_mix_gate.nx

11546 B281 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind gate/prooftopic fnet
docsdependenciesstructsconstsfunctions

about

nx_fnet_mix_gate.nx -- GATE for FNET-001 sub-quadratic Fourier token-mixer. Proves, by RUNNING (never asserting): CORRECTNESS C1 the generalized radix-2 FFT equals the naive O(n^2) DFT (same Q14 twiddles) at n=8 and n=16 -- the butterfly decomposition is algebraically a real Fourier transform, not loop-counting. C2 the synthesized n=32 twiddle table matches the SHIPPED, gated nx_fft hardcoded W_32 table within 1 Q14 unit -- so it is the SAME transform as the proven kernel, just generalized past N=32. MEASURED SUB-QUADRATIC EXCEED (the thesis: math kills the VRAM/compute exponential) For hidden dim d=16 and sequence lengths n in {64,256,1024,4096}, both kernels are RUN on real deterministic data and their executed integer-MULTIPLY counts are measured: attention = scores(Q@K^T, n*n*d) + softmax-normalize(n*n) + apply(@V, n*n*d) = 2*n^2*d + n^2 (O(n^2)) fnet-mix = 2*n*d*(log2 d + log2 n) (O(n log n)) (softmax's transcendental exp is excluded for BOTH as a non-MAC, the standard FLOP convention; the two O(n^2*d) matmuls are the attention cost present in every attention variant.) Each measured count is asserted EQUAL to its structural closed form (the counter is faithful), and the gate proves: fnet_mul < attn_mul at every n, AND the attn/fnet ratio STRICTLY GROWS with n -- the quadratic-vs-linearithmic crossover, compounding as context lengthens. A real output checksum from each kernel is printed so the work cannot be dead-code-eliminated. Evidence -> knowledge/status/fnet_mix.log (FNETGATE authored=organ ... verdict=GREEN). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_fnet_mix.nx nx_syscalls.nx nx_fnet_mix_gate.nx

imports: nx_fnet_mix.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 fn_c1_fft_vs_dft sys_mmap fnet_build_twiddles fnet_q16_to_q14 fx_cos fx_sin_cos fx_normalize_angle fx_cordic_atan fx_sin fx_sin_cos ↻ fnet_fft_fwd nx_fft_log2 nx_fft_bit_reverse fn_dft fnet_q16_to_q14 ↻ fn_abs fn_c2_twiddle_match sys_mmap ↻ fnet_build_twiddles ↻ fn_abs ↻ sys_mmap ↻ fn_attn_measure sys_mmap ↻ fn_fnet_measure sys_mmap ↻ fnet_mix sys_mmap ↻ fnet_build_twiddles ↻ fnet_fft_fwd ↻ nx_fft_log2 ↻ fn_emit fn_w sys_write fn_wn sys_mmap ↻ sys_write ↻ sys_openat_append sys_close

structs

none

consts

27const FN_LOG: *u8 = "knowledge/status/fnet_mix.log"

functions

29func fn_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
called by 1: fn_emit calls 1: sys_write
30func fn_wn(fd: i64, v: i64) -> i64
called by 1: fn_emit calls 2: sys_mmapsys_write
40func fn_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
44func fn_dft(in_re: *i64, in_im: *i64, n: i64, out_re: *i64, out_im: *i64) -> i64
called by 1: fn_c1_fft_vs_dft calls 1: fnet_q16_to_q14
67func fn_c1_fft_vs_dft(n: i64) -> i64
101func fn_c2_twiddle_match() -> i64
126func fn_attn_measure(n: i64, d: i64, chk: *i64) -> i64
called by 1: main calls 1: sys_mmap
192func fn_fnet_measure(n: i64, d: i64, chk: *i64) -> i64
called by 1: main calls 2: sys_mmapfnet_mix
207func fn_emit(fd: i64, c1a: i64, c1b: i64, c2: i64, ns: *i64, am: *i64, fm: *i64, rt: *i64, chk: i64, ok: i64) -> i64
called by 1: main calls 2: fn_wfn_wn
225func main() -> i64