From fd99d768a5300aeb0441d790a4aa83131fa013c4 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: Tue, 14 Aug 2018 19:14:11 +0900 Subject: [PATCH] [neurun] Introduce Graph Phase (#2298) `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 --- runtimes/neurun/src/graph/Graph.cc | 13 +++++++++++++ runtimes/neurun/src/graph/Graph.h | 10 ++++++++++ runtimes/neurun/src/model.cc | 3 +++ 3 files changed, 26 insertions(+) diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index 86f1a14..d33dc79 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -4,6 +4,7 @@ #include #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 &fn) const { std::vector visited(_operations.size(), false); diff --git a/runtimes/neurun/src/graph/Graph.h b/runtimes/neurun/src/graph/Graph.h index a4b762e..5c63b32 100644 --- a/runtimes/neurun/src/graph/Graph.h +++ b/runtimes/neurun/src/graph/Graph.h @@ -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 &fn) const; private: + Phase _phase{Phase::BUILDING}; operation::Set _operations; operand::Set _operands; operand::IndexSet _inputs; diff --git a/runtimes/neurun/src/model.cc b/runtimes/neurun/src/model.cc index f3ad0b4..06dec38 100644 --- a/runtimes/neurun/src/model.cc +++ b/runtimes/neurun/src/model.cc @@ -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; } -- 2.7.4