Skip to content
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

Added multithreaded version of chain-generic-numerator to remove CPU bottleneck #3766

Merged
merged 9 commits into from
Jan 7, 2020
Prev Previous commit
Next Next commit
Made number of threads command line configurable and set default to 1
  • Loading branch information
akshaysubr committed Dec 12, 2019
commit ae31d97ad3af01e8c27d69cd8879872099afa32c
3 changes: 2 additions & 1 deletion src/chain/chain-generic-numerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ bool GenericNumeratorComputation::ForwardBackward(
derivs.Set(-std::numeric_limits<BaseFloat>::infinity());

// Set total number of workers to the available hardware concurrency
unsigned int nthreads = opts_.multithreaded ? std::thread::hardware_concurrency() : 1;
unsigned int nthreads = opts_.num_threads > 0 ? opts_.num_threads :
std::thread::hardware_concurrency();
// Naive load balancing, each thread gets a chunk of the sequences to process
unsigned int num_sequences_per_thread =
(num_sequences + nthreads - 1) / nthreads;
Expand Down
10 changes: 5 additions & 5 deletions src/chain/chain-generic-numerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ namespace chain {


struct GenericNumeratorComputationOptions {
bool multithreaded;
GenericNumeratorComputationOptions(): multithreaded(true) { }
unsigned int num_threads;
GenericNumeratorComputationOptions(): num_threads(1) { }
void Register(OptionsItf *opts) {
opts->Register("multithreaded-numerator-graph", &multithreaded, "If true, "
"use multiple threads to parallelize the chain numerator "
"graph computation");
opts->Register("numerator-graph-threads", &num_threads, "Number of threads "
"to use to parallelize the chain numerator graph computation. "
"If 0, use available hardware concurrency.");
}

};
Expand Down