code wiki / _hdl_build / nx_fnet_mix_gate.nx
nx_fnet_mix_gate.nx
buildroot/runtime/_hdl_build/nx_fnet_mix_gate.nx
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
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
structs
| none |
consts
| 27 | const FN_LOG: *u8 = "knowledge/status/fnet_mix.log" |
functions
| 29 | func 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 } |
| 30 | func fn_wn(fd: i64, v: i64) -> i64 |
| 40 | func fn_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } |
| 44 | func fn_dft(in_re: *i64, in_im: *i64, n: i64, out_re: *i64, out_im: *i64) -> i64 |
| 67 | func fn_c1_fft_vs_dft(n: i64) -> i64 |
| 101 | func fn_c2_twiddle_match() -> i64 |
| 126 | func fn_attn_measure(n: i64, d: i64, chk: *i64) -> i64 |
| 192 | func fn_fnet_measure(n: i64, d: i64, chk: *i64) -> i64 |
| 207 | func fn_emit(fd: i64, c1a: i64, c1b: i64, c2: i64, ns: *i64, am: *i64, fm: *i64, rt: *i64, chk: i64, ok: i64) -> i64 |
| 225 | func main() -> i64 |