3 #include <condition_variable> 10 #include <c10/util/Optional.h> 11 #include <c10/util/intrusive_ptr.h> 12 #include <c10/util/numa.h> 13 #include <c10/util/thread_name.h> 24 virtual void run(
const std::function<
void()>& func) = 0;
26 virtual size_t size()
const = 0;
31 virtual size_t numAvailable()
const = 0;
36 virtual bool inThreadPool()
const = 0;
45 const std::function<void()> no_id;
46 const std::function<void(std::size_t)> with_id;
49 : run_with_id(
false), no_id(f), with_id(
nullptr) {}
51 : run_with_id(
true), no_id(
nullptr), with_id(f) {}
54 std::queue<task_element_t> tasks_;
55 std::vector<std::thread> threads_;
57 std::condition_variable condition_;
58 std::condition_variable completed_;
59 std::atomic_bool running_;
61 std::size_t available_;
69 std::size_t pool_size,
70 int numa_node_id = -1);
74 size_t size()
const override;
76 size_t numAvailable()
const override;
78 bool inThreadPool()
const override;
80 void run(
const std::function<
void()>& func)
override;
82 template <
typename Task>
83 void runTaskWithID(Task task) {
84 std::unique_lock<std::mutex> lock(mutex_);
89 task_element_t(
static_cast<std::function<void(std::size_t)>
>(task)));
91 condition_.notify_one();
95 void waitWorkComplete();
98 virtual void init_thread() {}
102 void main_loop(std::size_t index);
105 C10_API
void setNumThreads(
size_t v);
112 std::size_t pool_size,
113 int numa_node_id = -1)
117 void init_thread()
override {
118 setThreadName(
"CaffeTaskThread");
123 C10_DECLARE_SHARED_REGISTRY(
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
void NUMABind(int numa_node_id)
Bind to a given NUMA node.