Rust comments that named scripts/offline/*, gen_goldens.py, oracle/gen_*.{sh,cpp,py}, build_oracle.sh and similar retired generators now say where the data
came from (the Original's code, Strata 41cf05a0) or drop the sentence. The path/generator text of seven generated fixtures (sampler_oracle.json, sampling_keys.json,
memory_plan_golden.json, rope_golden.json, cvec_oracle.json, stra161 fixtures.json, commentary-tool-prompt.json) is reworded; no test reads those fields and no pin
covers their bytes. cmd_time/doc.rs: the two path texts in the format string; its lines are re-broken so they stay within 120 columns (the string is unchanged
otherwise). Comment-only except those data/string spots; no behaviour change.
62 lines
2.4 KiB
Rust
62 lines
2.4 KiB
Rust
//! The KV streaming planner against `layer.cpp`'s own functions (the golden host build extracts them
|
|
//! verbatim and drives them over a grid of formats, contexts, rings and `--kv-resident` values).
|
|
|
|
mod common;
|
|
|
|
use common::fixture;
|
|
use leleka_experimental_ref::{
|
|
kv_stream::{self, PlanSwitches, StreamMode},
|
|
layout::{KvFormat, QsaShapes},
|
|
};
|
|
|
|
fn format_of(c: &serde_json::Value) -> KvFormat {
|
|
match c["format"].as_str().unwrap() {
|
|
"fp16" => KvFormat::Fp16,
|
|
"int8" => KvFormat::Int8,
|
|
"q4_0" => KvFormat::Q4_0,
|
|
"k8v4" => KvFormat::K8V4,
|
|
"int8-keyless" => KvFormat::Int8Keyless,
|
|
other => panic!("{other}"),
|
|
}
|
|
}
|
|
|
|
/// One grid case against the plan and the state bytes; returns the plan's mode index.
|
|
fn check_case(s: &QsaShapes, c: &serde_json::Value) -> usize {
|
|
let format = format_of(c);
|
|
let (max_cells, ring, resident) = (
|
|
c["max_cells"].as_i64().unwrap(),
|
|
c["ring"].as_i64().unwrap(),
|
|
c["resident"].as_i64().unwrap(),
|
|
);
|
|
let sw = PlanSwitches::default();
|
|
let plan = kv_stream::kv_plan(s, max_cells, ring, resident, sw);
|
|
let ctx = format!("{format:?} {max_cells} ring {ring} resident {resident}");
|
|
assert_eq!(plan.mode as i64, c["mode"].as_i64().unwrap(), "{ctx}");
|
|
assert_eq!(plan.pages, c["pages"].as_i64().unwrap(), "{ctx}");
|
|
assert_eq!(plan.slots, c["slots"].as_i64().unwrap(), "{ctx}");
|
|
assert_eq!(plan.pooled_rows, c["pooled_rows"].as_i64().unwrap(), "{ctx}");
|
|
let rope = c["rope"].as_i64() == Some(1);
|
|
let cells = kv_stream::StateCells { max_cells, ring_cells: ring, kv_resident: resident };
|
|
let bytes = kv_stream::qsa_state_bytes(s, format, cells, rope, sw);
|
|
assert_eq!(bytes, c["state_bytes"].as_u64().unwrap(), "{ctx}");
|
|
plan.mode as usize
|
|
}
|
|
|
|
#[test]
|
|
fn planner_and_state_bytes_match_layer_cpp_over_the_whole_grid() {
|
|
let g = fixture("stream_plan_golden.json");
|
|
assert_eq!(g["resident_min"].as_i64(), Some(kv_stream::KV_RESIDENT_MIN));
|
|
assert_eq!(g["map_bytes_5120"].as_u64(), Some(kv_stream::map_bytes(5120)));
|
|
let s = QsaShapes::real();
|
|
let mut n = 0;
|
|
let mut modes = [0usize; 3];
|
|
for c in g["cases"].as_array().unwrap() {
|
|
modes[check_case(&s, c)] += 1;
|
|
n += 1;
|
|
}
|
|
assert_eq!(n, 5 * 4 * 3 * 4 * 2);
|
|
// the grid exercises all three modes
|
|
assert!(modes.iter().all(|m| *m > 0), "{modes:?}");
|
|
assert_eq!(StreamMode::Streamed as i32, 1);
|
|
}
|