Skip to content

Commit

Permalink
Move around benches files
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmundGoodman committed Jan 11, 2025
1 parent c9a4229 commit e27bc96
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 99 deletions.
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test:
cargo test --release --features=lp
# don't run examples in proof-production mode
cargo test --release --features "test-explanations"


.PHONY: nits
nits:
Expand All @@ -23,4 +23,29 @@ nits:

.PHONY: docs
docs:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open



math.csv:
EGG_BENCH_CSV=math.csv cargo test --test math --release -- --nocapture --test --test-threads=1

lambda.csv:
EGG_BENCH_CSV=lambda.csv cargo test --test lambda --release -- --nocapture --test --test-threads=1

.PHONY: existing-bench
existing-bench: math.csv lambda.csv

.PHONY: clean-bench
clean-bench:
rm math.csv lambda.csv profile.json

.PHONY: bench
bench:
cargo build --profile test && cargo bench

profile.json:
cargo build --profile test && samply record cargo bench

.PHONY: profile
profile: profile.json
Empty file added benches/lambda.rs
Empty file.
2 changes: 1 addition & 1 deletion benches/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,5 @@ pub fn math_tests(c: &mut Criterion) {
group.finish();
}

criterion_group!(benches, math_tests);
criterion_group!(benches, ematching_benches);
criterion_main!(benches);
92 changes: 92 additions & 0 deletions benches/schedulers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
pub mod schedulers {
use egg::*;
use rayon::prelude::*;

pub struct SerialRewriteScheduler;
impl<L: Language, N: Analysis<L>> RewriteScheduler<L, N> for SerialRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, N>,
rewrites: &[&'a Rewrite<L, N>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
rewrites
.iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect()
}
}

pub struct ParallelRewriteScheduler;
impl<L, N> RewriteScheduler<L, N> for ParallelRewriteScheduler
where
L: Language + Sync + Send,
L::Discriminant: Sync + Send,
N: Analysis<L> + Sync + Send,
N::Data: Sync + Send
{
// impl<L: Language + Send + Sync> RewriteScheduler<L, ()> for ParallelRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, N>,
rewrites: &[&'a Rewrite<L, N>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
// This implementation just ignores the limits
// fake `par_map` to enforce Send + Sync, in real life use rayon
// fn par_map<T, F, T2>(slice: &[T], f: F) -> Vec<T2>
// where
// T: Send + Sync,
// F: Fn(&T) -> T2 + Send + Sync,
// T2: Send + Sync,
// {
// slice.iter().map(f).collect()
// }
// Ok(par_map(rewrites, |rw| rw.search(egraph)))

rewrites
.par_iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect() // ::<RunnerResult<Vec<Vec<SearchMatches<'a, L>>>>>()

// TODO: Note that `Sync + Send` traits were added to both language and
// discriminant. Could this impact correctness?
}
}


pub struct RestrictedParallelRewriteScheduler;
impl<L> RewriteScheduler<L, ()> for RestrictedParallelRewriteScheduler
where
L: Language + Sync + Send,
L::Discriminant: Sync + Send,
{
// impl<L: Language + Send + Sync> RewriteScheduler<L, ()> for ParallelRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, ()>,
rewrites: &[&'a Rewrite<L, ()>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
rewrites
.par_iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect()
}
}
}
99 changes: 3 additions & 96 deletions benches/parallel.rs → benches/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,99 +4,10 @@ use rayon::prelude::*;
mod definitions;
use definitions::simple;

use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};

pub struct SerialRewriteScheduler;
impl<L: Language, N: Analysis<L>> RewriteScheduler<L, N> for SerialRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, N>,
rewrites: &[&'a Rewrite<L, N>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
rewrites
.iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect()
}
}

pub struct ParallelRewriteScheduler;
impl<L, N> RewriteScheduler<L, N> for ParallelRewriteScheduler
where
L: Language + Sync + Send,
L::Discriminant: Sync + Send,
N: Analysis<L> + Sync + Send,
N::Data: Sync + Send
{
// impl<L: Language + Send + Sync> RewriteScheduler<L, ()> for ParallelRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, N>,
rewrites: &[&'a Rewrite<L, N>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
// This implementation just ignores the limits
// fake `par_map` to enforce Send + Sync, in real life use rayon
// fn par_map<T, F, T2>(slice: &[T], f: F) -> Vec<T2>
// where
// T: Send + Sync,
// F: Fn(&T) -> T2 + Send + Sync,
// T2: Send + Sync,
// {
// slice.iter().map(f).collect()
// }
// Ok(par_map(rewrites, |rw| rw.search(egraph)))

rewrites
.par_iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect() // ::<RunnerResult<Vec<Vec<SearchMatches<'a, L>>>>>()

// TODO: Note that `Sync + Send` traits were added to both language and
// discriminant. Could this impact correctness?
}
}


pub struct RestrictedParallelRewriteScheduler;
impl<L> RewriteScheduler<L, ()> for RestrictedParallelRewriteScheduler
where
L: Language + Sync + Send,
L::Discriminant: Sync + Send,
{
// impl<L: Language + Send + Sync> RewriteScheduler<L, ()> for ParallelRewriteScheduler {
fn search_rewrites<'a>(
&mut self,
iteration: usize,
egraph: &EGraph<L, ()>,
rewrites: &[&'a Rewrite<L, ()>],
limits: &RunnerLimits,
) -> RunnerResult<Vec<Vec<SearchMatches<'a, L>>>> {
rewrites
.par_iter()
.map(|rw| {
let ms = rw.search(egraph);
limits.check_limits(iteration, egraph)?;
Ok(ms)
})
.collect()
}
}



mod schedulers;
use schedulers::schedulers::*;

use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};


fn serial_simplify(s: &str) -> String {
Expand Down Expand Up @@ -177,8 +88,6 @@ pub fn comparison_simple_bench(c: &mut Criterion) {
}




// fn math_serial_simplify_root() {
// egg::test::test_runner(
// "math_simplify_root",
Expand Down Expand Up @@ -208,7 +117,5 @@ pub fn comparison_simple_bench(c: &mut Criterion) {
// }




criterion_group!(benches, comparison_simple_bench);
criterion_main!(benches);

0 comments on commit e27bc96

Please sign in to comment.