From e05fa18d59b6063d0c1fddca6555292a4217fb26 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: Tue, 29 Jan 2019 08:52:30 +0900 Subject: [PATCH] Remove plan getter in Compiler (#4347) Remove plan getter in Compiler Prepare remove non-const model getter in Plan Fix plain initialize in Compiler to return nullptr when release() is called before compile() Signed-off-by: Hyeongseok Oh --- runtimes/neurun/src/compiler/Compiler.cc | 19 ++++++++++--------- runtimes/neurun/src/compiler/Compiler.h | 14 ++++++-------- runtimes/neurun/src/frontend/wrapper/compilation.h | 1 - 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/runtimes/neurun/src/compiler/Compiler.cc b/runtimes/neurun/src/compiler/Compiler.cc index b1bf70b..be50923 100644 --- a/runtimes/neurun/src/compiler/Compiler.cc +++ b/runtimes/neurun/src/compiler/Compiler.cc @@ -34,9 +34,10 @@ namespace compiler void Compiler::compile(void) { - auto &plan = this->plan(); - auto &graph = plan.model(); - const auto &operands = graph.operands(); + // TODO Move generating _plan before return + _plan = std::make_shared(_model); + + const auto &operands = _model->operands(); // Disable compile phase // When ready to use interpreter backend, remove this config and use backend setting @@ -55,16 +56,16 @@ void Compiler::compile(void) *************************************************************/ // dump graph to .dot - neurun::dumper::dot::DotDumper dot_dumper(graph); + neurun::dumper::dot::DotDumper dot_dumper(*_model); dot_dumper.dumpIfNeeded("before_lower"); // Lower: decide backend - graph.lower(); + _model->lower(); _state = State::LOWERED; dot_dumper.dumpIfNeeded("after_lower"); - auto linear = graph.linearize(); + auto linear = _model->linearize(); _state = State::LINEARIZED; // Dump ops @@ -83,7 +84,7 @@ void Compiler::compile(void) // finalize: generate tensor using subtensor info, then execute stage // Generated SubTensorInfo is in operand(Object) // for easy pass SubTensorInfo to plan builder and tensor builder - linear->accept(SubTensorAnalyzer{graph}); + linear->accept(SubTensorAnalyzer{*_model}); /********************************************************** * Backend dependent analysis & optimization phase finished @@ -93,7 +94,7 @@ void Compiler::compile(void) * Code generation phase ***********************/ - PlanBuilder plan_builder{plan}; + PlanBuilder plan_builder{*_plan}; // Plan building linear->iterate([&](const linear::Element &element) { @@ -109,7 +110,7 @@ void Compiler::compile(void) // TODO Add optimization passes plan_builder.finalize(tensor_builders); - ConstantInitializer{graph, plan}(); + ConstantInitializer{*_model, *_plan}(); /******************************** * Code generation phase finished diff --git a/runtimes/neurun/src/compiler/Compiler.h b/runtimes/neurun/src/compiler/Compiler.h index a555899..54b0fb2 100644 --- a/runtimes/neurun/src/compiler/Compiler.h +++ b/runtimes/neurun/src/compiler/Compiler.h @@ -49,24 +49,21 @@ public: * @brief Construct a new Compiler object * @param[in] model Graph model */ - Compiler(const std::shared_ptr &model) : _plan{new Plan{model}}, _state{State::NONE} + Compiler(const std::shared_ptr &model) + : _model{model}, _plan{nullptr}, _state{State::NONE} { // DO NOTHING } public: /** - * @brief Return plan - * @return Plan - */ - Plan &plan(void) { return *_plan; } - /** - * @brief Run compilation + * @brief Run compilation. Compilation result will be saved in _plan */ void compile(void); /** * @brief Pass plan reference - * @param[out] plan Plan reference to return + * @param[out] plan Plan reference to return\n + * Set nullptr if compile is not run yet */ void release(std::shared_ptr &plan) { plan = _plan; } @@ -74,6 +71,7 @@ public: State state(void) const { return _state; } private: + std::shared_ptr _model; std::shared_ptr _plan; State _state; }; diff --git a/runtimes/neurun/src/frontend/wrapper/compilation.h b/runtimes/neurun/src/frontend/wrapper/compilation.h index 1f2bd79..acca62a 100644 --- a/runtimes/neurun/src/frontend/wrapper/compilation.h +++ b/runtimes/neurun/src/frontend/wrapper/compilation.h @@ -30,7 +30,6 @@ public: } public: - neurun::compiler::Plan &plan(void) { return _compiler->plan(); } neurun::compiler::State state(void) { return _compiler->state(); } public: -- 2.7.4