-
Notifications
You must be signed in to change notification settings - Fork 598
feat: parallelization update for polynomials #2311
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
7 commits
Select commit
Hold shift + click to select a range
ca523b5
created thread_utils file, calc_num_threads function
lucasxia01 9523695
added namespace
lucasxia01 13219e2
replaced sumcheck duplicated code with calculate_num_threads_pow2
lucasxia01 c9e3da3
small fixes
lucasxia01 1e40cae
Merge branch 'master' into lx/parallelization_update_polynomials
lucasxia01 7e8e41a
Merge branch 'master' into lx/parallelization_update_polynomials
codygunton 4672989
Merge branch 'master' into lx/parallelization_update_polynomials
codygunton 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
| 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 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,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, | ||
lucasxia01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); | ||
|
|
||
| } // namespace barretenberg::thread_utils | ||
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
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.