Browse Source

fix(core): fix nr_threads is zero

GitOrigin-RevId: 0ccbe3c69b
tags/v1.5.0
Megvii Engine Team 4 years ago
parent
commit
ddba5c9674
3 changed files with 5 additions and 2 deletions
  1. +1
    -1
      dnn/test/common/utils.h
  2. +3
    -0
      src/core/impl/utils/thread_pool.cpp
  3. +1
    -1
      src/core/include/megbrain/utils/thread_pool.h

+ 1
- 1
dnn/test/common/utils.h View File

@@ -102,7 +102,7 @@ class CpuDispatchChecker final : MegcoreCPUDispatcher {
std::vector<std::thread> m_workers;
#endif
//! Total number of threads, including main thread.
size_t m_nr_threads = 0;
size_t m_nr_threads = 1;
};

//! track number of CpuDispatchChecker instances to avoid leaking


+ 3
- 0
src/core/impl/utils/thread_pool.cpp View File

@@ -20,6 +20,9 @@ ThreadPool::ThreadPool(size_t threads_num)
m_main_affinity_flag{false},
m_stop{false},
m_active{false} {
if (threads_num < 1) {
m_nr_threads = 1;
}
if (m_nr_threads > 1) {
if (m_nr_threads > static_cast<uint32_t>(sys::get_cpu_count())) {
mgb_log_debug(


+ 1
- 1
src/core/include/megbrain/utils/thread_pool.h View File

@@ -80,7 +80,7 @@ public:
~ThreadPool();

private:
const size_t m_nr_threads = 0;
size_t m_nr_threads = 1;
//! Indicate whether the main thread have binding
bool m_main_affinity_flag;
//! The callback binding the threads to cores


Loading…
Cancel
Save