提交 998f71a8 编写于 作者: M Megvii Engine Team

perf(mge/imperative): do not busy wait in imperative's queue

GitOrigin-RevId: de8db5109679ed70e38fcecfbb99478aa9303b2b
上级 62637fc4
......@@ -67,6 +67,12 @@ auto to_tuple(T begin, T end, pybind11::return_value_policy policy = pybind11::r
class PyTaskDipatcher {
struct Queue : mgb::AsyncQueueSC<std::function<void(void)>, Queue> {
using Task = std::function<void(void)>;
// set max_spin=0 to prevent Queue fetch task in busy wait manner.
// this won't affect throughput when python interpreter is sending enough task,
// but will significantly save CPU time when waiting for task, e.g. wait for data input
Queue() : mgb::AsyncQueueSC<std::function<void(void)>, Queue>(0) {}
void process_one_task(Task& f) {
if (!Py_IsInitialized()) return;
pybind11::gil_scoped_acquire _;
......
......@@ -207,7 +207,11 @@ private:
size_t m_enable_evict = 0;
struct WorkQueue : AsyncQueueSC<Command, WorkQueue> {
WorkQueue(ChannelImpl* owner) : m_owner(owner) {
// set max_spin=0 to prevent Queue fetch task in busy wait manner.
// this won't affect throughput when python interpreter is sending enough task,
// but will significantly save CPU time when waiting for task, e.g. wait for data input
WorkQueue(ChannelImpl* owner)
: AsyncQueueSC<Command, WorkQueue>(0), m_owner(owner) {
sys::set_thread_name("interpreter");
}
void process_one_task(Command& cmd) {
......
......@@ -30,7 +30,10 @@ class AsyncReleaser : public CompNodeDepedentObject {
AsyncReleaser* m_par_releaser;
public:
Waiter(AsyncReleaser* releaser) : m_par_releaser(releaser) {}
// disable busy wait by set max_spin=0 to save CPU cycle
Waiter(AsyncReleaser* releaser)
: AsyncQueueSC<WaiterParam, Waiter>(0),
m_par_releaser(releaser) {}
void process_one_task(WaiterParam& param) {
if (param.event->finished()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册