From 2b1cd462466c3e9aab72c53a996cf62606c5c6f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 2 Jan 2019 11:17:54 +0900 Subject: [PATCH] Revise compile state (#4086) Move lower, linearize state setting to plan Signed-off-by: Hyeongseok Oh --- runtimes/neurun/src/compiler/Compiler.cc | 4 +++- runtimes/neurun/src/compiler/Plan.h | 9 +++++---- runtimes/neurun/src/graph/Graph.cc | 7 +------ runtimes/neurun/src/graph/Graph.h | 5 +---- runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/runtimes/neurun/src/compiler/Compiler.cc b/runtimes/neurun/src/compiler/Compiler.cc index fb5f504..e1d24d8 100644 --- a/runtimes/neurun/src/compiler/Compiler.cc +++ b/runtimes/neurun/src/compiler/Compiler.cc @@ -52,10 +52,12 @@ void Compiler::compile(void) // Lower: decide backend graph.lower(); + plan.state(State::LOWERED); dot_dumper.dumpIfNeeded("after_lower"); auto linear = graph.linearize(); + plan.state(State::LINEARIZED); // Dump ops linear->accept(neurun::graph::dumper::Dumper{}); @@ -105,7 +107,7 @@ void Compiler::compile(void) * Code generation phase finished ********************************/ - plan.state(State::PLANNED); + plan.state(State::COMPILED); } } // namespace compiler diff --git a/runtimes/neurun/src/compiler/Plan.h b/runtimes/neurun/src/compiler/Plan.h index d7ba31f..f2a526e 100644 --- a/runtimes/neurun/src/compiler/Plan.h +++ b/runtimes/neurun/src/compiler/Plan.h @@ -28,10 +28,11 @@ namespace compiler enum class State { - NONE, // Initial state - FAILED, // Failed - PLANNED, // Success planned - NO_PLAN // Not planned by environment or graph status + NONE, // Initial state + LOWERED, // Backend is decided + LINEARIZED, // Everything is moved to Linear object so this Graph object is no longer effective + COMPILED, // Success compilation + NOT_COMPILED // Not compiled by environment or graph status }; class Plan diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index 33f30ea..280125a 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -206,8 +206,6 @@ void Graph::lower(void) }); } - _phase = Phase::LOWERED; - // Run PermutationInsertionPass { pass::PermutationInsertionPass pi_pass(*this); @@ -225,14 +223,11 @@ void Graph::lower(void) std::unique_ptr Graph::linearize(void) { - assert(isLowered()); + assert(_phase == Phase::MODEL); auto linear = nnfw::cpp14::make_unique(*this); // TODO Move the operations and operands to linear object - - _phase = Phase::LINEARIZED; - return std::move(linear); } diff --git a/runtimes/neurun/src/graph/Graph.h b/runtimes/neurun/src/graph/Graph.h index 6078793..7b9d639 100644 --- a/runtimes/neurun/src/graph/Graph.h +++ b/runtimes/neurun/src/graph/Graph.h @@ -49,9 +49,7 @@ private: enum class Phase { BUILDING, - MODEL, - LOWERED, - LINEARIZED // Everything is moved to Linear object so this Graph object is no longer effective + MODEL }; public: @@ -110,7 +108,6 @@ public: void removeOperand(const model::operand::Index &ind) { _model->operands.remove(ind); } std::unique_ptr linearize(void); bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; } - bool isLowered(void) const { return _phase == Phase::LOWERED; } private: void initializeUseDef(); diff --git a/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc b/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc index 1f49c91..a5d2752 100644 --- a/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc +++ b/runtimes/neurun/src/graph/pass/PermutationInsertionPass.cc @@ -117,7 +117,7 @@ model::operation::Index PermutationInsertionPass::insertPermute(const model::operand::Index &operand_index, const backend::Backend *backend) { - assert(_graph.isLowered()); + assert(!_graph.isBuildingPhase()); auto &operand = _graph.operands().at(operand_index); -- 2.7.4