code wiki / _hdl_build / nx_roofline.nx
nx_roofline.nx
buildroot/runtime/_hdl_build/nx_roofline.nx
about
nx_roofline.nx -- the team's "where is the real bottleneck?" intelligence (the mathematician's
FIRST move: diagnose the binding constraint before spending effort). Polishing a memory-bound
kernel's arithmetic is wasted work -- llama.cpp's AVX2 prefetch on the Q4 dot product bought
+0.8% because token generation is MEMORY-BANDWIDTH bound, not compute bound. This module makes
that judgment explicit and hardware-specific (it "grows to meet the hardware": ridge point is
computed from the chip's own peak flops + bandwidth, the vertical co-design north star).
ROOFLINE (Williams/Patterson 2009): arithmetic intensity AI = flops / bytes_moved. The machine
has a ridge point R = peak_flops / peak_bandwidth. AI < R => MEMORY-bound (the lever is bytes
moved: quantization, sparsity, fusion, reuse -- "mental math", not SIMD). AI > R => COMPUTE-
bound (the lever is the inner-loop instruction sequence: superopt / the search governor).
Attainable perf = min(peak_flops, AI * peak_bandwidth).
All comparisons are EXACT integer cross-multiplications (no float, no division truncation), and
peak_flops/peak_bw are taken in GFLOP/s and GB/s so the products stay well inside i64.
license_tier: ORIGINAL Refs: Williams, Waterman, Patterson, "Roofline" CACM 2009.
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_engineer_profile.nxnx_roofline_test.nx
structs
| none |
consts
| 20 | const RF_UNKNOWN: i64 = 0 // robustness sentinel: invalid inputs -> no verdict (fail loud) |
| 21 | const RF_MEMORY_BOUND: i64 = 1 |
| 22 | const RF_COMPUTE_BOUND: i64 = 2 |
| 23 | const RF_OVF_LIMIT: i64 = 4611686018427387904 // 2^62: keep every product safely inside i64 |
functions
| 31 | func rf_bound(flops: i64, bytes: i64, peak_flops: i64, peak_bw: i64) -> i64 |
| 50 | func rf_ai_milli(flops: i64, bytes: i64) -> i64 |
| 56 | func rf_ridge_milli(peak_flops: i64, peak_bw: i64) -> i64 called by 1: main |
| 64 | func rf_byte_speedup_milli(old_bytes: i64, new_bytes: i64) -> i64 called by 1: main |