onnxruntime/onnxruntime/core/util/thread_utils.cc
Dmitri Smirnov d1b1cdc5c4
Replace GSL with GSL-LITE submodule and fix up refs (#1920)
Remove gsl subodule and replace with a local copy of gsl-lite
  Refactor for onnxruntime::make_unique
  gsl::span size and index are now size_t
  Remove lambda auto argument type detection.
  Remove constexpr from fail_fast in gsl due to Linux not being happy.
  Comment out std::stream support due to MacOS std lib broken.
  Move make_unique into include/core/common so it is accessible for server builds.
  Relax requirements for onnxruntime/test/providers/cpu/ml/write_scores_test.cc
  due to x86 build.
  Add ONNXRUNTIME_ROOT to Server Lib includes so gsl is recognized
2019-10-01 12:43:29 -07:00

19 lines
No EOL
745 B
C++

#include "thread_utils.h"
#include <algorithm>
#include <core/common/make_unique.h>
namespace onnxruntime {
namespace concurrency {
std::unique_ptr<ThreadPool> CreateThreadPool(const std::string& name, int thread_pool_size) {
if (thread_pool_size <= 0) { // default
thread_pool_size = std::max<int>(1, std::thread::hardware_concurrency() / 2);
}
// since we use the main thread for execution we don't have to create any threads on the thread pool when
// the requested size is 1. For other cases, we will have thread_pool_size + 1 threads for execution
return thread_pool_size == 1 ? nullptr : onnxruntime::make_unique<concurrency::ThreadPool>(name, thread_pool_size);
}
} // namespace concurrency
} // namespace onnxruntime