mirror of
https://github.com/pseXperiments/clookup.git
synced 2026-01-09 15:47:56 -05:00
Apply parallelization
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use std::{cmp::max, io::Cursor};
|
||||
|
||||
use clookup::{
|
||||
core::{precomputation::Table, prover::Prover, verifier::Verifier}, pcs::{multilinear::kzg::MultilinearKzg, PolynomialCommitmentScheme}, sumcheck::{classic::ClassicSumcheck, parallel::ParallelSumcheck}, utils::{
|
||||
core::{precomputation::Table, prover::Prover, verifier::Verifier},
|
||||
pcs::{multilinear::kzg::MultilinearKzg, PolynomialCommitmentScheme},
|
||||
sumcheck::{classic::ClassicSumcheck, parallel::ParallelSumcheck},
|
||||
utils::{
|
||||
end_timer, random_fe, start_timer,
|
||||
transcript::{InMemoryTranscript, Keccak256Transcript},
|
||||
ProtocolError,
|
||||
}
|
||||
},
|
||||
};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use halo2curves::bn256::{Bn256, Fr};
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
use ff::PrimeField;
|
||||
use itertools::Itertools;
|
||||
use rand::RngCore;
|
||||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
use std::{cmp::max, hash::Hash, iter, marker::PhantomData};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -42,7 +43,7 @@ impl<
|
||||
) -> Result<Vec<MultilinearPolynomial<F>>, ProtocolError> {
|
||||
let indices = table.find_indices(&witness)?;
|
||||
let sigma: Vec<MultilinearPolynomial<F>> = transpose(indices)
|
||||
.iter()
|
||||
.par_iter()
|
||||
.map(|idx| MultilinearPolynomial::eval_to_coeff(idx, idx.len().ilog2() as usize))
|
||||
.collect();
|
||||
Ok(sigma)
|
||||
@@ -55,7 +56,7 @@ impl<
|
||||
move |evals: &Vec<F>| {
|
||||
let table_dim = table_poly.num_vars();
|
||||
let sigmas = &evals[1..1 + table_dim];
|
||||
let s = evals.iter().skip(1).take(table_dim).cloned().collect_vec();
|
||||
let s: Vec<F> = evals.par_iter().skip(1).take(table_dim).cloned().collect();
|
||||
(evals[0] - table_poly.eval_by_coeff(s.as_slice())
|
||||
+ sigmas
|
||||
.iter()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use ff::PrimeField;
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
|
||||
use crate::utils::{
|
||||
arithmetic::{barycentric_interpolate, barycentric_weights},
|
||||
@@ -62,20 +62,23 @@ impl<F: PrimeField> SumCheck<F> for ParallelSumcheck {
|
||||
let mut evaluations = vec![];
|
||||
for round_index in 0..pp.num_vars {
|
||||
for k in 0..(r_degree + 1) {
|
||||
for i in 0..virtual_poly.polys()[0].size() {
|
||||
let evaluations_at_k = virtual_poly
|
||||
.polys()
|
||||
.par_iter()
|
||||
.map(|poly| {
|
||||
let o = poly.table()[i].odd;
|
||||
let e = poly.table()[i].even;
|
||||
e + F::from(k as u64) * (o - e)
|
||||
})
|
||||
.collect::<Vec<F>>();
|
||||
|
||||
// apply combine function
|
||||
r_polys[round_index][k] += combine_function(&evaluations_at_k);
|
||||
}
|
||||
let eval_at_k_collection = (0..virtual_poly.polys()[0].size())
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
virtual_poly
|
||||
.polys()
|
||||
.par_iter()
|
||||
.map(|poly| {
|
||||
let o = poly.table()[i].odd;
|
||||
let e = poly.table()[i].even;
|
||||
e + F::from(k as u64) * (o - e)
|
||||
})
|
||||
.collect::<Vec<F>>()
|
||||
})
|
||||
.collect::<Vec<Vec<F>>>();
|
||||
eval_at_k_collection
|
||||
.iter()
|
||||
.for_each(|e| r_polys[round_index][k] += combine_function(e));
|
||||
}
|
||||
// append the round polynomial (i.e. prover message) to the transcript
|
||||
transcript.write_field_elements(&r_polys[round_index])?;
|
||||
|
||||
Reference in New Issue
Block a user