-
Notifications
You must be signed in to change notification settings - Fork 577
Optimize Msm #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Optimize Msm #796
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af1713f
arithmetic::best_multiexp add benchmark
ashWhiteHat e00f0d1
arithmetic::best_multiexp parallelize bucket arithmetic
ashWhiteHat 24e3ec3
arithmetic::best_multiexp refactor buckets
ashWhiteHat 27fddaf
Add test for `best_multiexp`
str4d 7de8af3
halo2_proofs: Add helper to resolve `Iterator::reduce` mismatch
str4d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #[macro_use] | ||
| extern crate criterion; | ||
|
|
||
| use crate::arithmetic::best_multiexp; | ||
| use crate::pasta::{EqAffine, Fp}; | ||
| use crate::poly::commitment::Params; | ||
| use criterion::{BenchmarkId, Criterion}; | ||
| use group::ff::Field; | ||
| use halo2_proofs::*; | ||
| use rand_core::OsRng; | ||
|
|
||
| fn criterion_benchmark(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("msm"); | ||
| for k in 8..16 { | ||
| group | ||
| .bench_function(BenchmarkId::new("k", k), |b| { | ||
| let coeffs = (0..(1 << k)).map(|_| Fp::random(OsRng)).collect::<Vec<_>>(); | ||
| let bases = Params::<EqAffine>::new(k).get_g(); | ||
|
|
||
| b.iter(|| best_multiexp(&coeffs, &bases)) | ||
| }) | ||
| .sample_size(30); | ||
| } | ||
| } | ||
|
|
||
| criterion_group!(benches, criterion_benchmark); | ||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,3 +71,46 @@ where | |
| self.try_fold(identity(), fold_op) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) trait TheBestReduce { | ||
| type Item; | ||
|
|
||
| /// Combines the best of `std::iter` and `rayon` reductions. | ||
| fn the_best_reduce( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙃 at the name, but this is fine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed something that was not likely to clash in future with a |
||
| self, | ||
| identity: impl Fn() -> Self::Item + Send + Sync, | ||
| op: impl Fn(Self::Item, Self::Item) -> Self::Item + Send + Sync, | ||
| ) -> Option<Self::Item>; | ||
| } | ||
|
|
||
| #[cfg(feature = "multicore")] | ||
| impl<I> TheBestReduce for I | ||
| where | ||
| I: maybe_rayon::iter::ParallelIterator, | ||
| { | ||
| type Item = <Self as maybe_rayon::iter::ParallelIterator>::Item; | ||
|
|
||
| fn the_best_reduce( | ||
| self, | ||
| identity: impl Fn() -> Self::Item + Send + Sync, | ||
| op: impl Fn(Self::Item, Self::Item) -> Self::Item + Send + Sync, | ||
| ) -> Option<Self::Item> { | ||
| Some(self.reduce(identity, op)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "multicore"))] | ||
| impl<I> TheBestReduce for I | ||
| where | ||
| I: std::iter::Iterator, | ||
| { | ||
| type Item = <Self as std::iter::Iterator>::Item; | ||
|
|
||
| fn the_best_reduce( | ||
| self, | ||
| _: impl Fn() -> Self::Item + Send + Sync, | ||
| f: impl Fn(Self::Item, Self::Item) -> Self::Item + Send + Sync, | ||
| ) -> Option<Self::Item> { | ||
| self.reduce(f) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bucket::addwas an existing function that is preserved in this PR, so in the interest of not needing to go through another round of CI, I'm going to defer this internal rename.