From 26eeb62f75159716b3ba74ee5e34808ab13745d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Wed, 28 Nov 2018 07:11:41 +0900 Subject: [PATCH] [neurun] Fix Graph Verifier visit check (#3722) Visit and OnStack checking assumed ID range as vector which is wrong. This commit changes variable `visit` and `on_stack` to be a map so it can correctly check nodes for sure. In the same manner with #3721 Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/verifier/Verifier.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/runtimes/neurun/src/graph/verifier/Verifier.cc b/runtimes/neurun/src/graph/verifier/Verifier.cc index 18c706d..4de61b8 100644 --- a/runtimes/neurun/src/graph/verifier/Verifier.cc +++ b/runtimes/neurun/src/graph/verifier/Verifier.cc @@ -35,17 +35,21 @@ bool DAGChecker::verify(const Graph &graph) const { auto &operations = graph.operations(); bool cyclic = false; - std::vector visited(operations.size(), false); - std::vector on_stack(operations.size(), false); + + std::unordered_map visited; + operations.iterate([&](const graph::operation::Index &index, const operation::Node &) { + visited[index] = false; + }); + std::unordered_map on_stack = visited; // Copy from visited std::function dfs_recursive = [&](const operation::Index &index, const operation::Node &node) -> void { - if (on_stack[index.value()]) + if (on_stack[index]) cyclic = true; - if (visited[index.value()]) + if (visited[index]) return; - visited[index.value()] = true; - on_stack[index.value()] = true; + visited[index] = true; + on_stack[index] = true; for (auto output : node.getOutputs()) { @@ -56,7 +60,7 @@ bool DAGChecker::verify(const Graph &graph) const } } - on_stack[index.value()] = false; + on_stack[index] = false; }; operations.iterate(dfs_recursive); -- 2.7.4