forked from mindspore-Ecosystem/mindspore
Optimization for BroadFirstSearchGraphCNodes function
This commit is contained in:
parent
7c1b44731e
commit
284ce5825f
|
@ -25,7 +25,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <queue>
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
@ -88,13 +87,14 @@ std::vector<AnfNodePtr> TopoSort(const AnfNodePtr &root, const SuccFunc &succ, c
|
||||||
|
|
||||||
// search the cnodes inside this graph only
|
// search the cnodes inside this graph only
|
||||||
std::vector<CNodePtr> BroadFirstSearchGraphCNodes(CNodePtr ret) {
|
std::vector<CNodePtr> BroadFirstSearchGraphCNodes(CNodePtr ret) {
|
||||||
std::queue<CNodePtr> todo;
|
std::deque<CNodePtr> todo(1024);
|
||||||
todo.push(ret);
|
todo.clear();
|
||||||
|
todo.push_back(ret);
|
||||||
std::vector<CNodePtr> sorted_nodes;
|
std::vector<CNodePtr> sorted_nodes;
|
||||||
auto seen = NewSeenGeneration();
|
auto seen = NewSeenGeneration();
|
||||||
while (!todo.empty()) {
|
while (!todo.empty()) {
|
||||||
CNodePtr top = todo.front();
|
CNodePtr top = todo.front();
|
||||||
todo.pop();
|
todo.pop_front();
|
||||||
sorted_nodes.push_back(top);
|
sorted_nodes.push_back(top);
|
||||||
auto inputs = top->inputs();
|
auto inputs = top->inputs();
|
||||||
for (auto &item : inputs) {
|
for (auto &item : inputs) {
|
||||||
|
@ -103,7 +103,7 @@ std::vector<CNodePtr> BroadFirstSearchGraphCNodes(CNodePtr ret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->isa<CNode>()) {
|
if (item->isa<CNode>()) {
|
||||||
todo.push(item->cast<CNodePtr>());
|
todo.push_back(item->cast<CNodePtr>());
|
||||||
}
|
}
|
||||||
item->seen_ = seen;
|
item->seen_ = seen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue