diff --git a/dft/src/radix_2_bowers.rs b/dft/src/radix_2_bowers.rs index 4a14fa069..501cbc559 100644 --- a/dft/src/radix_2_bowers.rs +++ b/dft/src/radix_2_bowers.rs @@ -4,7 +4,6 @@ use p3_field::{Field, Powers, TwoAdicField}; use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixViewMut}; use p3_matrix::util::reverse_matrix_index_bits; use p3_matrix::Matrix; -use p3_maybe_rayon::prelude::*; use p3_util::{log2_strict_usize, reverse_bits, reverse_slice_index_bits}; use crate::butterflies::{ diff --git a/fri/src/prover.rs b/fri/src/prover.rs index 3158b5163..b52c9376c 100644 --- a/fri/src/prover.rs +++ b/fri/src/prover.rs @@ -10,7 +10,7 @@ use p3_maybe_rayon::prelude::*; use tracing::{info_span, instrument}; use crate::fold_even_odd::fold_even_odd; -use crate::{CommitPhaseProofStep, FriConfig, FriProof, TwoAdicFriPcsGenericConfig, QueryProof}; +use crate::{CommitPhaseProofStep, FriConfig, FriProof, QueryProof}; #[instrument(name = "FRI prover", skip_all)] pub fn prove( diff --git a/fri/src/two_adic_pcs.rs b/fri/src/two_adic_pcs.rs index ea8515b4f..7d9e1a83f 100644 --- a/fri/src/two_adic_pcs.rs +++ b/fri/src/two_adic_pcs.rs @@ -113,12 +113,13 @@ pub struct BatchOpening { pub(crate) opening_proof: >::Proof, } -impl + Sized + Sync + Clone> - Pcs for TwoAdicFriPcs - where C::FriMmcs: Send, - >::Proof: Send, - >::ProverData: Send + Sync, - >::ProverData: Send + Sync + Sized, +impl + Sized + Sync + Clone> Pcs + for TwoAdicFriPcs +where + C::FriMmcs: Send, + >::Proof: Send, + >::ProverData: Send + Sync, + >::ProverData: Send + Sync + Sized, { type Commitment = >::Commitment; type ProverData = >::ProverData; @@ -133,10 +134,11 @@ impl + Sized + Sync + Clon impl + Sized + Sync + Clone> UnivariatePcsWithLde for TwoAdicFriPcs - where C::FriMmcs: Send, - >::Proof: Send, - >::ProverData: Send + Sync, - >::ProverData: Send + Sync + Sized, +where + C::FriMmcs: Send, + >::Proof: Send, + >::ProverData: Send + Sync, + >::ProverData: Send + Sync + Sized, { type Lde<'a> = BitReversedMatrixView<>::Mat<'a>> where Self: 'a; @@ -180,18 +182,19 @@ impl + Sized + Sync + Clon }) .collect() }); - let commitment = self.mmcs.commit(ldes); - commitment + + self.mmcs.commit(ldes) } } impl + Sync + Clone> UnivariatePcs for TwoAdicFriPcs - where C::FriMmcs: Send, - >::Proof: Send, - >::ProverData: Send + Sync, - >::ProverData: Send + Sync + Sized, - C::Challenge: Send + Sync + Sized, +where + C::FriMmcs: Send, + >::Proof: Send, + >::ProverData: Send + Sync, + >::ProverData: Send + Sync + Sized, + C::Challenge: Send + Sync + Sized, { #[instrument(name = "open_multi_batches", skip_all)] fn open_multi_batches( @@ -261,17 +264,23 @@ impl + Sync + Clone> let mut reduced_openings: [_; 32] = core::array::from_fn(|_| None); let mut num_reduced = [0; 32]; - let ys_outer: Vec::<(&Self::ProverData, Vec<&Vec>)> = (*prover_data_and_points) - .into_iter() - .map(|(pd, cs)| { (*pd, (*cs).into_iter().collect::>>()) }) + #[allow(clippy::type_complexity)] + let ys_outer: Vec<(&Self::ProverData, Vec<&Vec>)> = (*prover_data_and_points) + .iter() + .map(|(pd, cs)| (*pd, (*cs).iter().collect::>>())) .collect(); let ys_outer: Vec>>> = ys_outer .par_iter() .map(|(data, points)| { let mats = self.mmcs.get_matrices(data); - izip!(mats, (*points).clone()).collect::>().par_iter().map(|(mat, points_for_mat)| { - points_for_mat.par_iter().map(|&point| { + izip!(mats, (*points).clone()) + .collect::>() + .par_iter() + .map(|(mat, points_for_mat)| { + points_for_mat + .par_iter() + .map(|&point| { // Use Barycentric interpolation to evaluate the matrix at the given point. info_span!("compute opened values with Lagrange interpolation") .in_scope(|| { @@ -283,11 +292,14 @@ impl + Sync + Clone> point, ) }) - }).collect() - }).collect() - }).collect(); + }) + .collect() + }) + .collect() + }) + .collect(); - for (i, (data, points)) in prover_data_and_points.into_iter().enumerate() { + for (i, (data, points)) in prover_data_and_points.iter().enumerate() { let mats = self.mmcs.get_matrices(data); let opened_values_for_round = all_opened_values.pushed_mut(vec![]); for (j, (mat, points_for_mat)) in izip!(mats, *points).enumerate() { @@ -297,7 +309,7 @@ impl + Sync + Clone> debug_assert_eq!(reduced_opening_for_log_height.len(), mat.height()); let opened_values_for_mat = opened_values_for_round.pushed_mut(vec![]); - for (k, &point) in points_for_mat.into_iter().enumerate() { + for (k, &point) in points_for_mat.iter().enumerate() { let _guard = info_span!("reduce matrix quotient", dims = %mat.dimensions()).entered(); diff --git a/interpolation/src/lib.rs b/interpolation/src/lib.rs index 4eb50f774..6ad6463c4 100644 --- a/interpolation/src/lib.rs +++ b/interpolation/src/lib.rs @@ -12,8 +12,8 @@ use p3_field::{ two_adic_coset_zerofier, ExtensionField, Field, TwoAdicField, }; use p3_matrix::MatrixRows; -use p3_util::log2_strict_usize; use p3_maybe_rayon::prelude::*; +use p3_util::log2_strict_usize; /// Given evaluations of a batch of polynomials over the canonical power-of-two subgroup, evaluate /// the polynomials at `point`. @@ -54,19 +54,24 @@ where z }; - let sum: Vec = - g.powers().zip(diff_invs).enumerate() - .map(|(i, (subgroup_i, diff_inv))| { - (coset_evals.row(i).into_iter().collect::>(), (subgroup_i, diff_inv)) - }) - .collect::>() - .into_par_iter() - .map(|(row_i, (subgroup_i, diff_inv))| { - let s = diff_inv * subgroup_i; - row_i.into_iter().map(|y_i| s * y_i).collect() - }) - .reduce(sum_vecs) - .expect("Expected nonempty sum"); + let sum: Vec = g + .powers() + .zip(diff_invs) + .enumerate() + .map(|(i, (subgroup_i, diff_inv))| { + ( + coset_evals.row(i).into_iter().collect::>(), + (subgroup_i, diff_inv), + ) + }) + .collect::>() + .into_par_iter() + .map(|(row_i, (subgroup_i, diff_inv))| { + let s = diff_inv * subgroup_i; + row_i.into_iter().map(|y_i| s * y_i).collect() + }) + .fold_chunks(64, || vec![EF::zero(); width], sum_vecs) + .reduce(|| vec![EF::zero(); width], sum_vecs); let zerofier = two_adic_coset_zerofier::(log_height, EF::from_base(shift), point); let denominator = F::from_canonical_usize(height) * shift.exp_u64(height as u64 - 1); diff --git a/matrix/src/dense.rs b/matrix/src/dense.rs index 315f62a8e..8c8e62784 100644 --- a/matrix/src/dense.rs +++ b/matrix/src/dense.rs @@ -68,8 +68,7 @@ impl RowMajorMatrix { pub fn row_chunks_mut( &mut self, chunk_rows: usize, - ) -> impl Iterator> - { + ) -> impl Iterator> { self.values .chunks_exact_mut(self.width & chunk_rows) .map(|slice| RowMajorMatrixViewMut::new(slice, self.width)) @@ -341,11 +340,7 @@ impl<'a, T> RowMajorMatrixViewMut<'a, T> { self.values.par_chunks_exact_mut(size * self.width) } - pub fn row_chunks_mut( - &mut self, - size: usize, - ) -> impl Iterator - { + pub fn row_chunks_mut(&mut self, size: usize) -> impl Iterator { self.values.chunks_exact_mut(size * self.width) } diff --git a/maybe-rayon/Cargo.toml b/maybe-rayon/Cargo.toml index ef0056f2e..971b34ef2 100644 --- a/maybe-rayon/Cargo.toml +++ b/maybe-rayon/Cargo.toml @@ -6,6 +6,7 @@ version = "0.1.0" edition = "2021" [features] +default = ["parallel"] parallel = ["rayon"] [dependencies]