-
Notifications
You must be signed in to change notification settings - Fork 31
Fast Coset Extrapolate #212
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1c596b0
bench: Add benchmark target
aszepieniec 5be2c43
support: Add ZerofierTree
aszepieniec 881d441
refactor: Separate parallel from sequential `zerofier` methods
aszepieniec 4d8d792
feat: Use zerofier tree in batch evaluate
aszepieniec 4d86736
fix: Fix `structured_multiple_of_degree`
aszepieniec 3e978b6
refactor: Drop fast_divide
aszepieniec 2c49134
feat: Fast modular interpolate and extrapolate on coset
aszepieniec 3b90994
bench: Benchmark coset extrapolate
aszepieniec 510c4e7
perf: Speed up with precomputation
aszepieniec 4c0ccd5
bench: Update extrapolation benchmark
aszepieniec 9e7585d
feat: Batch and parallel versions of coset extrapolate
aszepieniec 6abebca
bench: Update benchmark
aszepieniec ba014ce
style: Happify clippy
aszepieniec f7ad230
refactor: Integrate reviewer feedback
aszepieniec de87941
refactor(ZerofierTree): improve interface and mechanics
aszepieniec 5a3a353
refactor: Encapsulate preprocessing data into new struct
aszepieniec d8e6068
refactor: Integrate reviewer feedback
aszepieniec 0a71c3e
ci: Work around `nextest` bug
jan-ferdinand 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
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,37 @@ | ||
| use criterion::criterion_group; | ||
| use criterion::criterion_main; | ||
| use criterion::BenchmarkId; | ||
| use criterion::Criterion; | ||
|
|
||
| use twenty_first::math::other::random_elements; | ||
| use twenty_first::prelude::*; | ||
|
|
||
| criterion_main!(benches); | ||
| criterion_group!( | ||
| name = benches; | ||
| config = Criterion::default().sample_size(10); | ||
| targets = coset_extrapolation<{ 1 << 18 }, { 1 << 8 }>, | ||
| coset_extrapolation<{ 1 << 19 }, { 1 << 8 }>, | ||
| coset_extrapolation<{ 1 << 20 }, { 1 << 8 }>, | ||
| coset_extrapolation<{ 1 << 21 }, { 1 << 8 }>, | ||
| coset_extrapolation<{ 1 << 22 }, { 1 << 8 }>, | ||
| coset_extrapolation<{ 1 << 23 }, { 1 << 8 }>, | ||
| ); | ||
|
|
||
| fn coset_extrapolation<const SIZE: usize, const NUM_POINTS: usize>(c: &mut Criterion) { | ||
| let log2_of_size = SIZE.ilog2(); | ||
| let mut group = c.benchmark_group(format!( | ||
| "Fast extrapolation of length-{SIZE} codeword in {NUM_POINTS} Points" | ||
| )); | ||
|
|
||
| let codeword = random_elements(SIZE); | ||
| let offset = BFieldElement::new(7); | ||
| let eval_points: Vec<BFieldElement> = random_elements(NUM_POINTS); | ||
|
|
||
| let id = BenchmarkId::new("Fast Codeword Extrapolation", log2_of_size); | ||
| group.bench_function(id, |b| { | ||
| b.iter(|| Polynomial::<BFieldElement>::coset_extrapolate(offset, &codeword, &eval_points)) | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } |
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,95 @@ | ||
| use criterion::criterion_group; | ||
| use criterion::criterion_main; | ||
| use criterion::BenchmarkId; | ||
| use criterion::Criterion; | ||
|
|
||
| use twenty_first::math::ntt::intt; | ||
| use twenty_first::math::other::random_elements; | ||
| use twenty_first::math::traits::PrimitiveRootOfUnity; | ||
| use twenty_first::math::zerofier_tree::ZerofierTree; | ||
| use twenty_first::prelude::*; | ||
|
|
||
| criterion_main!(benches); | ||
| criterion_group!( | ||
| name = benches; | ||
| config = Criterion::default().sample_size(10); | ||
| targets = extrapolation<{ 1 << 18 }, { 1 << 6 }>, | ||
| extrapolation<{ 1 << 18 }, { 1 << 7 }>, | ||
| extrapolation<{ 1 << 18 }, { 1 << 8 }>, | ||
| extrapolation<{ 1 << 19 }, { 1 << 6 }>, | ||
| extrapolation<{ 1 << 19 }, { 1 << 7 }>, | ||
| extrapolation<{ 1 << 19 }, { 1 << 8 }>, | ||
| extrapolation<{ 1 << 20 }, { 1 << 6 }>, | ||
| extrapolation<{ 1 << 20 }, { 1 << 7 }>, | ||
| extrapolation<{ 1 << 20 }, { 1 << 8 }>, | ||
| ); | ||
|
|
||
| fn intt_then_evaluate( | ||
| codeword: &[BFieldElement], | ||
| offset: BFieldElement, | ||
| zerofier_tree: &ZerofierTree<BFieldElement>, | ||
| shift_coefficients: &[BFieldElement], | ||
| tail_length: usize, | ||
| ) -> Vec<BFieldElement> { | ||
| let omega = BFieldElement::primitive_root_of_unity(codeword.len() as u64).unwrap(); | ||
| let log_domain_length = codeword.len().ilog2(); | ||
| let mut coefficients = codeword.to_vec(); | ||
| intt(&mut coefficients, omega, log_domain_length); | ||
| let polynomial: Polynomial<BFieldElement> = Polynomial::new(coefficients) | ||
| .scale(offset.inverse()) | ||
| .reduce_by_ntt_friendly_modulus(shift_coefficients, tail_length); | ||
| polynomial.divide_and_conquer_batch_evaluate(zerofier_tree) | ||
| } | ||
|
|
||
| fn extrapolation<const SIZE: usize, const NUM_POINTS: usize>(c: &mut Criterion) { | ||
| let log2_of_size = SIZE.ilog2(); | ||
| let mut group = c.benchmark_group(format!( | ||
| "Extrapolation of length-{SIZE} codeword in {NUM_POINTS} Points" | ||
| )); | ||
|
|
||
| let codeword = random_elements(SIZE); | ||
| let offset = BFieldElement::new(7); | ||
| let eval_points: Vec<BFieldElement> = random_elements(NUM_POINTS); | ||
|
|
||
| let zerofier_tree = ZerofierTree::new_from_domain(&eval_points); | ||
| let modulus = zerofier_tree.zerofier(); | ||
| let preprocessing_data = | ||
| Polynomial::fast_modular_coset_interpolate_preprocess(SIZE, offset, &modulus); | ||
|
|
||
| let id = BenchmarkId::new("INTT-then-Evaluate", log2_of_size); | ||
| group.bench_function(id, |b| { | ||
| b.iter(|| { | ||
| intt_then_evaluate( | ||
| &codeword, | ||
| offset, | ||
| &zerofier_tree, | ||
| &preprocessing_data.shift_coefficients, | ||
| preprocessing_data.tail_length, | ||
| ) | ||
| }) | ||
| }); | ||
|
|
||
| // We used to have another benchmark here that used barycentric evaluation | ||
| // (from `fri.rs` in repo triton-vm) inside of a loop over all points. It | ||
| // was never close to faster. | ||
| let id = BenchmarkId::new("Fast Codeword Extrapolation", log2_of_size); | ||
| group.bench_function(id, |b| { | ||
| b.iter(|| { | ||
| let minimal_interpolant = | ||
| Polynomial::<BFieldElement>::fast_modular_coset_interpolate_with_zerofiers_and_ntt_friendly_multiple( | ||
| &codeword, | ||
| offset, | ||
| &modulus, | ||
| &preprocessing_data | ||
| ); | ||
| minimal_interpolant.divide_and_conquer_batch_evaluate(&zerofier_tree) | ||
| }) | ||
| }); | ||
|
|
||
| let id = BenchmarkId::new("Dispatcher (includes preprocessing)", log2_of_size); | ||
| group.bench_function(id, |b| { | ||
| b.iter(|| Polynomial::coset_extrapolate(offset, &codeword, &eval_points)) | ||
| }); | ||
|
|
||
| group.finish(); | ||
| } |
This file was deleted.
Oops, something went wrong.
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
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 |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ pub mod polynomial; | |
| pub mod tip5; | ||
| pub mod traits; | ||
| pub mod x_field_element; | ||
| pub mod zerofier_tree; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.