From a760e436ed2ee92d29969dae2349d142e23f6533 Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Fri, 14 Jun 2024 15:04:09 +0200 Subject: [PATCH] Fix parallel feature tagging --- nomos-da/kzgrs/benches/kzg.rs | 4 ++++ nomos-da/kzgrs/src/fft.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/nomos-da/kzgrs/benches/kzg.rs b/nomos-da/kzgrs/benches/kzg.rs index 18c26eb6..e7cbbcee 100644 --- a/nomos-da/kzgrs/benches/kzg.rs +++ b/nomos-da/kzgrs/benches/kzg.rs @@ -6,7 +6,9 @@ use divan::counter::ItemsCount; use divan::{black_box, counter::BytesCount, AllocProfiler, Bencher}; use once_cell::sync::Lazy; use rand::RngCore; +#[cfg(feature = "parallel")] use rayon::iter::IntoParallelIterator; +#[cfg(feature = "parallel")] use rayon::iter::ParallelIterator; use kzgrs::{common::bytes_to_polynomial_unchecked, kzg::*}; @@ -46,6 +48,7 @@ fn commit_single_polynomial_with_element_count(bencher: Bencher, element_count: .bench_refs(|(_evals, poly)| black_box(commit_polynomial(poly, &GLOBAL_PARAMETERS))); } +#[cfg(feature = "parallel")] #[allow(non_snake_case)] #[divan::bench(args = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096])] fn commit_polynomial_with_element_count_parallelized(bencher: Bencher, element_count: usize) { @@ -114,6 +117,7 @@ fn compute_batch_proofs(bencher: Bencher, element_count: usize) { // This is a test on how will perform by having a wrapping rayon on top of the proof computation // ark libraries already use rayon underneath so no great improvements are probably come up from this. // But it should help reusing the same thread pool for all jobs saving a little time. +#[cfg(feature = "parallel")] #[allow(non_snake_case)] #[divan::bench(args = [128, 256, 512, 1024], sample_count = 3, sample_size = 5)] fn compute_parallelize_batch_proofs(bencher: Bencher, element_count: usize) { diff --git a/nomos-da/kzgrs/src/fft.rs b/nomos-da/kzgrs/src/fft.rs index 84a410ac..66edf55b 100644 --- a/nomos-da/kzgrs/src/fft.rs +++ b/nomos-da/kzgrs/src/fft.rs @@ -2,7 +2,7 @@ use ark_bls12_381::{Bls12_381, Fr, G1Affine}; use ark_ec::pairing::Pairing; use ark_ec::{AffineRepr, CurveGroup}; use ark_ff::{BigInt, BigInteger, FftField, Field, PrimeField}; -#[cfg(parallel)] +#[cfg(feature = "parallel")] use rayon::iter::IntoParallelIterator; pub fn fft_g1(vals: &[G1Affine], roots_of_unity: &[Fr]) -> Vec { @@ -36,22 +36,22 @@ pub fn fft_g1(vals: &[G1Affine], roots_of_unity: &[Fr]) -> Vec { }; let [l, r]: [Vec; 2] = { - #[cfg(parallel)] + #[cfg(feature = "parallel")] { [l, r].into_par_iter().map(|f| f()).collect() } - #[cfg(not(parallel))] + #[cfg(not(feature = "parallel"))] { [l(), r()] } }; let y_times_root = { - #[cfg(parallel)] + #[cfg(feature = "parallel")] { r.into_par_iter() } - #[cfg(not(parallel))] + #[cfg(not(feature = "parallel"))] { r.into_iter() } @@ -61,11 +61,11 @@ pub fn fft_g1(vals: &[G1Affine], roots_of_unity: &[Fr]) -> Vec { .map(|(i, y)| (y * roots_of_unity[i % vals.len()]).into_affine()); { - #[cfg(parallel)] + #[cfg(feature = "parallel")] { l.into_par_iter() } - #[cfg(not(parallel))] + #[cfg(not(feature = "parallel"))] { l.into_iter() } @@ -90,11 +90,11 @@ pub fn ifft_g1(vals: &[G1Affine], roots_of_unity: &[Fr]) -> Vec { let mut mod_min_2 = BigInt::new(::MODULUS.0); mod_min_2.sub_with_borrow(&BigInt::<4>::from(2u64)); let invlen = Fr::from(vals.len() as u64).pow(mod_min_2).into_bigint(); - #[cfg(parallel)] + #[cfg(feature = "parallel")] { - fft_g1(vals, roots_of_unity).into_par_iter() + fft_g1(vals, roots_of_unity).into_par_iter().collect() } - #[cfg(not(parallel))] + #[cfg(not(feature = "parallel"))] { fft_g1(vals, roots_of_unity).into_iter() } .map(|g| g.mul_bigint(invlen).into_affine()) .collect()