[neurun] Refine DAGChecker implementation (#3538)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 14 Nov 2018 07:22:05 +0000 (16:22 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 14 Nov 2018 07:22:05 +0000 (16:22 +0900)
Make DAGChecker implementation simpler by using operands' use info.
Cannot make a cyclic test for now, since after creating a cycle then
`finishBuilding` is called, it will cause assert failure by runtime.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/verifier/Verifier.cc
runtimes/neurun/test/graph/verifier/Verifier.cc

index 550b944..18c706d 100644 (file)
@@ -47,22 +47,13 @@ bool DAGChecker::verify(const Graph &graph) const
     visited[index.value()] = true;
     on_stack[index.value()] = true;
 
-    auto outputs = node.getOutputs();
-    for (auto output : outputs)
+    for (auto output : node.getOutputs())
     {
-      // TODO Fix traversing algorithm
-      //      Every time need to search for operations that has `outgoing` as incoming from all
-      //      operations but we can hold that info cached
-      operations.iterate([&](const operation::Index &cand_index, const operation::Node &cand_node) {
-        auto inputs = cand_node.getInputs();
-        for (auto input : inputs)
-        {
-          if (output == input)
-          {
-            dfs_recursive(cand_index, cand_node);
-          }
-        }
-      });
+      const auto &operand = graph.operands().at(output);
+      for (const auto &use : operand.getUses().list())
+      {
+        dfs_recursive(use, graph.operations().at(use));
+      }
     }
 
     on_stack[index.value()] = false;
index 3cecc38..27f03bf 100644 (file)
@@ -45,11 +45,7 @@ TEST(Verifier, dag_checker)
 
   graph.addOperation(nnfw::make_unique<MockNode>(IndexSet{operand1}, IndexSet{operand2}));
 
-  ASSERT_EQ(verifier.verify(graph), true);
-
-  // Create cycle
-  graph.operands().at(operand1).setAsOperationOutput();
-  graph.addOperation(nnfw::make_unique<MockNode>(IndexSet{operand2}, IndexSet{operand1}));
+  graph.finishBuilding();
 
-  ASSERT_EQ(verifier.verify(graph), false);
+  ASSERT_EQ(verifier.verify(graph), true);
 }