Skip to content

Commit

Permalink
relation summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Dec 2, 2024
1 parent e21f74f commit f7de614
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion crates/prover/src/constraint_framework/relation_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fmt::Debug;

use itertools::Itertools;
Expand Down Expand Up @@ -74,7 +75,7 @@ impl<E: FrameworkEval> RelationTrackerComponent<E> {
}

/// Aggregates relation entries.
// TODO(Ohad): write a summarize function, test.
// TODO(Ohad): test.
pub struct RelationTrackerEvaluator<'a> {
entries: Vec<RelationTrackerEntry>,
pub trace_eval:
Expand Down Expand Up @@ -187,3 +188,45 @@ impl<'a> EvalAtRow for RelationTrackerEvaluator<'a> {
}
}
}

type RelationInfo = (String, Vec<(Vec<M31>, M31)>);
pub struct RelationSummary(Vec<RelationInfo>);
impl RelationSummary {
/// Returns the sum of every entry's yields and uses.
/// The result is a map from relation name to a list of values(M31 vectors) and their sum.
pub fn summarize_relations(entries: &[RelationTrackerEntry]) -> Self {
let mut summary = vec![];
let relations = entries.iter().group_by(|entry| entry.relation.clone());
for (relation, entries) in &relations {
let mut relation_sums: HashMap<Vec<_>, M31> = HashMap::new();
for entry in entries {
let mult = relation_sums
.entry(entry.values.clone())
.or_insert(M31::zero());
*mult += entry.mult;
}
let relation_sums = relation_sums.into_iter().collect_vec();
summary.push((relation.clone(), relation_sums));
}
Self(summary)
}

pub fn get_relation_info(&self, relation: &str) -> Option<&[(Vec<M31>, M31)]> {
self.0
.iter()
.find(|(name, _)| name == relation)
.map(|(_, entries)| entries.as_slice())
}
}
impl Debug for RelationSummary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for (relation, entries) in &self.0 {
writeln!(f, "{}:", relation)?;
for (vector, sum) in entries {
let vector = vector.iter().map(|v| v.0).collect_vec();
writeln!(f, " {:?} -> {}", vector, sum)?;
}
}
Ok(())
}
}

1 comment on commit f7de614

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: f7de614 Previous: cd8b37b Ratio
iffts/simd ifft/22 12778984 ns/iter (± 278485) 6306399 ns/iter (± 210024) 2.03
merkle throughput/simd merkle 29484352 ns/iter (± 445037) 13712527 ns/iter (± 579195) 2.15

This comment was automatically generated by workflow using github-action-benchmark.

CC: @shaharsamocha7

Please sign in to comment.