Skip to content

Commit

Permalink
bench: Add benchmark for degree lowering times
Browse files Browse the repository at this point in the history
Also, factor out default degree lowering info into function.

Co-authored-by: Alan Szepieniec <alan@neptune.cash>
  • Loading branch information
Sword-Smith and aszepieniec committed Sep 19, 2024
1 parent 20fd0ea commit 86cf962
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
5 changes: 5 additions & 0 deletions triton-constraint-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ twenty-first.workspace = true
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
test-strategy.workspace = true
divan = "0.1.14"

[lints]
workspace = true

[[bench]]
name = "degree_lowering"
harness = false
90 changes: 90 additions & 0 deletions triton-constraint-builder/benches/degree_lowering.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use constraint_circuit::ConstraintCircuitMonad;
use divan::black_box;
use triton_constraint_builder::Constraints;

fn main() {
divan::main();
}

#[divan::bench(sample_count = 10)]
fn assemble_constraints() {
black_box(Constraints::all());
}

#[divan::bench(sample_count = 10)]
fn initial_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::initial_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
let (initial_main_substitutions, initial_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut constraints, degree_lowering_info);
black_box((initial_main_substitutions, initial_aux_substitutions));
});
}

#[divan::bench(sample_count = 10)]
fn consistency_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::consistency_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
let (consistency_main_substitutions, consistency_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut constraints, degree_lowering_info);
black_box((
consistency_main_substitutions,
consistency_aux_substitutions,
));
});
}

#[divan::bench(sample_count = 1)]
fn transition_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::transition_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
let (transition_main_substitutions, transition_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut constraints, degree_lowering_info);
black_box((transition_main_substitutions, transition_aux_substitutions));
});
}

#[divan::bench(sample_count = 10)]
fn terminal_constraints(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let degree_lowering_info = Constraints::default_degree_lowering_info();
let constraints = Constraints::terminal_constraints();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
let (terminal_main_substitutions, terminal_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut constraints, degree_lowering_info);
black_box((terminal_main_substitutions, terminal_aux_substitutions));
});
}

#[divan::bench(sample_count = 1)]
fn degree_lower_all(bencher: divan::Bencher) {
bencher
.with_inputs(|| {
let constraints = Constraints::all();
let degree_lowering_info = Constraints::default_degree_lowering_info();
(degree_lowering_info, constraints)
})
.bench_values(|(degree_lowering_info, mut constraints)| {
let substitutions =
constraints.lower_to_target_degree_through_substitutions(degree_lowering_info);
black_box(substitutions);
});
}
11 changes: 11 additions & 0 deletions triton-constraint-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ impl Constraints {
}
}

// Implementing Default for DegreeLoweringInfo is impossible because the
// constants are defined in crate `air` but struct `DegreeLoweringInfo` is
// defined in crate `triton-constraint-circuit`. Cfr. orphan rule.
pub fn default_degree_lowering_info() -> DegreeLoweringInfo {
constraint_circuit::DegreeLoweringInfo {
target_degree: air::TARGET_DEGREE,
num_main_cols: air::table::NUM_MAIN_COLUMNS,
num_aux_cols: air::table::NUM_AUX_COLUMNS,
}
}

pub fn initial_constraints() -> Vec<ConstraintCircuitMonad<SingleRowIndicator>> {
let circuit_builder = ConstraintCircuitBuilder::new();
vec![
Expand Down
6 changes: 1 addition & 5 deletions triton-vm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ fn main() {
println!("cargo::rerun-if-changed=build.rs");

let mut constraints = Constraints::all();
let degree_lowering_info = constraint_circuit::DegreeLoweringInfo {
target_degree: air::TARGET_DEGREE,
num_main_cols: air::table::NUM_MAIN_COLUMNS,
num_aux_cols: air::table::NUM_AUX_COLUMNS,
};
let degree_lowering_info = Constraints::default_degree_lowering_info();
let substitutions =
constraints.lower_to_target_degree_through_substitutions(degree_lowering_info);
let deg_low_table = substitutions.generate_degree_lowering_table_code();
Expand Down

0 comments on commit 86cf962

Please sign in to comment.