From 325c29dc7204f95242c598feec9c382ddc15ebe7 Mon Sep 17 00:00:00 2001 From: Hanting Zhang Date: Fri, 9 Feb 2024 02:00:56 +0000 Subject: [PATCH] bechmarks --- benches/grumpkin_msm.rs | 15 ++++++++++++--- examples/grumpkin_msm.rs | 2 +- src/lib.rs | 4 ++++ src/pasta.rs | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/benches/grumpkin_msm.rs b/benches/grumpkin_msm.rs index 993d5e4..72c6d12 100644 --- a/benches/grumpkin_msm.rs +++ b/benches/grumpkin_msm.rs @@ -65,15 +65,24 @@ fn criterion_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("GPU"); group.sample_size(20); + let indices = (0..(npoints as u32)).rev().collect::>(); + group.bench_function(format!("2**{} points", bench_npow), |b| { b.iter(|| { let _ = grumpkin_msm::bn256::msm_aux(&points, &scalars, None); }) }); + scalars.reverse(); + group.bench_function(format!("2**{} points rev", bench_npow), |b| { + b.iter(|| { + let _ = grumpkin_msm::bn256::msm_aux(&points, &scalars, Some(indices.as_slice())); + }) + }); + let context = grumpkin_msm::bn256::init(&points); - let indices = (0..(npoints as u32)).rev().collect::>(); + scalars.reverse(); group.bench_function( format!("preallocate 2**{} points", bench_npow), |b| { @@ -81,7 +90,7 @@ fn criterion_benchmark(c: &mut Criterion) { let _ = grumpkin_msm::bn256::with_context_aux( &context, &scalars, - Some(indices.as_slice()), + None, ); }) }, @@ -93,7 +102,7 @@ fn criterion_benchmark(c: &mut Criterion) { |b| { b.iter(|| { let _ = grumpkin_msm::bn256::with_context_aux( - &context, &scalars, None, + &context, &scalars, Some(indices.as_slice()), ); }) }, diff --git a/examples/grumpkin_msm.rs b/examples/grumpkin_msm.rs index 208183f..1ab89c5 100644 --- a/examples/grumpkin_msm.rs +++ b/examples/grumpkin_msm.rs @@ -6,7 +6,7 @@ use grumpkin_msm::cuda_available; fn main() { let bench_npow: usize = std::env::var("BENCH_NPOW") - .unwrap_or("22".to_string()) + .unwrap_or("23".to_string()) .parse() .unwrap(); let npoints: usize = 1 << bench_npow; diff --git a/src/lib.rs b/src/lib.rs index 2582d55..e7b7a24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,6 +214,10 @@ macro_rules! impl_msm { /// An indexed MSM. We do not check if the indices are valid, i.e. /// for i in 0..nscalars, 0 <= indices[i] < npoints + /// + /// Also, this version carries a performance penalty that all the + /// points must be moved onto the GPU once instead of in batches. + /// If the points are to be reused, please use the [`MSMContext`] API pub fn indexed_msm( points: &[$affine], scalars: &[$scalar], diff --git a/src/pasta.rs b/src/pasta.rs index 007b9de..be8682d 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -232,6 +232,10 @@ macro_rules! impl_pasta { /// An indexed MSM. We do not check if the indices are valid, i.e. /// for i in 0..nscalars, 0 <= indices[i] < npoints + /// + /// Also, this version carries a performance penalty that all the + /// points must be moved onto the GPU once instead of in batches. + /// If the points are to be reused, please use the [`MSMContext`] API pub fn indexed_msm( points: &[$affine], scalars: &[$scalar],