Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aqpbm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ pub struct SketchbenchArgs {
)]
pub operations: Option<String>,
/// How many shards the merge operation folds. A knob, never a selector:
/// measuring merge is asked for with `--operations merge`. Linear sketches
/// measuring merge is asked for with `--operations merge`. With
/// `--metrics accuracy` the folded sketch is asked the query's questions and
/// scored against the whole stream, as `merge_accuracy`. Linear sketches
/// merge exactly, so a gap is a defect; for KLL it is the result.
#[arg(long, default_value_t = 2, help_heading = "Measurement content")]
pub merge_shards: usize,
Expand Down
48 changes: 44 additions & 4 deletions aqpbm-cli/src/flatten_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,24 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
}
};
}
// `throughput_items_per_sec`, `latency_ns`, `accuracy` and the
// `merge_*` fields are each owned by exactly one metric-pass per
// `merge_shards`/`merge_supported` describe the merge setup, which
// every merge square of one invocation stamps — equal values agree,
// different ones mean two setups were folded together.
macro_rules! keep_same {
($slot:expr, $v:expr, $field:literal) => {
if let Some(v) = $v {
if $slot.is_some_and(|s| s != v) {
return Err(format!(
"flatten_record: {}/{} {operation} has two different values for {}",
record.sketch, record.library, $field
));
}
$slot = Some(v);
}
};
}
// `throughput_items_per_sec`, `latency_ns`, `accuracy` and
// `merge_folds_per_sec` are each owned by exactly one metric-pass per
// operation — nothing legitimately produces a second value for one
// of these within a slot. A second value is a genuine duplicate, so
// it is refused by field name rather than silently resolved.
Expand Down Expand Up @@ -166,12 +182,13 @@ pub fn flatten_record(records: &[Record]) -> Result<MergedRecord, String> {
*merge_folds_per_sec,
"merge_folds_per_sec"
);
keep_owned!(out.merge.merge_shards, *merge_shards, "merge_shards");
keep_owned!(
keep_same!(out.merge.merge_shards, *merge_shards, "merge_shards");
keep_same!(
out.merge.merge_supported,
*merge_supported,
"merge_supported"
);
keep_owned!(out.merge.accuracy, accuracy.clone(), "accuracy");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge accuracy can't be flattened together with any other merge metric. Every merge record stamps merge_shards/merge_supported (main.rs:440, bench_report.rs:52), and keep_owned! on merge_shards (line 169) rejects the second value.

Repro on this branch:

--operations merge --metrics throughput,accuracy --flat
Error: flatten_record: cms-fastpath-vector2d/lib merge has two values for merge_shards

Same failure from approxbench flatten joining a cost pass (merge throughput) with an accuracy pass that now includes merge accuracy, which is the join flatten_cmd.rs exists for. Throughput+latency on merge already hit this before, but this PR makes it the common case. These two fields probably want keep_shared! (equal values allowed) rather than keep_owned!.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

keep_shared!(out.merge.cpu_time_ms, cpu_time_ms);
keep_shared!(out.merge.wall_time_ms, wall_time_ms);
keep_shared!(out.merge.rss_peak_kb, rss_peak_kb);
Expand Down Expand Up @@ -382,6 +399,29 @@ mod tests {
assert_eq!(out.insert.wall_time_ms.unwrap().mean, 1.0);
}

/// A cost pass and an accuracy pass over one merge both stamp the merge
/// setup. The same setup twice is one setup; two different ones are not.
#[test]
fn merge_setup_on_two_squares_must_agree() {
let merge = |metric, shards| {
record(
"merge",
metric,
BenchSection {
merge_shards: Some(shards),
merge_supported: Some(true),
..Default::default()
},
)
};
let out = flatten_record(&[merge("throughput", 4), merge("accuracy", 4)])
.expect("the same setup agrees");
assert_eq!(out.merge.merge_shards, Some(4));
let err = flatten_record(&[merge("throughput", 4), merge("accuracy", 16)])
.expect_err("two setups in one row");
assert!(err.contains("merge_shards"), "{err}");
}

/// `throughput_items_per_sec` is owned by exactly one metric-pass per
/// operation — nothing legitimately produces it twice for `insert`. A
/// second value here is a genuine duplicate, refused by field name
Expand Down
9 changes: 8 additions & 1 deletion aqpbm-cli/src/rows/cms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub(crate) fn row_cms_oxide(
co::insert_cms_oxide::<$t>,
co::insert_step_cms_oxide::<$t>,
co::query_cms_oxide::<$t>,
Some((co::merge_cms_oxide::<$t>, co::merge_step_cms_oxide)),
Some((
co::merge_cms_oxide::<$t>,
co::merge_step_cms_oxide,
co::merge_query_cms_oxide::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -51,6 +55,7 @@ pub(crate) fn row_cms_datasketches(
Some((
cd::merge_cms_datasketches::<$t>,
cd::merge_step_cms_datasketches,
cd::merge_query_cms_datasketches::<$t>,
)),
None,
)
Expand Down Expand Up @@ -112,6 +117,7 @@ pub(crate) fn row_cms_fastpath_vector2d_lib(
Some((
cl::merge_cms_lib_vector2d_fast::<$t>,
cl::merge_step_cms_lib_vector2d_fast::<$t>,
cl::merge_query_cms_lib_vector2d_fast::<$t>,
)),
None,
)
Expand Down Expand Up @@ -144,6 +150,7 @@ pub(crate) fn row_cms_regularpath_vector2d_lib(
Some((
cl::merge_cms_lib_vector2d_regular::<$t>,
cl::merge_step_cms_lib_vector2d_regular::<$t>,
cl::merge_query_cms_lib_vector2d_regular::<$t>,
)),
None,
)
Expand Down
4 changes: 4 additions & 0 deletions aqpbm-cli/src/rows/cms_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) fn row_cms_heap_fastpath_vector2d_lib(
Some((
chl::merge_cms_heap_lib_vector2d_fast::<$t>,
chl::merge_step_cms_heap_lib_vector2d_fast::<$t>,
chl::merge_query_cms_heap_lib_vector2d_fast_estimate::<$t>,
)),
None,
)
Expand Down Expand Up @@ -55,6 +56,7 @@ pub(crate) fn row_cms_heap_regularpath_vector2d_lib(
Some((
chl::merge_cms_heap_lib_vector2d_regular::<$t>,
chl::merge_step_cms_heap_lib_vector2d_regular::<$t>,
chl::merge_query_cms_heap_lib_vector2d_regular_estimate::<$t>,
)),
None,
)
Expand Down Expand Up @@ -87,6 +89,7 @@ pub(crate) fn row_cms_heap_topk_fastpath_vector2d_lib(
Some((
chl::merge_cms_heap_lib_vector2d_fast::<$t>,
chl::merge_step_cms_heap_lib_vector2d_fast::<$t>,
chl::merge_query_cms_heap_lib_vector2d_fast_topk::<$t>,
)),
)
};
Expand Down Expand Up @@ -118,6 +121,7 @@ pub(crate) fn row_cms_heap_topk_regularpath_vector2d_lib(
Some((
chl::merge_cms_heap_lib_vector2d_regular::<$t>,
chl::merge_step_cms_heap_lib_vector2d_regular::<$t>,
chl::merge_query_cms_heap_lib_vector2d_regular_topk::<$t>,
)),
)
};
Expand Down
8 changes: 7 additions & 1 deletion aqpbm-cli/src/rows/cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub(crate) fn row_countsketch_oxide(
so::insert_cs_oxide,
so::insert_step_cs_oxide,
so::query_cs_oxide,
Some((so::merge_cs_oxide, so::merge_step_cs_oxide)),
Some((
so::merge_cs_oxide,
so::merge_step_cs_oxide,
so::merge_query_cs_oxide,
)),
None,
)
};
Expand Down Expand Up @@ -80,6 +84,7 @@ pub(crate) fn row_countsketch_fastpath_vector2d_lib(
Some((
sl::merge_cs_lib_vector2d_fast,
sl::merge_step_cs_lib_vector2d_fast,
sl::merge_query_cs_lib_vector2d_fast,
)),
None,
)
Expand Down Expand Up @@ -112,6 +117,7 @@ pub(crate) fn row_countsketch_regularpath_vector2d_lib(
Some((
sl::merge_cs_lib_vector2d_regular,
sl::merge_step_cs_lib_vector2d_regular,
sl::merge_query_cs_lib_vector2d_regular,
)),
None,
)
Expand Down
12 changes: 10 additions & 2 deletions aqpbm-cli/src/rows/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub(crate) fn row_dd_lib(
ddl::insert_dd_lib::<$t>,
ddl::insert_step_dd_lib::<$t>,
ddl::query_dd_lib::<$t>,
Some((ddl::merge_dd_lib::<$t>, ddl::merge_step_dd_lib::<$t>)),
Some((
ddl::merge_dd_lib::<$t>,
ddl::merge_step_dd_lib::<$t>,
ddl::merge_query_dd_lib::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -48,7 +52,11 @@ pub(crate) fn row_dd_oxide(
ddo::insert_dd_oxide::<$t>,
ddo::insert_step_dd_oxide::<$t>,
ddo::query_dd_oxide::<$t>,
Some((ddo::merge_dd_oxide::<$t>, ddo::merge_step_dd_oxide::<$t>)),
Some((
ddo::merge_dd_oxide::<$t>,
ddo::merge_step_dd_oxide::<$t>,
ddo::merge_query_dd_oxide::<$t>,
)),
None,
)
};
Expand Down
14 changes: 10 additions & 4 deletions aqpbm-cli/src/rows/fixed_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::*;
/// erased list, so nothing in the return type mentions the shape it ran at.
macro_rules! fixed_matrix_row {
($fname:ident, $params:ty, $algo:literal, $module:ident, $insert:ident, $insert_step:ident,
$query:ident, $merge:ident, $merge_step:ident) => {
$query:ident, $merge:ident, $merge_step:ident, $merge_query:ident) => {
pub(crate) fn $fname(
req: &Requirement,
description: &TableDescription,
Expand Down Expand Up @@ -54,7 +54,11 @@ macro_rules! fixed_matrix_row {
w::$insert::<M, T>,
w::$insert_step::<M, T>,
w::$query::<M, T>,
Some((w::$merge::<M, T>, w::$merge_step::<M, T>)),
Some((
w::$merge::<M, T>,
w::$merge_step::<M, T>,
w::$merge_query::<M, T>,
)),
None,
)
}
Expand Down Expand Up @@ -95,7 +99,8 @@ fixed_matrix_row!(
insert_step_cms_lib_fixedmatrix,
query_cms_lib_fixedmatrix,
merge_cms_lib_fixedmatrix,
merge_step_cms_lib_fixedmatrix
merge_step_cms_lib_fixedmatrix,
merge_query_cms_lib_fixedmatrix
);

fixed_matrix_row!(
Expand All @@ -107,5 +112,6 @@ fixed_matrix_row!(
insert_step_cs_lib_fixedmatrix,
query_cs_lib_fixedmatrix,
merge_cs_lib_fixedmatrix,
merge_step_cs_lib_fixedmatrix
merge_step_cs_lib_fixedmatrix,
merge_query_cs_lib_fixedmatrix
);
8 changes: 7 additions & 1 deletion aqpbm-cli/src/rows/hll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ pub(crate) fn row_hll_oxide(
ho::insert_hll_oxide::<$t>,
ho::insert_step_hll_oxide::<$t>,
ho::query_hll_oxide::<$t>,
Some((ho::merge_hll_oxide::<$t>, ho::merge_step_hll_oxide::<$t>)),
Some((
ho::merge_hll_oxide::<$t>,
ho::merge_step_hll_oxide::<$t>,
ho::merge_query_hll_oxide::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -53,6 +57,7 @@ pub(crate) fn row_hll_datasketches(
Some((
hd::merge_hll_datasketches::<$t>,
hd::merge_step_hll_datasketches::<$t>,
hd::merge_query_hll_datasketches::<$t>,
)),
None,
)
Expand Down Expand Up @@ -149,6 +154,7 @@ pub(crate) fn row_hll_lib(
Some((
hl::merge_hll_lib::<$r, $t>,
hl::merge_step_hll_lib::<$r, $t>,
hl::merge_query_hll_lib::<$r, $t>,
)),
None,
)
Expand Down
24 changes: 20 additions & 4 deletions aqpbm-cli/src/rows/hydra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub(crate) fn row_hydra_cms_lib(
hs::insert_hydra_cms::<$t>,
hs::insert_step_hydra_cms::<$t>,
hs::query_hydra_cms::<$t>,
Some((hs::merge_hydra_cms::<$t>, hs::merge_step_hydra_cms::<$t>)),
Some((
hs::merge_hydra_cms::<$t>,
hs::merge_step_hydra_cms::<$t>,
hs::merge_query_hydra_cms::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -80,7 +84,11 @@ pub(crate) fn row_hydra_cs_lib(
hcs::insert_hydra_cs::<$t>,
hcs::insert_step_hydra_cs::<$t>,
hcs::query_hydra_cs::<$t>,
Some((hcs::merge_hydra_cs::<$t>, hcs::merge_step_hydra_cs::<$t>)),
Some((
hcs::merge_hydra_cs::<$t>,
hcs::merge_step_hydra_cs::<$t>,
hcs::merge_query_hydra_cs::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -138,7 +146,11 @@ pub(crate) fn row_hydra_hll_lib(
hhs::insert_hydra_hll::<$t>,
hhs::insert_step_hydra_hll::<$t>,
hhs::query_hydra_hll::<$t>,
Some((hhs::merge_hydra_hll::<$t>, hhs::merge_step_hydra_hll::<$t>)),
Some((
hhs::merge_hydra_hll::<$t>,
hhs::merge_step_hydra_hll::<$t>,
hhs::merge_query_hydra_hll::<$t>,
)),
None,
)
};
Expand Down Expand Up @@ -196,7 +208,11 @@ pub(crate) fn row_hydra_kll_lib(
hks::insert_hydra_kll::<$t>,
hks::insert_step_hydra_kll::<$t>,
hks::query_hydra_kll::<$t>,
Some((hks::merge_hydra_kll::<$t>, hks::merge_step_hydra_kll::<$t>)),
Some((
hks::merge_hydra_kll::<$t>,
hks::merge_step_hydra_kll::<$t>,
hks::merge_query_hydra_kll::<$t>,
)),
None,
)
};
Expand Down
4 changes: 4 additions & 0 deletions aqpbm-cli/src/rows/hydra_univmon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) fn row_hydra_univmon_cardinality_lib(
Some((
hus::merge_hydra_univmon::<$t>,
hus::merge_step_hydra_univmon::<$t>,
hus::merge_query_hydra_univmon_cardinality::<$t>,
)),
None,
)
Expand Down Expand Up @@ -85,6 +86,7 @@ pub(crate) fn row_hydra_univmon_l1_norm_lib(
Some((
hus::merge_hydra_univmon::<$t>,
hus::merge_step_hydra_univmon::<$t>,
hus::merge_query_hydra_univmon_l1_norm::<$t>,
)),
None,
)
Expand Down Expand Up @@ -154,6 +156,7 @@ pub(crate) fn row_hydra_univmon_l2_norm_lib(
Some((
hus::merge_hydra_univmon::<$t>,
hus::merge_step_hydra_univmon::<$t>,
hus::merge_query_hydra_univmon_l2_norm::<$t>,
)),
None,
)
Expand Down Expand Up @@ -223,6 +226,7 @@ pub(crate) fn row_hydra_univmon_entropy_lib(
Some((
hus::merge_hydra_univmon::<$t>,
hus::merge_step_hydra_univmon::<$t>,
hus::merge_query_hydra_univmon_entropy::<$t>,
)),
None,
)
Expand Down
4 changes: 4 additions & 0 deletions aqpbm-cli/src/rows/kll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) fn row_kll_percall_oxide(
Some((
ko::merge_kll_oxide_per_call::<$t>,
ko::merge_step_kll_oxide_per_call::<$t>,
ko::merge_query_kll_oxide_per_call::<$t>,
)),
None,
)
Expand Down Expand Up @@ -59,6 +60,7 @@ pub(crate) fn row_kll_percall_lib(
Some((
kl::merge_kll_lib_per_call::<$t>,
kl::merge_step_kll_lib_per_call::<$t>,
kl::merge_query_kll_lib_per_call::<$t>,
)),
None,
)
Expand Down Expand Up @@ -91,6 +93,7 @@ pub(crate) fn row_kll_cdf_oxide(
Some((
ko::merge_kll_oxide_cdf::<$t>,
ko::merge_step_kll_oxide_cdf::<$t>,
ko::merge_query_kll_oxide_cdf::<$t>,
)),
Some(ko::prepare_kll_oxide_cdf::<$t>),
)
Expand Down Expand Up @@ -123,6 +126,7 @@ pub(crate) fn row_kll_cdf_lib(
Some((
kl::merge_kll_lib_cdf::<$t>,
kl::merge_step_kll_lib_cdf::<$t>,
kl::merge_query_kll_lib_cdf::<$t>,
)),
Some(kl::prepare_kll_lib_cdf::<$t>),
)
Expand Down
Loading
Loading