From cfc786640429d7daab2ab8db2f0f00178eb69bc3 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 6 Nov 2026 20:05:44 +0100 Subject: [PATCH] STRA-338 size-fn2: npu-service test compare back within 30 lines after the wide-line wrap (read_output helper) --- crates/npu-service/tests/service.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/npu-service/tests/service.rs b/crates/npu-service/tests/service.rs index 0f23f43c..0b102cb4 100644 --- a/crates/npu-service/tests/service.rs +++ b/crates/npu-service/tests/service.rs @@ -219,6 +219,17 @@ fn product_errors( ((num / den).sqrt(), worst, shown) } +/// The f16 output rows and the per-column shifts (all zero unless the service reported a boost). +fn read_output(svc: &mut Service, out_off: usize, (rows, n): (usize, usize), shifted: bool) -> (Vec, Vec) { + let mut out = vec![0u8; rows * n * 2]; + svc.shm.read(out_off, &mut out).unwrap(); + let mut shifts = vec![0u8; n]; + if shifted { + svc.shm.read(out_off + rows * n * 2, &mut shifts).unwrap(); + } + (out, shifts) +} + fn compare(env: &Env, svc: &mut Service, name: &str, expert: Option, rows: usize, seed: u64) { let info_dims = tensor_dims(env, name); let (n, first) = match expert { @@ -233,14 +244,9 @@ fn compare(env: &Env, svc: &mut Service, name: &str, expert: Option, rows let e = expert.map_or("-".to_owned(), |e| e.to_string()); let answer = svc.ask(&format!("MM {name} {e} {rows} {in_off} {out_off}")); assert!(answer.starts_with("OK"), "{name}: {answer}"); - let mut out = vec![0u8; rows * n * 2]; - svc.shm.read(out_off, &mut out).unwrap(); // the service reports a boost of subnormal scales and appends one shift per column let shifted = answer.split_whitespace().nth(3) == Some("1"); - let mut shifts = vec![0u8; n]; - if shifted { - svc.shm.read(out_off + rows * n * 2, &mut shifts).unwrap(); - } + let (out, shifts) = read_output(svc, out_off, (rows, n), shifted); let (rel, worst, shown) = product_errors((&x, &w, &out, &shifts), (rows, n, k)); eprintln!( "{name} expert {expert:?} rows {rows}: relative rms error {rel:.2e}, worst abs {worst:.3e}, shifted columns \