[neurun] Introduce Graph Phase (#2298)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Tue, 14 Aug 2018 10:14:11 +0000 (19:14 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 14 Aug 2018 10:14:11 +0000 (19:14 +0900)
`graph::Graph::Phase` is an enum class that represents which phase the
Graph is at. Since we are going to use `Graph` class for multiple
phases we need this with verification infra.

- Introduce an enum class `graph::Graph::Phase`
- Phase transition when `ANeuralNetworksModel_finish()` is called
- Call verifier from the appropriate place

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/Graph.cc
runtimes/neurun/src/graph/Graph.h
runtimes/neurun/src/model.cc

index 86f1a14..d33dc79 100644 (file)
@@ -4,6 +4,7 @@
 #include <bitset>
 
 #include "logging.h"
+#include "verifier/IVerifier.h"
 
 namespace neurun
 {
@@ -32,6 +33,18 @@ void Graph::addInput(const operand::Index &ind) { _inputs.append(ind); }
 
 void Graph::addOutput(const operand::Index &ind) { _outputs.append(ind); }
 
+void Graph::finishBuilding(void)
+{
+  assert(_phase == Phase::BUILDING);
+  _phase = Phase::MODEL;
+
+  // Call graph verifications for the MODEL phase
+  {
+    verifier::DAGChecker dag_checker;
+    dag_checker.verify(*this);
+  }
+}
+
 void Graph::iteratePostDfs(const std::function<void(const operation::Node &)> &fn) const
 {
   std::vector<bool> visited(_operations.size(), false);
index a4b762e..5c63b32 100644 (file)
@@ -15,6 +15,14 @@ namespace graph
 
 class Graph
 {
+private:
+  enum class Phase
+  {
+    BUILDING,
+    MODEL,
+    LOWERED
+  };
+
 public:
   Graph(void) = default;
 
@@ -26,6 +34,7 @@ public:
                        std::unique_ptr<::internal::tflite::operand::Data> &&data);
   void addInput(const operand::Index &ind);
   void addOutput(const operand::Index &ind);
+  void finishBuilding(void);
 
   // Accessors
 public:
@@ -39,6 +48,7 @@ public:
   void iteratePostDfs(const std::function<void(const operation::Node &)> &fn) const;
 
 private:
+  Phase _phase{Phase::BUILDING};
   operation::Set _operations;
   operand::Set _operands;
   operand::IndexSet _inputs;
index f3ad0b4..06dec38 100644 (file)
@@ -1,5 +1,7 @@
 #include "model.h"
 
+#include "graph/Graph.h"
+
 //
 // ANeuralNetworksModel
 //
@@ -17,6 +19,7 @@ ResultCode ANeuralNetworksModel::finish()
   }
 
   _finished = true;
+  _model->finishBuilding();
 
   return ANEURALNETWORKS_NO_ERROR;
 }