From 6b516922df0a86448bd4c80c6934b83f30cc0314 Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Sat, 13 Sep 2025 05:22:22 +0530 Subject: [PATCH 1/6] feat: using p3-maybe-rayon for mpcs and witness crates --- Cargo.lock | 1 + crates/mpcs/Cargo.toml | 5 ++--- crates/mpcs/benches/interpolate.rs | 2 +- crates/mpcs/src/basefold/commit_phase.rs | 6 +----- crates/mpcs/src/util.rs | 2 +- crates/witness/src/lib.rs | 5 +---- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5db9561..12c04f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,6 +471,7 @@ dependencies = [ "multilinear_extensions", "num-integer", "p3", + "p3-maybe-rayon", "rand", "rand_chacha", "rayon", diff --git a/crates/mpcs/Cargo.toml b/crates/mpcs/Cargo.toml index 20e3063..a84ec4b 100644 --- a/crates/mpcs/Cargo.toml +++ b/crates/mpcs/Cargo.toml @@ -18,6 +18,7 @@ whir.workspace = true multilinear_extensions.workspace = true num-integer = "0.1" p3.workspace = true +p3-maybe-rayon.workspace = true rand.workspace = true rand_chacha.workspace = true rayon = { workspace = true, optional = true } @@ -32,8 +33,6 @@ witness.workspace = true criterion.workspace = true [features] -benchmark = ["parallel"] -default = ["parallel"] # Add "sanity-check" to debug nightly-features = [ "p3/nightly-features", "ff_ext/nightly-features", @@ -43,7 +42,7 @@ nightly-features = [ "whir/nightly-features", "witness/nightly-features", ] -parallel = ["dep:rayon"] +parallel = ["p3-maybe-rayon/parallel","dep:rayon"] print-trace = ["whir/print-trace"] sanity-check = [] diff --git a/crates/mpcs/benches/interpolate.rs b/crates/mpcs/benches/interpolate.rs index 435a9a6..f7298bd 100644 --- a/crates/mpcs/benches/interpolate.rs +++ b/crates/mpcs/benches/interpolate.rs @@ -7,9 +7,9 @@ use itertools::Itertools; use mpcs::util::arithmetic::interpolate_field_type_over_boolean_hypercube; use multilinear_extensions::mle::{FieldType, MultilinearExtension}; +use p3::maybe_rayon::prelude::*; use rand::{SeedableRng, rngs::OsRng}; use rand_chacha::ChaCha8Rng; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; type E = GoldilocksExt2; diff --git a/crates/mpcs/src/basefold/commit_phase.rs b/crates/mpcs/src/basefold/commit_phase.rs index d563334..bcf1aff 100644 --- a/crates/mpcs/src/basefold/commit_phase.rs +++ b/crates/mpcs/src/basefold/commit_phase.rs @@ -38,11 +38,7 @@ use multilinear_extensions::{ mle::{IntoMLE, MultilinearExtension}, virtual_poly::build_eq_x_r_vec, }; -use rayon::{ - iter::{IntoParallelIterator, IntoParallelRefMutIterator}, - prelude::{IndexedParallelIterator, ParallelIterator}, - slice::ParallelSlice, -}; +use p3::maybe_rayon::prelude::*; use super::structure::BasefoldCommitmentWithWitness; diff --git a/crates/mpcs/src/util.rs b/crates/mpcs/src/util.rs index c6cabe0..24a3495 100644 --- a/crates/mpcs/src/util.rs +++ b/crates/mpcs/src/util.rs @@ -101,7 +101,7 @@ pub(crate) fn codeword_fold_with_challenge( lo + challenge * (hi - lo) } -#[cfg(any(test, feature = "benchmark"))] +#[cfg(any(test))] pub mod test { use ff_ext::FromUniformBytes; use rand::{ diff --git a/crates/witness/src/lib.rs b/crates/witness/src/lib.rs index dc961f4..dda65ae 100644 --- a/crates/witness/src/lib.rs +++ b/crates/witness/src/lib.rs @@ -2,12 +2,9 @@ use multilinear_extensions::mle::{IntoMLE, MultilinearExtension}; use p3::{ field::{Field, FieldAlgebra}, matrix::Matrix, + maybe_rayon::prelude::*, }; use rand::{Rng, distributions::Standard, prelude::Distribution}; -use rayon::{ - iter::{IndexedParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator}, - slice::ParallelSliceMut, -}; use std::{ ops::{Deref, DerefMut, Index}, slice::{Chunks, ChunksMut}, From 2f107bf1a701ba6f3c313553960baaf21b85ac36 Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Sat, 13 Sep 2025 05:30:00 +0530 Subject: [PATCH 2/6] feat: using p3-maybe-rayon for whir crate --- Cargo.lock | 1 + crates/whir/Cargo.toml | 3 ++- crates/whir/src/crypto/mod.rs | 2 +- crates/whir/src/ntt/mod.rs | 4 ++-- crates/whir/src/ntt/transpose.rs | 6 ++++-- crates/whir/src/ntt/wavelet.rs | 2 +- crates/whir/src/sumcheck/prover_batched.rs | 4 ++-- crates/whir/src/sumcheck/prover_single.rs | 14 ++++++-------- crates/whir/src/utils.rs | 5 +---- crates/whir/src/whir/batch/committer.rs | 2 +- crates/whir/src/whir/batch/prover.rs | 2 +- crates/whir/src/whir/batch/verifier.rs | 3 +-- crates/whir/src/whir/fold.rs | 4 ++-- crates/whir/src/whir/prover.rs | 3 +-- crates/whir/src/whir/verifier.rs | 2 +- 15 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12c04f0..5905a06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1379,6 +1379,7 @@ dependencies = [ "itertools 0.14.0", "multilinear_extensions", "p3", + "p3-maybe-rayon", "rand", "rand_chacha", "rayon", diff --git a/crates/whir/Cargo.toml b/crates/whir/Cargo.toml index eacf319..f270f5d 100644 --- a/crates/whir/Cargo.toml +++ b/crates/whir/Cargo.toml @@ -18,6 +18,7 @@ clap.workspace = true ff_ext = { path = "../ff_ext" } multilinear_extensions = { path = "../multilinear_extensions" } p3.workspace = true +p3-maybe-rayon.workspace = true rand = "0.8" rand_chacha = "0.3" rayon = { workspace = true, optional = true } @@ -42,6 +43,6 @@ nightly-features = [ "transcript/nightly-features", "witness/nightly-features", ] -parallel = ["dep:rayon"] +parallel = ["p3-maybe-rayon/parallel","dep:rayon"] print-trace = ["tracing/log"] rayon = ["dep:rayon"] diff --git a/crates/whir/src/crypto/mod.rs b/crates/whir/src/crypto/mod.rs index c816640..daa6feb 100644 --- a/crates/whir/src/crypto/mod.rs +++ b/crates/whir/src/crypto/mod.rs @@ -5,8 +5,8 @@ use p3::{ Dimensions, dense::{DenseMatrix, RowMajorMatrix}, }, + maybe_rayon::prelude::*, }; -use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use transcript::Transcript; diff --git a/crates/whir/src/ntt/mod.rs b/crates/whir/src/ntt/mod.rs index 9d2959a..dd39431 100644 --- a/crates/whir/src/ntt/mod.rs +++ b/crates/whir/src/ntt/mod.rs @@ -9,13 +9,13 @@ mod wavelet; use self::matrix::MatrixMut; +#[cfg(feature = "parallel")] +use p3::maybe_rayon::prelude::*; use p3::{ dft::{Radix2DitParallel, TwoAdicSubgroupDft}, field::TwoAdicField, matrix::Matrix, }; -#[cfg(feature = "parallel")] -use rayon::prelude::*; use tracing::instrument; use witness::{InstancePaddingStrategy, RowMajorMatrix}; diff --git a/crates/whir/src/ntt/transpose.rs b/crates/whir/src/ntt/transpose.rs index cc7fb48..b27ec83 100644 --- a/crates/whir/src/ntt/transpose.rs +++ b/crates/whir/src/ntt/transpose.rs @@ -3,8 +3,10 @@ use crate::ntt::matrix_skip::MatrixMutSkip; use super::{super::utils::is_power_of_two, MatrixMut, utils::workload_size}; use std::mem::swap; -use p3::matrix::{Matrix, dense::RowMajorMatrix}; -use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; +use p3::{ + matrix::{Matrix, dense::RowMajorMatrix}, + maybe_rayon::prelude::*, +}; #[cfg(feature = "parallel")] use rayon::join; use sumcheck::macros::{entered_span, exit_span}; diff --git a/crates/whir/src/ntt/wavelet.rs b/crates/whir/src/ntt/wavelet.rs index d5a7b84..96cad52 100644 --- a/crates/whir/src/ntt/wavelet.rs +++ b/crates/whir/src/ntt/wavelet.rs @@ -3,7 +3,7 @@ use p3::field::Field; use std::cmp::max; #[cfg(feature = "parallel")] -use rayon::prelude::*; +use p3::maybe_rayon::prelude::*; /// Fast Wavelet Transform. /// diff --git a/crates/whir/src/sumcheck/prover_batched.rs b/crates/whir/src/sumcheck/prover_batched.rs index ef3c202..306cc9d 100644 --- a/crates/whir/src/sumcheck/prover_batched.rs +++ b/crates/whir/src/sumcheck/prover_batched.rs @@ -1,9 +1,9 @@ use super::proof::SumcheckPolynomial; use crate::sumcheck::prover_single::SumcheckSingle; use ff_ext::ExtensionField; -use p3::{field::Field, util::log2_strict_usize}; +use p3::{field::Field, maybe_rayon::prelude::*, util::log2_strict_usize}; #[cfg(feature = "parallel")] -use rayon::{join, prelude::*}; +use rayon::join; pub struct SumcheckBatched { // The evaluation on each p and eq diff --git a/crates/whir/src/sumcheck/prover_single.rs b/crates/whir/src/sumcheck/prover_single.rs index 73a35f8..6de13a0 100644 --- a/crates/whir/src/sumcheck/prover_single.rs +++ b/crates/whir/src/sumcheck/prover_single.rs @@ -1,9 +1,9 @@ use super::proof::SumcheckPolynomial; use ff_ext::ExtensionField; -use p3::util::log2_strict_usize; +use p3::{maybe_rayon::prelude::*, util::log2_strict_usize}; #[cfg(feature = "parallel")] -use rayon::{join, prelude::*}; +use rayon::join; pub struct SumcheckSingle { // The evaluation of p @@ -261,12 +261,10 @@ mod tests { let eval = MultilinearExtension::from_evaluations_ext_vec(2, polynomial.clone()) .evaluate(&eval_point); - let mut prover = SumcheckSingle::new( - polynomial, - &[eval_point], - &[E::from_canonical_u64(1)], - &[eval], - ); + let mut prover = + SumcheckSingle::new(polynomial, &[eval_point], &[E::from_canonical_u64(1)], &[ + eval, + ]); let poly_1 = prover.compute_sumcheck_polynomial(); diff --git a/crates/whir/src/utils.rs b/crates/whir/src/utils.rs index 6ac3cd2..7e39e9b 100644 --- a/crates/whir/src/utils.rs +++ b/crates/whir/src/utils.rs @@ -4,10 +4,7 @@ use multilinear_extensions::mle::FieldType; use p3::{ field::Field, matrix::{Matrix, dense::RowMajorMatrix}, -}; -use rayon::{ - iter::ParallelIterator, - slice::{ParallelSlice, ParallelSliceMut}, + maybe_rayon::prelude::*, }; use std::collections::BTreeSet; use sumcheck::macros::{entered_span, exit_span}; diff --git a/crates/whir/src/whir/batch/committer.rs b/crates/whir/src/whir/batch/committer.rs index 2b69e21..3a074a4 100644 --- a/crates/whir/src/whir/batch/committer.rs +++ b/crates/whir/src/whir/batch/committer.rs @@ -19,7 +19,7 @@ use sumcheck::macros::{entered_span, exit_span}; use transcript::{BasicTranscript, Transcript}; #[cfg(feature = "parallel")] -use rayon::prelude::*; +use p3::maybe_rayon::prelude::*; #[derive(Debug)] pub struct Witnesses { diff --git a/crates/whir/src/whir/batch/prover.rs b/crates/whir/src/whir/batch/prover.rs index 1c0f744..5aed563 100644 --- a/crates/whir/src/whir/batch/prover.rs +++ b/crates/whir/src/whir/batch/prover.rs @@ -27,7 +27,7 @@ use transcript::Transcript; use crate::whir::fs_utils::get_challenge_stir_queries; #[cfg(feature = "parallel")] -use rayon::prelude::*; +use p3::maybe_rayon::prelude::*; struct RoundStateBatch<'a, E: ExtensionField> { round_state: RoundState<'a, E>, diff --git a/crates/whir/src/whir/batch/verifier.rs b/crates/whir/src/whir/batch/verifier.rs index 445d118..64ada43 100644 --- a/crates/whir/src/whir/batch/verifier.rs +++ b/crates/whir/src/whir/batch/verifier.rs @@ -17,8 +17,7 @@ use crate::{ use ff_ext::{ExtensionField, PoseidonField}; use itertools::zip_eq; use multilinear_extensions::{mle::MultilinearExtension, virtual_poly::eq_eval}; -use p3::{commit::Mmcs, util::log2_strict_usize}; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +use p3::{commit::Mmcs, maybe_rayon::prelude::*, util::log2_strict_usize}; use sumcheck::macros::{entered_span, exit_span}; use transcript::Transcript; diff --git a/crates/whir/src/whir/fold.rs b/crates/whir/src/whir/fold.rs index f193178..293f607 100644 --- a/crates/whir/src/whir/fold.rs +++ b/crates/whir/src/whir/fold.rs @@ -3,12 +3,12 @@ use crate::{ parameters::FoldType, }; +#[cfg(feature = "parallel")] +use p3::maybe_rayon::prelude::*; use p3::{ field::{Field, TwoAdicField}, matrix::Matrix, }; -#[cfg(feature = "parallel")] -use rayon::prelude::*; /// Given the evaluation of f on the coset specified by coset_offset * /// Compute the fold on that point diff --git a/crates/whir/src/whir/prover.rs b/crates/whir/src/whir/prover.rs index 1a90df7..fe41305 100644 --- a/crates/whir/src/whir/prover.rs +++ b/crates/whir/src/whir/prover.rs @@ -14,8 +14,7 @@ use crate::{ }; use ff_ext::ExtensionField; use multilinear_extensions::mle::{FieldType, MultilinearExtension}; -use p3::matrix::dense::RowMajorMatrix; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +use p3::{matrix::dense::RowMajorMatrix, maybe_rayon::prelude::*}; use sumcheck::macros::{entered_span, exit_span}; use transcript::Transcript; diff --git a/crates/whir/src/whir/verifier.rs b/crates/whir/src/whir/verifier.rs index 9c3ce8c..3983843 100644 --- a/crates/whir/src/whir/verifier.rs +++ b/crates/whir/src/whir/verifier.rs @@ -7,8 +7,8 @@ use multilinear_extensions::{mle::MultilinearExtension, virtual_poly::eq_eval}; use p3::{ commit::Mmcs, field::{Field, FieldAlgebra}, + maybe_rayon::prelude::*, }; -use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use std::iter; use sumcheck::macros::{entered_span, exit_span}; From 7083b2051a96a974d471701aafda0de61e82d5b2 Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Sat, 13 Sep 2025 06:23:01 +0530 Subject: [PATCH 3/6] feat: using p3-maybe-rayon for multilinear_extensions crate --- Cargo.lock | 1 + crates/multilinear_extensions/Cargo.toml | 4 ++-- crates/multilinear_extensions/src/expression.rs | 3 +-- crates/multilinear_extensions/src/mle.rs | 12 ++++-------- crates/multilinear_extensions/src/virtual_poly.rs | 6 +----- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5905a06..8116856 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -495,6 +495,7 @@ dependencies = [ "itertools 0.13.0", "log", "p3", + "p3-maybe-rayon", "rand", "rayon", "serde", diff --git a/crates/multilinear_extensions/Cargo.toml b/crates/multilinear_extensions/Cargo.toml index 0b6d409..6d89c3c 100644 --- a/crates/multilinear_extensions/Cargo.toml +++ b/crates/multilinear_extensions/Cargo.toml @@ -14,6 +14,7 @@ either.workspace = true ff_ext.workspace = true itertools.workspace = true p3.workspace = true +p3-maybe-rayon.workspace = true rand.workspace = true rayon.workspace = true serde.workspace = true @@ -26,9 +27,8 @@ log = "0.4" serde_json.workspace = true [features] -default = ["parallel"] nightly-features = ["p3/nightly-features", "ff_ext/nightly-features"] -parallel = [] +parallel = ["p3-maybe-rayon/parallel"] [[bench]] harness = false diff --git a/crates/multilinear_extensions/src/expression.rs b/crates/multilinear_extensions/src/expression.rs index aa958d4..1d8c583 100644 --- a/crates/multilinear_extensions/src/expression.rs +++ b/crates/multilinear_extensions/src/expression.rs @@ -9,8 +9,7 @@ use crate::{ }; use ff_ext::{ExtensionField, SmallField}; use itertools::{Either, Itertools, chain, izip}; -use p3::field::FieldAlgebra; -use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; +use p3::{field::FieldAlgebra, maybe_rayon::prelude::*}; use serde::de::DeserializeOwned; use std::{ cmp::max, diff --git a/crates/multilinear_extensions/src/mle.rs b/crates/multilinear_extensions/src/mle.rs index f4a7c9b..acb9ac4 100644 --- a/crates/multilinear_extensions/src/mle.rs +++ b/crates/multilinear_extensions/src/mle.rs @@ -9,15 +9,11 @@ use crate::{ }; use either::Either; use ff_ext::{ExtensionField, FromUniformBytes}; -use p3::field::{Field, FieldAlgebra}; -use rand::Rng; -use rayon::{ - iter::{ - IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, - IntoParallelRefMutIterator, ParallelIterator, - }, - slice::ParallelSliceMut, +use p3::{ + field::{Field, FieldAlgebra}, + maybe_rayon::prelude::*, }; +use rand::Rng; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use std::fmt::Debug; diff --git a/crates/multilinear_extensions/src/virtual_poly.rs b/crates/multilinear_extensions/src/virtual_poly.rs index e1205e7..e15185c 100644 --- a/crates/multilinear_extensions/src/virtual_poly.rs +++ b/crates/multilinear_extensions/src/virtual_poly.rs @@ -10,12 +10,8 @@ use crate::{ use either::Either; use ff_ext::ExtensionField; use itertools::Itertools; -use p3::field::Field; +use p3::{field::Field, maybe_rayon::prelude::*}; use rand::Rng; -use rayon::{ - iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}, - slice::ParallelSliceMut, -}; use serde::{Deserialize, Serialize, de::DeserializeOwned}; pub type MonomialTermsType<'a, E> = From 561a525ebd504c50a61ee8717e370b7c1b3f5a0b Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Tue, 23 Sep 2025 12:04:03 +0530 Subject: [PATCH 4/6] refactor: removing unnecessary flags and fixing linting issues --- crates/whir/Cargo.toml | 2 +- crates/whir/src/ntt/mod.rs | 3 +-- crates/whir/src/ntt/ntt_impl.rs | 5 ++--- crates/whir/src/ntt/transpose.rs | 2 -- crates/whir/src/ntt/wavelet.rs | 1 - crates/whir/src/sumcheck/prover_batched.rs | 2 -- crates/whir/src/sumcheck/prover_single.rs | 14 ++++++++------ crates/whir/src/whir/batch/committer.rs | 4 +--- crates/whir/src/whir/batch/prover.rs | 4 +--- crates/whir/src/whir/fold.rs | 3 +-- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/whir/Cargo.toml b/crates/whir/Cargo.toml index f270f5d..17550c2 100644 --- a/crates/whir/Cargo.toml +++ b/crates/whir/Cargo.toml @@ -43,6 +43,6 @@ nightly-features = [ "transcript/nightly-features", "witness/nightly-features", ] -parallel = ["p3-maybe-rayon/parallel","dep:rayon"] +parallel = ["p3-maybe-rayon/parallel", "dep:rayon"] print-trace = ["tracing/log"] rayon = ["dep:rayon"] diff --git a/crates/whir/src/ntt/mod.rs b/crates/whir/src/ntt/mod.rs index dd39431..a927223 100644 --- a/crates/whir/src/ntt/mod.rs +++ b/crates/whir/src/ntt/mod.rs @@ -9,12 +9,11 @@ mod wavelet; use self::matrix::MatrixMut; -#[cfg(feature = "parallel")] -use p3::maybe_rayon::prelude::*; use p3::{ dft::{Radix2DitParallel, TwoAdicSubgroupDft}, field::TwoAdicField, matrix::Matrix, + maybe_rayon::prelude::*, }; use tracing::instrument; use witness::{InstancePaddingStrategy, RowMajorMatrix}; diff --git a/crates/whir/src/ntt/ntt_impl.rs b/crates/whir/src/ntt/ntt_impl.rs index 5067628..defc4dd 100644 --- a/crates/whir/src/ntt/ntt_impl.rs +++ b/crates/whir/src/ntt/ntt_impl.rs @@ -14,16 +14,15 @@ use p3::{ Matrix, dense::{DenseMatrix, RowMajorMatrix}, }, + maybe_rayon::prelude::*, }; use std::{ any::{Any, TypeId}, + cmp::max, collections::HashMap, sync::{Arc, LazyLock, Mutex, RwLock, RwLockReadGuard}, }; -#[cfg(feature = "parallel")] -use {rayon::prelude::*, std::cmp::max}; - /// Global cache for NTT engines, indexed by field. // TODO: Skip `LazyLock` when `HashMap::with_hasher` becomes const. // see https://github.com/rust-lang/rust/issues/102575 diff --git a/crates/whir/src/ntt/transpose.rs b/crates/whir/src/ntt/transpose.rs index b27ec83..04bbb0d 100644 --- a/crates/whir/src/ntt/transpose.rs +++ b/crates/whir/src/ntt/transpose.rs @@ -7,8 +7,6 @@ use p3::{ matrix::{Matrix, dense::RowMajorMatrix}, maybe_rayon::prelude::*, }; -#[cfg(feature = "parallel")] -use rayon::join; use sumcheck::macros::{entered_span, exit_span}; // NOTE: The assumption that rows and cols are a power of two are actually only relevant for the square matrix case. diff --git a/crates/whir/src/ntt/wavelet.rs b/crates/whir/src/ntt/wavelet.rs index 96cad52..edbe03f 100644 --- a/crates/whir/src/ntt/wavelet.rs +++ b/crates/whir/src/ntt/wavelet.rs @@ -2,7 +2,6 @@ use super::{transpose, utils::workload_size}; use p3::field::Field; use std::cmp::max; -#[cfg(feature = "parallel")] use p3::maybe_rayon::prelude::*; /// Fast Wavelet Transform. diff --git a/crates/whir/src/sumcheck/prover_batched.rs b/crates/whir/src/sumcheck/prover_batched.rs index 306cc9d..8d27100 100644 --- a/crates/whir/src/sumcheck/prover_batched.rs +++ b/crates/whir/src/sumcheck/prover_batched.rs @@ -2,8 +2,6 @@ use super::proof::SumcheckPolynomial; use crate::sumcheck::prover_single::SumcheckSingle; use ff_ext::ExtensionField; use p3::{field::Field, maybe_rayon::prelude::*, util::log2_strict_usize}; -#[cfg(feature = "parallel")] -use rayon::join; pub struct SumcheckBatched { // The evaluation on each p and eq diff --git a/crates/whir/src/sumcheck/prover_single.rs b/crates/whir/src/sumcheck/prover_single.rs index 6de13a0..684c4f4 100644 --- a/crates/whir/src/sumcheck/prover_single.rs +++ b/crates/whir/src/sumcheck/prover_single.rs @@ -1,9 +1,9 @@ use super::proof::SumcheckPolynomial; use ff_ext::ExtensionField; -use p3::{maybe_rayon::prelude::*, util::log2_strict_usize}; #[cfg(feature = "parallel")] -use rayon::join; +use p3::maybe_rayon::prelude::join; +use p3::{maybe_rayon::prelude::*, util::log2_strict_usize}; pub struct SumcheckSingle { // The evaluation of p @@ -261,10 +261,12 @@ mod tests { let eval = MultilinearExtension::from_evaluations_ext_vec(2, polynomial.clone()) .evaluate(&eval_point); - let mut prover = - SumcheckSingle::new(polynomial, &[eval_point], &[E::from_canonical_u64(1)], &[ - eval, - ]); + let mut prover = SumcheckSingle::new( + polynomial, + &[eval_point], + &[E::from_canonical_u64(1)], + &[eval], + ); let poly_1 = prover.compute_sumcheck_polynomial(); diff --git a/crates/whir/src/whir/batch/committer.rs b/crates/whir/src/whir/batch/committer.rs index 3a074a4..233d462 100644 --- a/crates/whir/src/whir/batch/committer.rs +++ b/crates/whir/src/whir/batch/committer.rs @@ -13,14 +13,12 @@ use derive_more::Debug; use ff_ext::ExtensionField; use p3::{ matrix::{Matrix, dense::RowMajorMatrix}, + maybe_rayon::prelude::*, util::log2_strict_usize, }; use sumcheck::macros::{entered_span, exit_span}; use transcript::{BasicTranscript, Transcript}; -#[cfg(feature = "parallel")] -use p3::maybe_rayon::prelude::*; - #[derive(Debug)] pub struct Witnesses { pub(crate) polys: Vec>, diff --git a/crates/whir/src/whir/batch/prover.rs b/crates/whir/src/whir/batch/prover.rs index 5aed563..c4d3362 100644 --- a/crates/whir/src/whir/batch/prover.rs +++ b/crates/whir/src/whir/batch/prover.rs @@ -21,13 +21,11 @@ use crate::{ use ff_ext::{ExtensionField, PoseidonField}; use itertools::zip_eq; use multilinear_extensions::mle::{FieldType, MultilinearExtension}; -use p3::{commit::Mmcs, matrix::dense::RowMajorMatrix}; +use p3::{commit::Mmcs, matrix::dense::RowMajorMatrix, maybe_rayon::prelude::*}; use sumcheck::macros::{entered_span, exit_span}; use transcript::Transcript; use crate::whir::fs_utils::get_challenge_stir_queries; -#[cfg(feature = "parallel")] -use p3::maybe_rayon::prelude::*; struct RoundStateBatch<'a, E: ExtensionField> { round_state: RoundState<'a, E>, diff --git a/crates/whir/src/whir/fold.rs b/crates/whir/src/whir/fold.rs index 293f607..a2e13bc 100644 --- a/crates/whir/src/whir/fold.rs +++ b/crates/whir/src/whir/fold.rs @@ -3,11 +3,10 @@ use crate::{ parameters::FoldType, }; -#[cfg(feature = "parallel")] -use p3::maybe_rayon::prelude::*; use p3::{ field::{Field, TwoAdicField}, matrix::Matrix, + maybe_rayon::prelude::*, }; /// Given the evaluation of f on the coset specified by coset_offset * From a2b035fb458663fe49039399c9f9e276380837c6 Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Tue, 23 Sep 2025 12:05:12 +0530 Subject: [PATCH 5/6] refactor: remaining fixes in mpcs and whir crates --- crates/mpcs/Cargo.toml | 2 +- crates/mpcs/src/util.rs | 2 +- crates/whir/src/sumcheck/prover_single.rs | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/mpcs/Cargo.toml b/crates/mpcs/Cargo.toml index a84ec4b..671c185 100644 --- a/crates/mpcs/Cargo.toml +++ b/crates/mpcs/Cargo.toml @@ -42,7 +42,7 @@ nightly-features = [ "whir/nightly-features", "witness/nightly-features", ] -parallel = ["p3-maybe-rayon/parallel","dep:rayon"] +parallel = ["p3-maybe-rayon/parallel", "dep:rayon"] print-trace = ["whir/print-trace"] sanity-check = [] diff --git a/crates/mpcs/src/util.rs b/crates/mpcs/src/util.rs index 24a3495..587df7b 100644 --- a/crates/mpcs/src/util.rs +++ b/crates/mpcs/src/util.rs @@ -101,7 +101,7 @@ pub(crate) fn codeword_fold_with_challenge( lo + challenge * (hi - lo) } -#[cfg(any(test))] +#[cfg(test)] pub mod test { use ff_ext::FromUniformBytes; use rand::{ diff --git a/crates/whir/src/sumcheck/prover_single.rs b/crates/whir/src/sumcheck/prover_single.rs index 684c4f4..e2f69a4 100644 --- a/crates/whir/src/sumcheck/prover_single.rs +++ b/crates/whir/src/sumcheck/prover_single.rs @@ -1,8 +1,6 @@ use super::proof::SumcheckPolynomial; use ff_ext::ExtensionField; -#[cfg(feature = "parallel")] -use p3::maybe_rayon::prelude::join; use p3::{maybe_rayon::prelude::*, util::log2_strict_usize}; pub struct SumcheckSingle { From 981729345a132970a6f4a04f617eb2f7384ca3f3 Mon Sep 17 00:00:00 2001 From: Sahilgill24 Date: Sun, 12 Oct 2025 00:21:05 +0530 Subject: [PATCH 6/6] feat: changes in crate dependencies --- Cargo.lock | 3 --- Makefile.toml | 11 +++++++- crates/curves/Cargo.toml | 6 ++--- crates/mpcs/Cargo.toml | 16 +++--------- crates/mpcs/src/lib.rs | 3 +++ crates/multilinear_extensions/Cargo.toml | 5 ++-- crates/multilinear_extensions/src/mle.rs | 20 ++++++-------- crates/p3/Cargo.toml | 1 - crates/poseidon/Cargo.toml | 2 +- crates/sumcheck/Cargo.toml | 18 +++++-------- crates/sumcheck/src/prover.rs | 33 ++++++++++++------------ crates/sumcheck_macro/Cargo.toml | 4 +-- crates/sumcheck_macro/src/lib.rs | 2 +- crates/transcript/Cargo.toml | 6 +---- crates/whir/Cargo.toml | 22 +++++----------- crates/witness/Cargo.toml | 8 ++---- crates/witness/src/lib.rs | 5 +++- 17 files changed, 70 insertions(+), 95 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e96f48..c6e60e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -816,7 +816,6 @@ dependencies = [ "multilinear_extensions", "num-integer", "p3", - "p3-maybe-rayon", "rand", "rand_chacha", "rayon", @@ -840,7 +839,6 @@ dependencies = [ "itertools 0.13.0", "log", "p3", - "p3-maybe-rayon", "rand", "rayon", "serde", @@ -2031,7 +2029,6 @@ dependencies = [ "itertools 0.14.0", "multilinear_extensions", "p3", - "p3-maybe-rayon", "rand", "rand_chacha", "rayon", diff --git a/Makefile.toml b/Makefile.toml index ce579bb..ebbc95c 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -4,6 +4,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true [tasks.tests] args = [ "test", + "--all-features", # Run everything but 'benches'. "--lib", "--bins", @@ -16,6 +17,14 @@ env = { RUST_MIN_STACK = "33554432" } workspace = false [tasks.clippy] -args = ["clippy", "--workspace", "--all-targets", "--", "-D", "warnings"] +args = [ + "clippy", + "--workspace", + "--all-targets", + "--all-features", + "--", + "-D", + "warnings", +] command = "cargo" workspace = false diff --git a/crates/curves/Cargo.toml b/crates/curves/Cargo.toml index c51daaf..67bd2e1 100644 --- a/crates/curves/Cargo.toml +++ b/crates/curves/Cargo.toml @@ -24,9 +24,9 @@ serde = { workspace = true, features = ["derive"] } typenum = "1.17.0" cfg-if.workspace = true -ff_ext = { version = "0.1.0", path = "../ff_ext" } -itertools = { workspace = true } -multilinear_extensions = { version = "0.1.0", path = "../multilinear_extensions" } +ff_ext.workspace = true +itertools.workspace = true +multilinear_extensions.workspace = true rug = { version = "1.26.1", optional = true } [dev-dependencies] diff --git a/crates/mpcs/Cargo.toml b/crates/mpcs/Cargo.toml index 671c185..4ae4972 100644 --- a/crates/mpcs/Cargo.toml +++ b/crates/mpcs/Cargo.toml @@ -14,11 +14,10 @@ bincode = "1.3.3" clap.workspace = true ff_ext.workspace = true itertools.workspace = true -whir.workspace = true +whir = { workspace = true, optional = true } multilinear_extensions.workspace = true num-integer = "0.1" p3.workspace = true -p3-maybe-rayon.workspace = true rand.workspace = true rand_chacha.workspace = true rayon = { workspace = true, optional = true } @@ -33,16 +32,9 @@ witness.workspace = true criterion.workspace = true [features] -nightly-features = [ - "p3/nightly-features", - "ff_ext/nightly-features", - "multilinear_extensions/nightly-features", - "sumcheck/nightly-features", - "transcript/nightly-features", - "whir/nightly-features", - "witness/nightly-features", -] -parallel = ["p3-maybe-rayon/parallel", "dep:rayon"] +nightly-features = ["ff_ext/nightly-features"] +parallel = ["p3/parallel", "dep:rayon"] +whir = ["dep:whir"] print-trace = ["whir/print-trace"] sanity-check = [] diff --git a/crates/mpcs/src/lib.rs b/crates/mpcs/src/lib.rs index aa08767..0959d75 100644 --- a/crates/mpcs/src/lib.rs +++ b/crates/mpcs/src/lib.rs @@ -258,6 +258,7 @@ pub enum Error { PolynomialSizesNotEqual, MerkleRootMismatch, PointEvalMismatch(String), + #[cfg(feature = "whir")] WhirError(whir_external::error::Error), } @@ -266,9 +267,11 @@ pub use basefold::{ Basefold, BasefoldCommitment, BasefoldCommitmentWithWitness, BasefoldDefault, BasefoldParams, BasefoldRSParams, BasefoldSpec, EncodingScheme, RSCode, RSCodeDefaultSpec, }; +#[cfg(feature = "whir")] extern crate whir as whir_external; mod whir; use multilinear_extensions::mle::ArcMultilinearExtension; +#[cfg(feature = "whir")] pub use whir::{Whir, WhirDefault, WhirDefaultSpec}; // TODO: Need to use some functions here in the integration benchmarks. But diff --git a/crates/multilinear_extensions/Cargo.toml b/crates/multilinear_extensions/Cargo.toml index 6d89c3c..c4f8ea2 100644 --- a/crates/multilinear_extensions/Cargo.toml +++ b/crates/multilinear_extensions/Cargo.toml @@ -14,7 +14,6 @@ either.workspace = true ff_ext.workspace = true itertools.workspace = true p3.workspace = true -p3-maybe-rayon.workspace = true rand.workspace = true rayon.workspace = true serde.workspace = true @@ -27,8 +26,8 @@ log = "0.4" serde_json.workspace = true [features] -nightly-features = ["p3/nightly-features", "ff_ext/nightly-features"] -parallel = ["p3-maybe-rayon/parallel"] +nightly-features = ["ff_ext/nightly-features"] +parallel = ["p3/parallel"] [[bench]] harness = false diff --git a/crates/multilinear_extensions/src/mle.rs b/crates/multilinear_extensions/src/mle.rs index 6d4b470..f1370da 100644 --- a/crates/multilinear_extensions/src/mle.rs +++ b/crates/multilinear_extensions/src/mle.rs @@ -9,6 +9,8 @@ use crate::{ }; use either::Either; use ff_ext::{ExtensionField, FromUniformBytes}; +#[cfg(not(feature = "parallel"))] +use itertools::Itertools; use p3::{ field::{Field, FieldAlgebra}, maybe_rayon::prelude::*, @@ -608,10 +610,8 @@ impl<'a, E: ExtensionField> MultilinearExtension<'a, E> { Cow::Owned(MultilinearExtension::from_evaluations_ext_vec( self.num_vars() - 1, evaluations - .par_iter() - .chunks(2) - .with_min_len(64) - .map(|buf| *point * (*buf[1] - *buf[0]) + *buf[0]) + .par_chunks(2) + .map(|buf| *point * (buf[1] - buf[0]) + buf[0]) .collect(), )) }); @@ -641,10 +641,8 @@ impl<'a, E: ExtensionField> MultilinearExtension<'a, E> { match &mut self.evaluations { FieldType::Base(slice) => { let slice_ext = slice - .par_iter() - .chunks(2) - .with_min_len(64) - .map(|buf| *point * (*buf[1] - *buf[0]) + *buf[0]) + .par_chunks(2) + .map(|buf| *point * (buf[1] - buf[0]) + buf[0]) .collect(); let _ = mem::replace( &mut self.evaluations, @@ -654,10 +652,8 @@ impl<'a, E: ExtensionField> MultilinearExtension<'a, E> { FieldType::Ext(slice) => { let slice_mut = slice.to_mut(); slice_mut - .par_iter_mut() - .chunks(2) - .with_min_len(64) - .for_each(|mut buf| *buf[0] = *buf[0] + (*buf[1] - *buf[0]) * *point); + .par_chunks_mut(2) + .for_each(|buf| buf[0] = buf[0] + (buf[1] - buf[0]) * *point); // sequentially update buf[b1, b2,..bt] = buf[b1, b2,..bt, 0] for index in 0..1 << (max_log2_size - 1) { diff --git a/crates/p3/Cargo.toml b/crates/p3/Cargo.toml index cd16d15..6154570 100644 --- a/crates/p3/Cargo.toml +++ b/crates/p3/Cargo.toml @@ -27,7 +27,6 @@ p3-symmetric.workspace = true p3-util.workspace = true [features] -default = ["parallel"] nightly-features = [ "p3-baby-bear/nightly-features", "p3-dft/nightly-features", diff --git a/crates/poseidon/Cargo.toml b/crates/poseidon/Cargo.toml index e9e8f90..ed49c18 100644 --- a/crates/poseidon/Cargo.toml +++ b/crates/poseidon/Cargo.toml @@ -18,4 +18,4 @@ serde.workspace = true rand.workspace = true [features] -nightly-features = ["p3/nightly-features", "ff_ext/nightly-features"] +nightly-features = ["ff_ext/nightly-features"] diff --git a/crates/sumcheck/Cargo.toml b/crates/sumcheck/Cargo.toml index c0f56b7..2a0cfc6 100644 --- a/crates/sumcheck/Cargo.toml +++ b/crates/sumcheck/Cargo.toml @@ -13,16 +13,14 @@ version.workspace = true either.workspace = true ff_ext.workspace = true itertools.workspace = true -multilinear_extensions = { path = "../multilinear_extensions", features = [ - "parallel", -] } +multilinear_extensions.workspace = true p3.workspace = true rayon.workspace = true serde.workspace = true -sumcheck_macro = { path = "../sumcheck_macro" } +sumcheck_macro.workspace = true thiserror.workspace = true tracing.workspace = true -transcript = { path = "../transcript" } +transcript.workspace = true [dev-dependencies] criterion.workspace = true @@ -31,13 +29,9 @@ poseidon.workspace = true rand.workspace = true [features] -nightly-features = [ - "p3/nightly-features", - "ff_ext/nightly-features", - "multilinear_extensions/nightly-features", - "sumcheck_macro/nightly-features", - "transcript/nightly-features", -] +nightly-features = ["ff_ext/nightly-features"] +parallel = ["p3/parallel", "multilinear_extensions/parallel"] + [[bench]] harness = false diff --git a/crates/sumcheck/src/prover.rs b/crates/sumcheck/src/prover.rs index 9778005..ec8982f 100644 --- a/crates/sumcheck/src/prover.rs +++ b/crates/sumcheck/src/prover.rs @@ -10,10 +10,7 @@ use multilinear_extensions::{ virtual_poly::{MonomialTerms, VirtualPolynomial}, virtual_polys::{PolyMeta, VirtualPolynomials}, }; -use rayon::{ - iter::{IndexedParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator}, - prelude::{IntoParallelIterator, ParallelIterator}, -}; +use p3::maybe_rayon::prelude::*; use sumcheck_macro::sumcheck_code_gen; use transcript::{Challenge, Transcript}; @@ -41,12 +38,14 @@ impl<'a, E: ExtensionField> Phase1Workers<'a, E> { ) -> (Vec>, Vec>) { let mut prover_msgs = Vec::with_capacity(num_variables); for _ in 0..num_variables { - let evaluations = self - .workers_states - .par_iter_mut() - .map(|state| state.run_round()) - .reduce(|| AdditiveVec::new(max_degree + 1), |a, b| a + b); - + let evaluations: AdditiveVec = self.workers_states.par_iter_mut().par_fold_reduce( + || AdditiveVec::new(max_degree + 1), + |mut acc, state| { + acc += state.run_round(); + acc + }, + |a, b| a + b, + ); transcript.append_field_element_exts(&evaluations.0); let challenge = transcript.sample_and_append_challenge(b"Internal round"); @@ -166,8 +165,8 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { max_thread_id, num_variables, poly_meta, - polys, max_degree, + polys, transcript, ); exit_span!(span); @@ -234,8 +233,8 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { max_thread_id: usize, num_variables: usize, poly_meta: Vec, - mut polys: Vec>, max_degree: usize, + mut polys: Vec>, transcript: &mut impl Transcript, ) -> (Vec>, Vec>) { let log2_max_thread_id = ceil_log2(max_thread_id); // do not support SIZE not power of 2 @@ -599,8 +598,8 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { .poly .products .par_iter() - .fold_with( - AdditiveVec::new(self.poly.aux_info.max_degree + 1), + .par_fold_reduce( + || AdditiveVec::new(self.poly.aux_info.max_degree + 1), |mut uni_polys, MonomialTerms { terms }| { for Term { scalar, @@ -642,9 +641,9 @@ impl<'a, E: ExtensionField> IOPProverState<'a, E> { } uni_polys }, - ) - .reduce_with(|acc, item| acc + item) - .unwrap(); + |acc, item| acc + item, + ); + exit_span!(span); exit_span!(start); diff --git a/crates/sumcheck_macro/Cargo.toml b/crates/sumcheck_macro/Cargo.toml index 177ceda..1da511a 100644 --- a/crates/sumcheck_macro/Cargo.toml +++ b/crates/sumcheck_macro/Cargo.toml @@ -21,9 +21,9 @@ rand.workspace = true syn = { version = "2.0", features = ["full"] } [features] -nightly-features = ["p3/nightly-features"] +nightly-features = ["ff_ext/nightly-features"] [dev-dependencies] ff_ext.workspace = true -multilinear_extensions = { path = "../multilinear_extensions" } +multilinear_extensions.workspace = true sumcheck.workspace = true diff --git a/crates/sumcheck_macro/src/lib.rs b/crates/sumcheck_macro/src/lib.rs index 5d2a2f6..e3e66d1 100644 --- a/crates/sumcheck_macro/src/lib.rs +++ b/crates/sumcheck_macro/src/lib.rs @@ -237,7 +237,7 @@ pub fn sumcheck_code_gen(input: proc_macro::TokenStream) -> proc_macro::TokenStr }; let iter = if parallalize { - quote! {.into_par_iter().step_by(2).rev().with_min_len(64)} + quote! {.into_par_iter().step_by(2).rev()} } else { quote! {.step_by(2).rev()} }; diff --git a/crates/transcript/Cargo.toml b/crates/transcript/Cargo.toml index ad8efe9..48b31f7 100644 --- a/crates/transcript/Cargo.toml +++ b/crates/transcript/Cargo.toml @@ -16,8 +16,4 @@ p3.workspace = true poseidon.workspace = true [features] -nightly-features = [ - "p3/nightly-features", - "ff_ext/nightly-features", - "poseidon/nightly-features", -] +nightly-features = ["ff_ext/nightly-features"] diff --git a/crates/whir/Cargo.toml b/crates/whir/Cargo.toml index 17550c2..d928c40 100644 --- a/crates/whir/Cargo.toml +++ b/crates/whir/Cargo.toml @@ -15,19 +15,18 @@ default-run = "main" [dependencies] bincode = "1.3.3" clap.workspace = true -ff_ext = { path = "../ff_ext" } -multilinear_extensions = { path = "../multilinear_extensions" } +ff_ext.workspace = true +multilinear_extensions.workspace = true p3.workspace = true -p3-maybe-rayon.workspace = true rand = "0.8" rand_chacha = "0.3" rayon = { workspace = true, optional = true } serde = { version = "1.0", features = ["derive"] } -sumcheck = { path = "../sumcheck" } +sumcheck.workspace = true tracing.workspace = true -transcript = { path = "../transcript" } +transcript.workspace = true transpose = "0.2.3" -witness = { path = "../witness" } +witness.workspace = true derive_more = { version = "1.0.0", features = ["debug"] } itertools = "0.14.0" @@ -35,14 +34,7 @@ itertools = "0.14.0" [features] asm = [] default = ["parallel"] -nightly-features = [ - "p3/nightly-features", - "ff_ext/nightly-features", - "multilinear_extensions/nightly-features", - "sumcheck/nightly-features", - "transcript/nightly-features", - "witness/nightly-features", -] -parallel = ["p3-maybe-rayon/parallel", "dep:rayon"] +nightly-features = ["ff_ext/nightly-features"] +parallel = ["sumcheck/parallel", "dep:rayon"] print-trace = ["tracing/log"] rayon = ["dep:rayon"] diff --git a/crates/witness/Cargo.toml b/crates/witness/Cargo.toml index 6fa5f68..8c2e725 100644 --- a/crates/witness/Cargo.toml +++ b/crates/witness/Cargo.toml @@ -11,15 +11,11 @@ version.workspace = true [dependencies] ff_ext.workspace = true -multilinear_extensions = { version = "0", path = "../multilinear_extensions" } +multilinear_extensions.workspace = true p3.workspace = true rand.workspace = true rayon.workspace = true tracing.workspace = true [features] -nightly-features = [ - "p3/nightly-features", - "ff_ext/nightly-features", - "multilinear_extensions/nightly-features", -] +nightly-features = ["ff_ext/nightly-features"] diff --git a/crates/witness/src/lib.rs b/crates/witness/src/lib.rs index 0cf13bb..f7d6471 100644 --- a/crates/witness/src/lib.rs +++ b/crates/witness/src/lib.rs @@ -2,9 +2,12 @@ use multilinear_extensions::mle::{IntoMLE, MultilinearExtension}; use p3::{ field::{Field, FieldAlgebra}, matrix::Matrix, - maybe_rayon::prelude::*, }; use rand::{Rng, distributions::Standard, prelude::Distribution}; +use rayon::{ + iter::{IndexedParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator}, + prelude::ParallelSliceMut, +}; use std::{ ops::{Deref, DerefMut, Index}, slice::{Chunks, ChunksMut},