STRA-338 size-fn2: npu-service test compare back within 30 lines after the wide-line wrap (read_output helper)

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 20:05:44 +01:00
parent dc28184651
commit cfc7866404
+12 -6
View File
@@ -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<u8>, Vec<u8>) {
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<usize>, 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<usize>, 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 \