-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parallelization update for polynomials (#2311)
I added parallelization update to polynomials, specifically to the `add_scaled`, `operator+=`, `operator-=`, and `operator*=` functions. This was done using the parallel_for function, replacing the simple for loops. This update has sped up the Gemini component without queue processing (just `execute_univariatization_round()`) by roughly 5-10x. In particular, with a circuit of 2^19 gates, this component's runtime changes from ~520ms to ~65ms. Overall, this change leads to ~20% improvements in Honk for larger circuit sizes. Note that these values are noisy because of mainframe load. Another side note is that the Shplonk component seems to be slower with these changes for small circuit sizes (2^13 or so), and this needs further investigation. For larger circuit sizes, we observe a ~2x speedup in the Shplonk component. More benchmarking details [here](https://docs.google.com/spreadsheets/d/1mFquxU0nbigLwmttcfxC2Yc9J8-TbjLKOHeRMtY7JfM/). I also created new thread_utils file for standardization purposes, which includes the `calculate_num_threads`, and `calculate_num_threads_pow2` functions. These functions serve to calculate the number of threads to split up the work based on the minimum number of iterations per thread and the total amount of iterations. --------- Co-authored-by: codygunton <[email protected]>
- Loading branch information
1 parent
882682b
commit 922fc99
Showing
5 changed files
with
119 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,40 @@ | ||
#include "thread_utils.hpp" | ||
|
||
namespace barretenberg::thread_utils { | ||
/** | ||
* @brief calculates number of threads to create based on minimum iterations per thread | ||
* @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` | ||
* Returns the min of `desired_num_threads` and `max_num_threads`. | ||
* Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead | ||
* | ||
* @param num_iterations | ||
* @param min_iterations_per_thread | ||
* @return size_t | ||
*/ | ||
size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread) | ||
{ | ||
size_t max_num_threads = get_num_cpus(); // number of available threads | ||
size_t desired_num_threads = num_iterations / min_iterations_per_thread; | ||
size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified | ||
num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 | ||
return num_threads; | ||
} | ||
|
||
/** | ||
* @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 | ||
* @details Same functionality as `calculate_num_threads` but guaranteed power of 2 | ||
* @param num_iterations | ||
* @param min_iterations_per_thread | ||
* @return size_t | ||
*/ | ||
size_t calculate_num_threads_pow2(size_t num_iterations, size_t min_iterations_per_thread) | ||
{ | ||
size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) | ||
size_t desired_num_threads = num_iterations / min_iterations_per_thread; | ||
desired_num_threads = static_cast<size_t>(1ULL << numeric::get_msb(desired_num_threads)); | ||
size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified | ||
num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 | ||
return num_threads; | ||
} | ||
|
||
} // namespace barretenberg::thread_utils |
This file contains 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,29 @@ | ||
#include "thread.hpp" | ||
|
||
namespace barretenberg::thread_utils { | ||
|
||
const size_t DEFAULT_MIN_ITERS_PER_THREAD = 1 << 4; | ||
|
||
/** | ||
* @brief calculates number of threads to create based on minimum iterations per thread | ||
* @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` | ||
* Returns the min of `desired_num_threads` and `max_num_theads`. | ||
* Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead | ||
* | ||
* @param num_iterations | ||
* @param min_iterations_per_thread | ||
* @return size_t | ||
*/ | ||
size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); | ||
|
||
/** | ||
* @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 | ||
* @details Same functionality as `calculate_num_threads` but guaranteed power of 2 | ||
* @param num_iterations | ||
* @param min_iterations_per_thread | ||
* @return size_t | ||
*/ | ||
size_t calculate_num_threads_pow2(size_t num_iterations, | ||
size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); | ||
|
||
} // namespace barretenberg::thread_utils |
This file contains 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 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 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