diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc index 0bf05c3c112c467b9cdae091e0d2d38d4d299655..fc8403155625fdf21c467aa189c65b14d3487b41 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc @@ -178,10 +178,7 @@ void ThreadedSSAGraphExecutor::RunOp( try { VLOG(10) << op->Name() << " : " << op->DebugString(); op->Run(use_event_); - - for (auto &each : op->outputs_) { - ready_var_q.Push(each); - } + ready_var_q.Extend(op->outputs_); } catch (platform::EnforceNotMet ex) { exception_.reset(new platform::EnforceNotMet(ex)); } catch (...) { diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.h b/paddle/fluid/framework/details/threaded_ssa_graph_executor.h index 26ff14786397933382795c1371e6ab68185b0abe..839217031145a276b25992e334657608c3637758 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.h +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.h @@ -35,6 +35,17 @@ class BlockingQueue { cv_.notify_one(); } + template + void Extend(const U &items) { + { + std::lock_guard g(mutex_); + for (auto &item : items) { + q_.emplace_back(item); + } + } + cv_.notify_all(); + } + T Pop() { std::unique_lock lock(mutex_); while (q_.empty()) {