Parallelize vanishing poly computation

This commit is contained in:
Daniel Lubarov 2021-04-01 13:46:24 -07:00
parent 8302c10f21
commit 524a974de3
3 changed files with 15 additions and 23 deletions

View File

@ -1,5 +1,5 @@
use std::hash::{Hash, Hasher};
use std::rc::Rc;
use std::sync::Arc;
use crate::circuit_builder::CircuitBuilder;
use crate::constraint_polynomial::{EvaluationTargets, EvaluationVars};
@ -8,7 +8,7 @@ use crate::generator::WitnessGenerator;
use crate::target::Target;
/// A custom gate.
pub trait Gate<F: Field>: 'static {
pub trait Gate<F: Field>: 'static + Send + Sync {
fn id(&self) -> String;
fn eval_unfiltered(&self, vars: EvaluationVars<F>) -> Vec<F>;
@ -45,11 +45,11 @@ pub trait Gate<F: Field>: 'static {
/// A wrapper around an `Rc<Gate>` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs.
#[derive(Clone)]
pub struct GateRef<F: Field>(pub(crate) Rc<dyn Gate<F>>);
pub struct GateRef<F: Field>(pub(crate) Arc<dyn Gate<F>>);
impl<F: Field> GateRef<F> {
pub fn new<G: Gate<F>>(gate: G) -> GateRef<F> {
GateRef(Rc::new(gate))
GateRef(Arc::new(gate))
}
}

View File

@ -66,7 +66,7 @@ pub(crate) fn generate_partial_witness<F: Field>(
}
/// A generator participates in the generation of the witness.
pub trait WitnessGenerator<F: Field>: 'static + Debug {
pub trait WitnessGenerator<F: Field>: 'static + Debug + Send + Sync {
/// Targets to be "watched" by this generator. Whenever a target in the watch list is populated,
/// the generator will be queued to run.
fn watch_list(&self) -> Vec<Target>;
@ -80,7 +80,7 @@ pub trait WitnessGenerator<F: Field>: 'static + Debug {
/// A generator which runs once after a list of dependencies is present in the witness.
// TODO: Remove Debug. Here temporarily to debug generator issues.
pub trait SimpleGenerator<F: Field>: 'static + Debug {
pub trait SimpleGenerator<F: Field>: 'static + Debug + Send + Sync {
fn dependencies(&self) -> Vec<Target>;
fn run_once(&self, witness: &PartialWitness<F>) -> PartialWitness<F>;

View File

@ -14,7 +14,7 @@ use crate::plonk_common::{eval_l_1, reduce_with_powers_multi};
use crate::polynomial::division::divide_by_z_h;
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::proof::Proof;
use crate::util::transpose_poly_values;
use crate::util::{transpose_poly_values, transpose};
use crate::wire::Wire;
use crate::witness::PartialWitness;
@ -146,11 +146,9 @@ fn compute_vanishing_polys<F: Field>(
let lde_gen = common_data.lde_generator();
let num_checks = common_data.config.num_checks;
let mut values = vec![Vec::with_capacity(lde_size); num_checks];
let mut point = F::ONE;
for i in 0..lde_size {
debug_assert!(point != F::ONE);
// let mut values = vec![Vec::with_capacity(lde_size); num_checks];
let points = F::cyclic_subgroup_known_order(lde_gen, lde_size);
let values: Vec<Vec<F>> = points.into_par_iter().enumerate().map(|(i, x)| {
let i_next = (i + 1) % lde_size;
let local_wires = &wire_ldes_t[i];
let next_wires = &wire_ldes_t[i_next];
@ -169,18 +167,12 @@ fn compute_vanishing_polys<F: Field>(
local_wires,
next_wires,
};
let values_i = compute_vanishing_poly_entry(
common_data, point, vars, local_plonk_zs, next_plonk_zs, s_sigmas, beta, gamma, alphas);
for check in 0..num_checks {
values[check].push(values_i[check])
}
compute_vanishing_poly_entry(
common_data, x, vars, local_plonk_zs, next_plonk_zs, s_sigmas, beta, gamma, alphas)
}).collect();
point *= lde_gen;
}
debug_assert_eq!(point, F::ONE);
values.into_iter()
transpose(&values)
.into_iter()
.map(PolynomialValues::new)
.collect()
}