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
25 changes: 4 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ exclude = ["crates/metricsql-parser-vendored"]
resolver = "2"

[workspace.dependencies]
asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "831a5045847010a3a65f5a8e614e0208581d4a05" }
asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "3f44cf1c2d823b844c17796f24408e03863149ee" }
30 changes: 17 additions & 13 deletions crates/asap-aware-mapping/src/accuracy/estimators/univmon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use asap_types::pre_asap::AggIntent;

/// Layers `asap_sketchlib` builds: layer `i` hashes at seed index `i`, and
/// seed 19 picks the layers a key reaches.
pub(crate) const MAX_LAYERS: u8 = 19;
pub(crate) const MAX_LAYERS: u8 = asap_sketchlib::sketch_framework::univmon::MAX_LAYER_SIZE as u8;
/// Rows the executor builds an L2 sketch with: the deepest odd shape under
/// its 20-row limit.
const MAX_L2_ROWS: u32 = 19;
Expand Down Expand Up @@ -91,19 +91,13 @@ pub(super) fn guarantee(
}
}

/// Whether `asap_sketchlib` builds this shape with independent hashes: at
/// most [`MAX_LAYERS`] layers, and `rows · (⌈log2 cols⌉ + 1) ≤ 128`.
/// Whether `asap_sketchlib` builds this shape, with independent hashes: at
/// most [`MAX_LAYERS`] layers and 20 rows, and `rows · (⌈log2 cols⌉ + 1) ≤
/// 128` ([`asap_sketchlib::UnivMon::check_shape`]; the heap size is not part
/// of the hash rules).
pub(crate) fn hash_independent(rows: u32, cols: u32, layers: u8) -> bool {
rows >= 1
&& cols >= 1
&& (1..=MAX_LAYERS).contains(&layers)
&& rows.saturating_mul(column_bits(cols) + 1) <= HASH_BITS
}

/// `⌈log2 cols⌉`, the column bits a row reads.
fn column_bits(cols: u32) -> u32 {
cols.checked_next_power_of_two()
.map_or(u32::BITS, u32::trailing_zeros)
asap_sketchlib::UnivMon::check_shape(1, rows as usize, cols as usize, usize::from(layers))
.is_ok()
}

/// The relative error of the L2 norm at `cols` columns. Per row, the
Expand Down Expand Up @@ -495,6 +489,16 @@ mod tests {
}
}

/// The library builds at most 20 rows, so a 21-row UnivMon certifies
/// nothing even though its hashes fit the budget (21 · (3 + 1) = 84 ≤
/// 128 at 8 columns).
#[test]
fn univmon_past_twenty_rows_is_not_hash_independent() {
assert!(hash_independent(20, 8, 1));
assert!(!hash_independent(21, 8, 1));
assert!(l2(&univmon(1, 21, 8, 1, None)).is_none());
}

/// Each distinct-count heap meets its target once the source's bound
/// is bound, and one fewer key does not.
#[test]
Expand Down
17 changes: 14 additions & 3 deletions crates/asap-aware-mapping/src/empirical_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ fn valid_params(algorithm: &SketchAlgorithm, params: &SketchParams) -> bool {
alpha.is_finite() && *alpha > 0.0 && *alpha < 1.0
}
(SketchAlgorithm::Cms, SketchParams::Cms { width, depth }) => *width > 0 && *depth > 0,
// A CountSketch reads the median of its rows: the depth must be odd.
// The kernel's shape rules (an odd depth, for the median).
(SketchAlgorithm::CountSketch, SketchParams::CountSketch { width, depth }) => {
*width > 0 && depth % 2 == 1
count_sketch_builds(*width, *depth)
}
(
SketchAlgorithm::CmsWithHeap,
Expand All @@ -392,11 +392,22 @@ fn valid_params(algorithm: &SketchAlgorithm, params: &SketchParams) -> bool {
depth,
heap_size,
},
) => *width > 0 && depth % 2 == 1 && *heap_size > 0,
) => count_sketch_builds(*width, *depth) && *heap_size > 0,
_ => false,
}
}

/// Whether `asap_sketchlib`'s CountSketch kernel builds a `width x depth`
/// shape, so evidence for it describes an executable shape.
fn count_sketch_builds(width: u32, depth: u32) -> bool {
asap_sketchlib::WeightedFrequency::check_shape(
asap_sketchlib::FrequencyAlgorithm::CountSketch,
width as usize,
depth as usize,
)
.is_ok()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/asap-physical-operators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
chrono = { version = "0.4.39", default-features = false, features = ["std"] }
futures = "0.3"
planner-types = { package = "asap-types", path = "../types" }
asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "9415c5b161237ad238e101ed9166d4dbaace3031", features = ["experimental"] }
asap_sketchlib = { workspace = true, features = ["experimental"] }
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
tracing = "0.1"
Expand Down
12 changes: 9 additions & 3 deletions crates/asap-physical-operators/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ pub fn validate_summary_kernel(
(A::Hll, P::Hll { precision, .. }) if (4..=18).contains(precision) => false,
(A::Kmv, P::Kmv { k, .. }) if *k >= crate::summary_kernels::kmv::KMV_MIN_K => false,
(A::Cms, P::Cms { width, depth }) if valid_matrix(*width, *depth) => true,
// The median needs an odd row count.
// The kernel's shape rules (an odd depth, for the median).
(A::CountSketch, P::CountSketch { width, depth })
if valid_matrix(*width, *depth) && depth % 2 == 1 =>
if valid_matrix(*width, *depth)
&& asap_sketchlib::WeightedFrequency::check_shape(
asap_sketchlib::FrequencyAlgorithm::CountSketch,
*width as usize,
*depth as usize,
)
.is_ok() =>
{
true
}
Expand Down Expand Up @@ -93,7 +99,7 @@ pub fn validate_summary_kernel(
layers,
..
},
) if crate::summary_kernels::univmon::check_dimensions(
) if asap_sketchlib::UnivMon::check_shape(
*heap_size as usize,
*sketch_rows as usize,
*sketch_cols as usize,
Expand Down
Loading
Loading