tvm
threading_backend.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_RUNTIME_THREADING_BACKEND_H_
25 #define TVM_RUNTIME_THREADING_BACKEND_H_
26 
27 #include <functional>
28 #include <memory>
29 #include <vector>
30 
31 namespace tvm {
32 namespace runtime {
33 namespace threading {
34 
39 class ThreadGroup {
40  public:
41  class Impl;
42 
55  ThreadGroup(int num_workers, std::function<void(int)> worker_callback,
56  bool exclude_worker0 = false);
57  ~ThreadGroup();
58 
62  void Join();
63 
64  enum AffinityMode : int {
65  kBig = 1,
66  kLittle = -1,
67  };
68 
81  int Configure(AffinityMode mode, int nthreads, bool exclude_worker0);
82 
83  private:
84  Impl* impl_;
85 };
86 
90 void Yield();
91 
95 int MaxConcurrency();
96 
103 void ResetThreadPool();
104 
105 } // namespace threading
106 } // namespace runtime
107 } // namespace tvm
108 
109 #endif // TVM_RUNTIME_THREADING_BACKEND_H_
A platform-agnostic abstraction for managing a collection of thread pool threads. ...
Definition: threading_backend.h:39
void Join()
Blocks until all non-main threads in the pool finish.
void Yield()
Platform-agnostic no-op.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
ThreadGroup(int num_workers, std::function< void(int)> worker_callback, bool exclude_worker0=false)
Creates a collection of threads which run a provided function.
Definition: threading_backend.h:65
AffinityMode
Definition: threading_backend.h:64
void ResetThreadPool()
Reset the threads in the pool. All current threads are destroyed and new ones are created...
int Configure(AffinityMode mode, int nthreads, bool exclude_worker0)
configure the CPU id affinity
Definition: threading_backend.h:66