Skip to content

Commit 745f88b

Browse files
authored
Merge pull request #15768 from wojtuss/wojtuss/fix-link-to-debug
Removed duplicated code
2 parents 118b765 + 7a412cd commit 745f88b

File tree

2 files changed

+1
-97
lines changed

2 files changed

+1
-97
lines changed

paddle/fluid/inference/analysis/ir_passes/subgraph_detector.cc

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -460,77 +460,6 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) {
460460
return node.inputs.size() == n;
461461
}
462462

463-
NodesTSIterator::NodesTSIterator(const std::vector<Node *> &source) {
464-
PADDLE_ENFORCE(!source.empty(),
465-
"Start points of topological sorting should not be empty!");
466-
// CHECK all the inputs' in-degree is 0
467-
for (auto *node : source) {
468-
PADDLE_ENFORCE(CheckNodeIndegreeEquals(*node, 0));
469-
}
470-
471-
std::unordered_set<Node *> visited;
472-
std::unordered_set<Node *> to_visit{source.begin(), source.end()};
473-
474-
std::vector<Node *> inlink_visited;
475-
while (!to_visit.empty()) {
476-
std::vector<Node *> queue(to_visit.begin(), to_visit.end());
477-
for (auto *p : queue) {
478-
if (Agent(p).deleted()) {
479-
visited.insert(p);
480-
to_visit.erase(p);
481-
}
482-
483-
inlink_visited.clear();
484-
485-
std::copy_if(p->inputs.begin(), p->inputs.end(),
486-
std::back_inserter(inlink_visited),
487-
[&](Node *x) -> bool { return visited.count(x) != 0; });
488-
489-
if (inlink_visited.size() == p->inputs.size()) {
490-
sorted_.push_back(p);
491-
for (auto *_ : p->outputs) {
492-
if (!visited.count(_)) {
493-
to_visit.insert(_);
494-
}
495-
}
496-
497-
to_visit.erase(p);
498-
visited.insert(p);
499-
}
500-
}
501-
}
502-
}
503-
504-
NodesTSIterator::NodesTSIterator(const NodesTSIterator &other)
505-
: sorted_(other.sorted_), cursor_(other.cursor_) {}
506-
507-
Node &NodesTSIterator::operator*() {
508-
PADDLE_ENFORCE_LT(cursor_, sorted_.size());
509-
return *sorted_[cursor_];
510-
}
511-
512-
NodesTSIterator &NodesTSIterator::operator++() {
513-
if (++cursor_ >= sorted_.size()) {
514-
sorted_.clear();
515-
cursor_ = 0;
516-
}
517-
return *this;
518-
}
519-
NodesTSIterator &NodesTSIterator::operator=(const NodesTSIterator &other) {
520-
cursor_ = other.cursor_;
521-
sorted_ = other.sorted_;
522-
return *this;
523-
}
524-
525-
bool NodesTSIterator::operator==(const NodesTSIterator &other) {
526-
return sorted_ == other.sorted_ && cursor_ == other.cursor_;
527-
}
528-
529-
Node *NodesTSIterator::operator->() {
530-
PADDLE_ENFORCE_LT(cursor_, sorted_.size());
531-
return sorted_[cursor_];
532-
}
533-
534463
} // namespace analysis
535464
} // namespace inference
536465
} // namespace paddle

paddle/fluid/inference/analysis/ir_passes/subgraph_detector.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace inference {
3030
namespace analysis {
3131

3232
using framework::ir::Graph;
33+
using framework::ir::NodesTSIterator;
3334

3435
const char kIsFunctionNode[] = "__is_function_node__";
3536
const char kFunctionNodeSubGraph[] = "__function_node_sub_graph__";
@@ -132,32 +133,6 @@ struct Agent {
132133
framework::ir::Node *x_;
133134
};
134135

135-
// Topological sorting iterator on nodes.
136-
struct NodesTSIterator
137-
: public std::iterator<std::forward_iterator_tag, framework::ir::Node *> {
138-
NodesTSIterator() = default;
139-
explicit NodesTSIterator(const std::vector<framework::ir::Node *> &source);
140-
NodesTSIterator(NodesTSIterator &&other)
141-
: sorted_(std::move(other.sorted_)), cursor_(other.cursor_) {
142-
other.cursor_ = 0;
143-
}
144-
NodesTSIterator(const NodesTSIterator &other);
145-
146-
framework::ir::Node &operator*();
147-
NodesTSIterator &operator++();
148-
// TODO(Superjomn) current implementation just compare the first
149-
// element, need to compare the graph and all the elements in the queue and
150-
// set.
151-
NodesTSIterator &operator=(const NodesTSIterator &other);
152-
bool operator==(const NodesTSIterator &other);
153-
bool operator!=(const NodesTSIterator &other) { return !(*this == other); }
154-
framework::ir::Node *operator->();
155-
156-
private:
157-
std::vector<framework::ir::Node *> sorted_;
158-
size_t cursor_{0};
159-
};
160-
161136
// The nodes those have no input will be treated as start points.
162137
static std::vector<framework::ir::Node *> ExtractStartPoints(const Graph &g) {
163138
std::vector<framework::ir::Node *> result;

0 commit comments

Comments
 (0)