Open
Conversation
## Context This PR addresses `AztecProtocol/barretenberg#1656` by making the `MSM::batch_multi_scalar_mul(...)` phase breakdown measurable and by adding a benchmark case that targets the exact regime called out in the issue (`2^16` points with `256` threads). The goal is to answer: is the single-threaded final reduction (`accumulate_results`) actually a bottleneck relative to the full MSM? ## What Changed ### 1) Phase Breakdown (`BB_BENCH`) inside `batch_multi_scalar_mul` Added `BB_BENCH` scopes for: - `MSM::batch_multi_scalar_mul/evaluate_work_units` - `MSM::batch_multi_scalar_mul/accumulate_results` - `MSM::batch_multi_scalar_mul/batch_normalize` - `MSM::batch_multi_scalar_mul/scalars_to_montgomery` These are surfaced in google-benchmark output via `GOOGLE_BB_BENCH_REPORTER(state)`. ### 2) New Benchmark Case: `BatchMSM_1656` Added a dedicated benchmark: - `PippengerBench/BatchMSM_1656/256/{msm_size}` - Single MSM (`num_polys = 1`) - Sizes: - `msm_size ∈ {2^16, 2^20}` This uses `bb::set_parallel_for_concurrency(256)` to force the intended partitioning and restores the original value after the benchmark finishes. ## Results (Local) Machine: 4 vCPU laptop (so `256 threads` is intentionally oversubscribed; the key point is the *absolute* reduction overhead). Key takeaways (from `BB_BENCH` counters; time counters are nanoseconds): - `2^16, 256 threads`: - `accumulate_results ≈ 139k ns` (~0.139 ms) - total `≈ 521 ms` - reduction fraction `~0.027%` - `2^20, 256 threads`: - `accumulate_results ≈ 141k ns` (~0.141 ms) - total `≈ 3457 ms` - reduction fraction `~0.004%` So the final reduction appears negligible in these regimes on my setup, and the benchmark now makes it easy to validate on a 64+ core machine where the original concern is most relevant. ## Notes / Background - `MSM` here is a Pippenger-style MSM. For background reading on multiexponentiation / multi-product methods: - Nicholas Pippenger, *On the evaluation of powers and related problems* (1976). - Jurjen Bos and Matthijs Coster, *Addition Chain Heuristics* (CRYPTO 1989). - Ryan Henry, *Pippenger's Multiproduct and Multiexponentiation Algorithms* (2010). ## How To Run ``` cmake --build <build-dir> --target pippenger_bench CRS_PATH=<path-to-bn254_g1.dat> <build-dir>/bin/pippenger_bench \ --benchmark_filter='BatchMSM_1656' \ --benchmark_min_time=0.1s \ --benchmark_counters_tabular=true ``` Fixes AztecProtocol/barretenberg#1656 --------- Co-authored-by: Peter <peter@users.noreply.github.com> Co-authored-by: Jonathan Hao <jonathan@aztec-labs.com>
Collaborator
Author
|
🤖 Auto-merge enabled after 4 hours of inactivity. This PR will be merged automatically once all checks pass. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
BEGIN_COMMIT_OVERRIDE
chore: bench phase breakdown + thread sweep for MSM reduction (#21885)
END_COMMIT_OVERRIDE