code wiki / _hdl_build / nx_builder_quant.nx

nx_builder_quant.nx source

↩ module page · 33 lines · 2210 B

1// nx_builder_quant.nx -- the BUILDER's operating-point decision (RACI: the Builder ARCHITECTS the 2// approach, using the Engineer's diagnosis and the Council's quality policy -- it does not measure 3// or set the policy, it DECIDES under them). Given a kernel and a menu of quantization options, the 4// Builder: 5// 1. asks the ENGINEER which constraint binds (memory vs compute); 6// 2. if MEMORY-bound, trading bytes for speed pays -> pick the QUALITY-BALANCED option (Council 7// floor + quality-slightly-over-speed weighting). NOT the smallest/fastest -- the balanced one. 8// 3. if COMPUTE-bound, fewer bytes won't help (the lever is the inner loop / search governor), so 9// DON'T sacrifice quality for size -- keep the HIGHEST-QUALITY option and let compute-opt do 10// the speed. (Balance, with quality favoured, in both regimes.) 11// license_tier: ORIGINAL 12 13import "nx_engineer_profile.nx" // the Engineer's diagnosis (eng_diagnose_kernel, eng_recommend_lever) 14import "nx_quality_balance.nx" // the Council-governed balance (qb_select, QB_QUALITY_FLOOR) 15 16// the Builder's chosen quantization index, or -1 if the Engineer could not diagnose the kernel. 17func bld_select_operating_point(flops: i64, bytes: i64, peak_flops: i64, peak_bw: i64, n: i64, loss: *i64, bits10: *i64) -> i64 { 18 let bound: i64 = eng_diagnose_kernel(flops, bytes, peak_flops, peak_bw) 19 let lever: i64 = eng_recommend_lever(bound) 20 if lever == ENG_LEVER_NONE { return 0 - 1 } 21 if lever == ENG_LEVER_DATA { 22 // memory-bound: balance quality vs speed under the Council floor (quality weighted higher). 23 return qb_select(n, loss, bits10, QB_QUALITY_FLOOR) 24 } 25 // compute-bound: no quality sacrifice buys speed here -> keep highest quality. (qb_select with an 26 // unmeetable floor degrades gracefully to the lowest-loss option -- reused as "highest quality".) 27 return qb_select(n, loss, bits10, 0 - 1) 28} 29 30// expose the lever class for the Scribe / journal (so the deliverable records WHY the Builder chose). 31func bld_lever_for(flops: i64, bytes: i64, peak_flops: i64, peak_bw: i64) -> i64 { 32 return eng_recommend_lever(eng_diagnose_kernel(flops, bytes, peak_flops, peak_bw)) 33}