diff --git a/paddle/fluid/framework/new_executor/interpreter/dependency_builder.cc b/paddle/fluid/framework/new_executor/interpreter/dependency_builder.cc index 7f4b52123fbce5ba46a09e21e25bfa34ad034e66..f12fc719d49dea624e968c3b10ec1798722db2a5 100644 --- a/paddle/fluid/framework/new_executor/interpreter/dependency_builder.cc +++ b/paddle/fluid/framework/new_executor/interpreter/dependency_builder.cc @@ -53,33 +53,6 @@ bool IsCommunicationOp(const std::string& op_name) { return false; } -// check whether exists prior_op -> ... -> posterior_op to avoid building loops -bool IsDependency(int prior_op_idx, - int posterior_op_idx, - const std::map>& downstream_map) { - std::queue q; - q.push(prior_op_idx); - - while (!q.empty()) { - int op_idx = q.front(); - q.pop(); - - auto it = downstream_map.find(op_idx); - if (it != downstream_map.end()) { - for (int downstream_op_idx : it->second) { - if (downstream_op_idx == posterior_op_idx) { - return true; - } - - // no need for double enqueue checking since DAG is assumed - q.push(downstream_op_idx); - } - } - } - - return false; -} - const std::string StringizeDownstreamMap( const std::map>& downstream_map) { std::ostringstream oss; @@ -324,8 +297,9 @@ void DependencyBuilder::AddDependencyForReadOp() { for (size_t read_op_idx : read_ops) { for (size_t downstream_op_idx : startup_ops) { if (read_op_idx != downstream_op_idx && - !IsDependency(downstream_op_idx, read_op_idx, op_downstream_map_)) + !op_happens_before_[downstream_op_idx][read_op_idx]) { AddDownstreamOp(read_op_idx, downstream_op_idx); + } } } }