Skip to content

Commit

Permalink
Turn off constraint parallelisation for small vector size?
Browse files Browse the repository at this point in the history
  • Loading branch information
volhovm committed Feb 7, 2025
1 parent fc7b5ab commit a979221
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion kimchi/src/circuits/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,33 @@ impl<F: PrimeField, G: KimchiCurve<ScalarField = F>, OpeningProof: OpenProof<G>>
impl<F: PrimeField> ConstraintSystem<F> {
/// evaluate witness polynomials over domains
pub fn evaluate(&self, w: &[DP<F>; COLUMNS], z: &DP<F>) -> WitnessOverDomains<F> {
// this optimisation saves 100ms
// this optimisation saves 100ms for the prover.
// but it adds 3% = 2.5ms to the verifier on small (1k rows) circuits.

// the idea is to have threading minimised below a certain threshold.
let min_len = {
let threads_to_use = if w[0].len() <= 2048 {
1
} else {
rayon::max_num_threads()
};
// min batch size is COLUMNS, when threads_to_use == 1,
// in which case every iterator will use one thread
std::cmp::max(COLUMNS, COLUMNS / threads_to_use)
};

// compute shifted witness polynomials
let w8: [E<F, D<F>>; COLUMNS] = (0..COLUMNS)
.into_par_iter()
.with_min_len(min_len)
.map(|i| w[i].evaluate_over_domain_by_ref(self.domain.d8))
.collect::<Vec<_>>()
.try_into()
.unwrap();

let w4: [E<F, D<F>>; COLUMNS] = (0..COLUMNS)
.into_par_iter()
.with_min_len(min_len)
.map(|i| {
E::<F, D<F>>::from_vec_and_domain(
(0..self.domain.d4.size)
Expand All @@ -405,13 +420,15 @@ impl<F: PrimeField> ConstraintSystem<F> {

let d4_next_w: [_; COLUMNS] = (0..COLUMNS)
.into_par_iter()
.with_min_len(min_len)
.map(|i| w4[i].shift(4))
.collect::<Vec<_>>()
.try_into()
.unwrap();

let d8_next_w: [_; COLUMNS] = (0..COLUMNS)
.into_par_iter()
.with_min_len(min_len)
.map(|i| w8[i].shift(8))
.collect::<Vec<_>>()
.try_into()
Expand Down

0 comments on commit a979221

Please sign in to comment.