Skip to content

Commit

Permalink
Merge pull request #51 from 0xfuturistic/feat/parallelize_to_grand_pr…
Browse files Browse the repository at this point in the history
…oducts

feat(parallelize): add parallelism to to_grand_products
  • Loading branch information
moodlezoup authored Sep 25, 2023
2 parents e52d160 + ddcce1c commit 6911db4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/lasso/memory_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ use ark_ff::{Field, PrimeField};
use ark_serialize::*;
use ark_std::{One, Zero};
use merlin::Transcript;
use std::marker::Sync;

#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
pub struct MemoryCheckingProof<
G: CurveGroup,
const C: usize,
const M: usize,
S: SubtableStrategy<G::ScalarField, C, M>,
S: SubtableStrategy<G::ScalarField, C, M> + Sync,
> where
[(); S::NUM_MEMORIES]: Sized,
{
proof_prod_layer: ProductLayerProof<G::ScalarField, { S::NUM_MEMORIES }>,
proof_hash_layer: HashLayerProof<G, C, M, S>,
}

impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M>>
impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M> + Sync>
MemoryCheckingProof<G, C, M, S>
where
[(); S::NUM_SUBTABLES]: Sized,
Expand Down Expand Up @@ -666,7 +667,7 @@ impl<F: PrimeField, const NUM_MEMORIES: usize> ProductLayerProof<F, NUM_MEMORIES
/// - `transcript`: The proof transcript, used for Fiat-Shamir.
#[tracing::instrument(skip_all, name = "ProductLayer.prove")]
pub fn prove<G>(
grand_products: &mut [GrandProducts<F>; NUM_MEMORIES],
grand_products: &mut Vec<GrandProducts<F>>,
transcript: &mut Transcript,
) -> (Self, Vec<F>, Vec<F>)
where
Expand Down
5 changes: 3 additions & 2 deletions src/lasso/surge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use ark_serialize::*;

use ark_std::log2;
use merlin::Transcript;
use std::marker::Sync;

pub struct SparsePolyCommitmentGens<G> {
pub gens_combined_l_variate: PolyCommitmentGens<G>,
Expand Down Expand Up @@ -93,7 +94,7 @@ pub struct SparsePolynomialEvaluationProof<
G: CurveGroup,
const C: usize,
const M: usize,
S: SubtableStrategy<G::ScalarField, C, M>,
S: SubtableStrategy<G::ScalarField, C, M> + Sync,
> where
[(); S::NUM_MEMORIES]: Sized,
{
Expand All @@ -102,7 +103,7 @@ pub struct SparsePolynomialEvaluationProof<
memory_check: MemoryCheckingProof<G, C, M, S>,
}

impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M>>
impl<G: CurveGroup, const C: usize, const M: usize, S: SubtableStrategy<G::ScalarField, C, M> + Sync>
SparsePolynomialEvaluationProof<G, C, M, S>
where
[(); S::NUM_SUBTABLES]: Sized,
Expand Down
2 changes: 1 addition & 1 deletion src/subprotocols/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<F: PrimeField> SumcheckInstanceProof<F> {
let iterator = (0..mle_half).into_par_iter();

#[cfg(not(feature = "multicore"))]
let iterator = (0..mle_half).iter();
let iterator = 0..mle_half;

let accum: Vec<Vec<F>> = iterator
.map(|poly_term_i| {
Expand Down
54 changes: 39 additions & 15 deletions src/subtables/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::marker::PhantomData;
use std::marker::{PhantomData, Sync};

use ark_ec::CurveGroup;
use ark_ff::PrimeField;
Expand Down Expand Up @@ -107,7 +107,7 @@ where
/// Stores the non-sparse evaluations of T[k] for each of the 'c'-dimensions as DensePolynomials, enables combination and commitment.
impl<F: PrimeField, const C: usize, const M: usize, S> Subtables<F, C, M, S>
where
S: SubtableStrategy<F, C, M>,
S: SubtableStrategy<F, C, M> + Sync,
[(); S::NUM_SUBTABLES]: Sized,
[(); S::NUM_MEMORIES]: Sized,
{
Expand Down Expand Up @@ -135,19 +135,43 @@ where
&self,
dense: &DensifiedRepresentation<F, C>,
r_mem_check: &(F, F),
) -> [GrandProducts<F>; S::NUM_MEMORIES] {
std::array::from_fn(|i| {
let subtable = &self.subtable_entries[S::memory_to_subtable_index(i)];
let j = S::memory_to_dimension_index(i);
GrandProducts::new(
subtable,
&dense.dim[j],
&dense.dim_usize[j],
&dense.read[j],
&dense.r#final[j],
r_mem_check,
)
})
) -> Vec<GrandProducts<F>> {
#[cfg(feature = "multicore")]
{
(0..S::NUM_MEMORIES)
.into_par_iter()
.map(|i| {
let subtable = &self.subtable_entries[S::memory_to_subtable_index(i)];
let j = S::memory_to_dimension_index(i);
GrandProducts::new(
subtable,
&dense.dim[j],
&dense.dim_usize[j],
&dense.read[j],
&dense.r#final[j],
r_mem_check,
)
})
.collect::<Vec<_>>()
}

#[cfg(not(feature = "multicore"))]
{
(0..S::NUM_MEMORIES)
.map(|i| {
let subtable = &self.subtable_entries[S::memory_to_subtable_index(i)];
let j = S::memory_to_dimension_index(i);
GrandProducts::new(
subtable,
&dense.dim[j],
&dense.dim_usize[j],
&dense.read[j],
&dense.r#final[j],
r_mem_check,
)
})
.collect::<Vec<_>>()
}
}

#[tracing::instrument(skip_all, name = "Subtables.commit")]
Expand Down

0 comments on commit 6911db4

Please sign in to comment.