Skip to content

Commit

Permalink
use SetAffinity when logical cores > physical cores (hyperthreading) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eqy authored and tqchen committed Jul 18, 2018
1 parent 4a464c6 commit f32841f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/runtime/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ class ThreadPool {
num_workers_, [this](int worker_id) { this->RunWorker(worker_id); },
exclude_worker0_ /* include_main_thread */));
num_workers_used_ = threads_->Configure(threading::ThreadGroup::kBig, 0, exclude_worker0_);
// if MaxConcurrency restricted the number of workers (e.g., due to
// hyperthreading), respect the restriction
num_workers_used_ = std::min(num_workers_, num_workers_used_);
}
~ThreadPool() {
for (std::unique_ptr<SpscTaskQueue>& q : queues_) {
Expand Down
10 changes: 8 additions & 2 deletions src/runtime/threading_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ class ThreadGroup::Impl {
if (nthreads) {
num_workers_used = nthreads;
}
// if MaxConcurrency restricted the number of workers (e.g., due to
// hyperthreading), respect the restriction. On CPUs with N logical cores
// and N/2 physical cores this will set affinity to the first N/2 logical
// ones.
num_workers_used = std::min(num_workers_, num_workers_used);

const char *val = getenv("TVM_BIND_THREADS");
if (val == nullptr || atoi(val) == 1) {
// Skip if sorted_order.size() is bigger than the number of workers (threads_)
if (!(sorted_order_.size() > static_cast<unsigned int>(num_workers_))) {
// Do not set affinity if there are more workers than found cores
if (sorted_order_.size() >= static_cast<unsigned int>(num_workers_)) {
SetAffinity(exclude_worker0, mode == kLittle);
} else {
LOG(WARNING)
Expand Down

0 comments on commit f32841f

Please sign in to comment.