From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Tue, 27 Nov 2018 06:28:46 +0000 (+0900) Subject: [neurun] Fix Dfs Iterator (#3721) X-Git-Tag: 0.3~317 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42c1600cf5fa6659a941d51e33dc6a73e7a2a63e;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Fix Dfs Iterator (#3721) As mentioned from #3617 by @d-poshshoev, Visit checking assumed ID range as vector which is wrong. This commit changes variable `visit` to be a map so it can correctly check nodes for sure. Signed-off-by: Hanjoung Lee --- diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index aa26e92..33aa25c 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -281,13 +281,15 @@ void Graph::PostDfsIterator::iterate(GraphRef graph, const IterFn &fn) { assert(!graph.isBuildingPhase()); // Restrict iteration condition - std::vector visited(graph.operations().size(), false); + std::unordered_map visited; + graph.operations().iterate( + [&](const operation::Index &index, NodeRef) { visited[index] = false; }); std::function dfs_recursive = [&](const operation::Index &index, NodeRef node) -> void { - if (visited[index.asInt()]) + if (visited[index]) return; - visited[index.asInt()] = true; + visited[index] = true; for (auto output : node.getOutputs()) { @@ -304,7 +306,8 @@ void Graph::PostDfsIterator::iterate(GraphRef graph, const IterFn &fn) graph.operations().iterate(dfs_recursive); // All of the operations(nodes) must have been visited. - assert(std::all_of(visited.begin(), visited.end(), [](bool v) { return v; })); + assert(std::all_of(visited.begin(), visited.end(), + [](const std::pair &v) { return v.second; })); } } // namespace graph