code wiki / (root) / nx_linear_attn_bench.nx

nx_linear_attn_bench.nx

buildroot/runtime/nx_linear_attn_bench.nx

4195 B115 linesdepth 7pulls 13 transitivereach 0 importersview sourcekind bench
docsdependenciesstructsconstsfunctions

about

nx_linear_attn_bench.nx -- measure SANA linear attention O(n·d^2) vs softmax O(n^2·d) at scale. Confirms the DiT-IC/SANA lever concretely: at n=512 tokens, head_dim=64, linear attention should be materially faster than softmax (which builds the 512x512 score matrix + 512x512 exps). Linear attention copied inline (nx_f32_linear_attention has a main); softmax via the nx_f32_attention lib. license_tier: ORIGINAL

dependencies 7 imports · 0 importers

nx_syscalls.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f32_attention.nx nx_clock.nx nx_strconv.nx nx_linear_attn_bench.nx

imports: nx_syscalls.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f32_attention.nxnx_clock.nxnx_strconv.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap nx_i32_to_f32 nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_clock_monotonic_ns sys_mmap ↻ sys_clock_gettime_mono lab_linear lab_phi nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_i32_to_f32 ↻ nx_f32_add ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_div ↻ nx_f32_attention nx_f32_add ↻ nx_f32_mul ↻ nx_f32_softmax _f32_gt nx_f32_sub nx_f32_add ↻ nx_f32_neg nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_sub ↻ nx_f32_exp

structs

none

consts

none

functions

15func lab_phi(x: i64) -> i64
called by 1: lab_linear calls 2: nx_f32_addnx_i32_to_f32
21func lab_linear(Q: *i64, K: *i64, V: *i64, n_tokens: i64, head_dim: i64, out: *i64, S: *i64, z: *i64) -> i64
56func lab_emit(fd: i64, key: *u8, kl: i64, v: i64) -> i64
70func main() -> i64