mirror of https://github.com/zcash/halo2.git
fix: Upstream concurrent poly generation fixes
This commit is contained in:
parent
e49cf60f59
commit
a4cc9f60e0
|
@ -2,18 +2,15 @@ use std::iter;
|
|||
|
||||
use ff::Field;
|
||||
use group::Curve;
|
||||
use rand_core::RngCore;
|
||||
|
||||
#[cfg(feature = "multicore")]
|
||||
use maybe_rayon::{
|
||||
current_num_threads,
|
||||
prelude::{IntoParallelRefMutIterator, ParallelIterator},
|
||||
};
|
||||
use maybe_rayon::{current_num_threads, prelude::*};
|
||||
#[cfg(feature = "multicore")]
|
||||
use rand_chacha::ChaCha20Rng;
|
||||
#[cfg(feature = "multicore")]
|
||||
use rand_core::SeedableRng;
|
||||
|
||||
use rand_core::RngCore;
|
||||
|
||||
use super::Argument;
|
||||
use crate::{
|
||||
arithmetic::{eval_polynomial, CurveAffine},
|
||||
|
@ -55,9 +52,11 @@ impl<C: CurveAffine> Argument<C> {
|
|||
#[cfg(feature = "multicore")]
|
||||
let random_poly = {
|
||||
let n_threads = current_num_threads();
|
||||
let needed_scalars = (1usize << domain.k as usize) / n_threads;
|
||||
let n = 1usize << domain.k() as usize;
|
||||
let n_chunks = n_threads + if n % n_threads != 0 { 1 } else { 0 };
|
||||
let mut rand_vec = vec![C::Scalar::ZERO; n];
|
||||
|
||||
let mut thread_seeds: Vec<ChaCha20Rng> = (0..n_threads)
|
||||
let mut thread_seeds: Vec<ChaCha20Rng> = (0..n_chunks)
|
||||
.into_iter()
|
||||
.map(|_| {
|
||||
let mut seed = [0u8; 32];
|
||||
|
@ -66,17 +65,16 @@ impl<C: CurveAffine> Argument<C> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let rand_vec: Vec<C::Scalar> = thread_seeds
|
||||
thread_seeds
|
||||
.par_iter_mut()
|
||||
.flat_map(|mut rng| {
|
||||
(0..needed_scalars)
|
||||
.into_iter()
|
||||
.map(|_| C::Scalar::random(&mut rng))
|
||||
.collect::<Vec<C::Scalar>>()
|
||||
})
|
||||
.collect();
|
||||
.zip_eq(rand_vec.par_chunks_mut(n / n_threads))
|
||||
.for_each(|(mut rng, chunk)| {
|
||||
chunk
|
||||
.iter_mut()
|
||||
.for_each(|v| *v = C::Scalar::random(&mut rng))
|
||||
});
|
||||
|
||||
Polynomial::<C::ScalarExt, Coeff>::from_evals(rand_vec)
|
||||
domain.coeff_from_vec(rand_vec)
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "multicore"))]
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::marker::PhantomData;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct EvaluationDomain<F: Field> {
|
||||
n: u64,
|
||||
pub(crate) k: u32,
|
||||
k: u32,
|
||||
extended_k: u32,
|
||||
omega: F,
|
||||
omega_inv: F,
|
||||
|
@ -142,6 +142,11 @@ impl<F: WithSmallOrderMulGroup<3>> EvaluationDomain<F> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the `k` or Degree associated to the domain.
|
||||
pub(crate) fn k(&self) -> usize {
|
||||
self.k as usize
|
||||
}
|
||||
|
||||
/// Obtains a polynomial in Lagrange form when given a vector of Lagrange
|
||||
/// coefficients of size `n`; panics if the provided vector is the wrong
|
||||
/// length.
|
||||
|
|
Loading…
Reference in New Issue