Skip to content

Commit

Permalink
[chore] add more detailed profiling (#23)
Browse files Browse the repository at this point in the history
* chore: add more timers to `evaluate_h` for "profile" feature

* chore: add timer for synthesize and `next_phase` commitments

* chore: turn off profile as default feature

* chore: fix timer location
  • Loading branch information
jonathanpwang authored Nov 4, 2023
1 parent d2b79f0 commit 2e98a5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions halo2_proofs/src/plonk/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::{
arithmetic::{parallelize, CurveAffine},
poly::{Coeff, ExtendedLagrangeCoeff, Polynomial, Rotation},
};
#[cfg(feature = "profile")]
use ark_std::{end_timer, start_timer};
use group::ff::{Field, PrimeField, WithSmallOrderMulGroup};

use super::{shuffle, ConstraintSystem, Expression};
Expand Down Expand Up @@ -322,6 +324,8 @@ impl<C: CurveAffine> Evaluator<C> {
let l_active_row = &pk.l_active_row;
let p = &pk.vk.cs.permutation;

#[cfg(feature = "profile")]
let start1 = start_timer!(|| "FFT coeff to extended for advice");
// Calculate the advice and instance cosets
let advice: Vec<Vec<Polynomial<C::Scalar, ExtendedLagrangeCoeff>>> = advice_polys
.iter()
Expand All @@ -332,6 +336,10 @@ impl<C: CurveAffine> Evaluator<C> {
.collect()
})
.collect();
#[cfg(feature = "profile")]
end_timer!(start1);
#[cfg(feature = "profile")]
let start2 = start_timer!(|| "FFT coeff to extended for instance");
let instance: Vec<Vec<Polynomial<C::Scalar, ExtendedLagrangeCoeff>>> = instance_polys
.iter()
.map(|instance_polys| {
Expand All @@ -341,6 +349,8 @@ impl<C: CurveAffine> Evaluator<C> {
.collect()
})
.collect();
#[cfg(feature = "profile")]
end_timer!(start2);

let mut values = domain.empty_extended();

Expand All @@ -353,6 +363,8 @@ impl<C: CurveAffine> Evaluator<C> {
.zip(shuffles.iter())
.zip(permutations.iter())
{
#[cfg(feature = "profile")]
let start3 = start_timer!(|| "Custom gates");
// Custom gates
multicore::scope(|scope| {
let chunk_size = (size + num_threads - 1) / num_threads;
Expand Down Expand Up @@ -381,7 +393,11 @@ impl<C: CurveAffine> Evaluator<C> {
});
}
});
#[cfg(feature = "profile")]
end_timer!(start3);

#[cfg(feature = "profile")]
let start4 = start_timer!(|| "Permutations");
// Permutations
let sets = &permutation.sets;
if !sets.is_empty() {
Expand Down Expand Up @@ -463,7 +479,11 @@ impl<C: CurveAffine> Evaluator<C> {
}
});
}
#[cfg(feature = "profile")]
end_timer!(start4);

#[cfg(feature = "profile")]
let start5 = start_timer!(|| "Lookups");
// Lookups
for (n, lookup) in lookups.iter().enumerate() {
// Polynomials required for this lookup.
Expand Down Expand Up @@ -534,6 +554,8 @@ impl<C: CurveAffine> Evaluator<C> {
}
});
}
#[cfg(feature = "profile")]
end_timer!(start5);

// Shuffle constraints
for (n, shuffle) in shuffles.iter().enumerate() {
Expand Down
11 changes: 11 additions & 0 deletions halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ where

fn next_phase(&mut self) {
let phase = self.current_phase.to_u8() as usize;
#[cfg(feature = "profile")]
let start1 = start_timer!(|| format!("Phase {phase} inversion and MSM commitment"));
if phase == 0 {
// Absorb instances into transcript.
// Do this here and not earlier in case we want to be able to mutate
Expand Down Expand Up @@ -370,6 +372,8 @@ where
assert!(existing.is_none());
}
self.current_phase = self.current_phase.next();
#[cfg(feature = "profile")]
end_timer!(start1);
}
}

Expand Down Expand Up @@ -431,6 +435,11 @@ where
// while loop is for compatibility with circuits that do not use the new `next_phase` API to manage phases
// If the circuit uses the new API, then the while loop will only execute once
while witness.current_phase.to_u8() < num_phases as u8 {
#[cfg(feature = "profile")]
let syn_time = start_timer!(|| format!(
"Synthesize time starting from phase {} (synthesize may cross multiple phases)",
witness.current_phase.to_u8()
));
// Synthesize the circuit to obtain the witness and other information.
ConcreteCircuit::FloorPlanner::synthesize(
&mut witness,
Expand All @@ -439,6 +448,8 @@ where
meta.constants.clone(),
)
.unwrap();
#[cfg(feature = "profile")]
end_timer!(syn_time);
if witness.current_phase.to_u8() < num_phases as u8 {
witness.next_phase();
}
Expand Down

0 comments on commit 2e98a5c

Please sign in to comment.