From 5dd190b6169981701b0ab9c6415cd152a32c734d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 27 Mar 2019 08:57:50 +0900 Subject: [PATCH] [neurun] Promote OperandContext to ExecutorBase (#4864) As all the executors have OperandContext in common, we can promote it to its base class `ExecutorBase`. Part of #4823 Signed-off-by: Hanjoung Lee --- runtimes/neurun/core/src/compiler/Compiler.cc | 9 +++++---- runtimes/neurun/core/src/exec/DataflowExecutor.cc | 4 ++-- runtimes/neurun/core/src/exec/DataflowExecutor.h | 6 ++---- runtimes/neurun/core/src/exec/Executor.h | 7 +++---- runtimes/neurun/core/src/exec/ExecutorBase.cc | 4 +++- runtimes/neurun/core/src/exec/ExecutorBase.h | 3 +++ 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/runtimes/neurun/core/src/compiler/Compiler.cc b/runtimes/neurun/core/src/compiler/Compiler.cc index a7a9d58..e8814c8 100644 --- a/runtimes/neurun/core/src/compiler/Compiler.cc +++ b/runtimes/neurun/core/src/compiler/Compiler.cc @@ -141,8 +141,9 @@ std::shared_ptr Compiler::createLinearExecutor(graph::Graph &mo ConstantInitializer{model, *operand_context, *linear->getLowerInfo()}(); auto plan = std::make_shared(operation_sequence); - return std::make_shared(model.shareModel(), linear->releaseSubgraphSet(), - linear->releaseLowerInfo(), operand_context, plan); + return std::make_shared(model.shareModel(), operand_context, + linear->releaseSubgraphSet(), linear->releaseLowerInfo(), + plan); } std::shared_ptr Compiler::createDataflowExecutor(graph::Graph &model) @@ -229,8 +230,8 @@ std::shared_ptr Compiler::createDataflowExecutor(graph::Graph & ConstantInitializer{model, *operand_context, *lower_info}(); - return std::make_shared(model.shareModel(), std::move(lower_info), - operand_context, + return std::make_shared(model.shareModel(), operand_context, + std::move(lower_info), std::move(execution_builder.releaseCodeMap())); } diff --git a/runtimes/neurun/core/src/exec/DataflowExecutor.cc b/runtimes/neurun/core/src/exec/DataflowExecutor.cc index 356ec6a..85ad420 100644 --- a/runtimes/neurun/core/src/exec/DataflowExecutor.cc +++ b/runtimes/neurun/core/src/exec/DataflowExecutor.cc @@ -47,10 +47,10 @@ void DataflowExecutor::notify(const model::operand::IndexSet &operands) } DataflowExecutor::DataflowExecutor(const std::shared_ptr &model, - std::unique_ptr lower_info, const std::shared_ptr &operand_context, + std::unique_ptr lower_info, CodeMap &&code_map) - : ExecutorBase{model, nullptr, std::move(lower_info)}, _operand_context{operand_context}, + : ExecutorBase{model, operand_context, nullptr, std::move(lower_info)}, _code_map{std::move(code_map)} { VERBOSE(DataflowExecutor) << "Constructing Dataflow Executor" << std::endl; diff --git a/runtimes/neurun/core/src/exec/DataflowExecutor.h b/runtimes/neurun/core/src/exec/DataflowExecutor.h index f9a76f3..b47b145 100644 --- a/runtimes/neurun/core/src/exec/DataflowExecutor.h +++ b/runtimes/neurun/core/src/exec/DataflowExecutor.h @@ -47,19 +47,17 @@ public: * @brief Constructs a DataflowExecutor object * * @param model Model object - * @param lower_info LowerInfo object (Only to know input/output operands layout) * @param operand_context (Only for input/output operand data access) + * @param lower_info LowerInfo object (Only to know input/output operands layout) * @param code_map Compiled code map */ DataflowExecutor(const std::shared_ptr &model, - std::unique_ptr lower_info, const std::shared_ptr &operand_context, - CodeMap &&code_map); + std::unique_ptr lower_info, CodeMap &&code_map); void execute() override; private: - std::shared_ptr _operand_context; CodeMap _code_map; model::operand::IndexSet _initially_ready_operands; std::list> _finished_jobs; diff --git a/runtimes/neurun/core/src/exec/Executor.h b/runtimes/neurun/core/src/exec/Executor.h index d9cf1f2..12078d8 100644 --- a/runtimes/neurun/core/src/exec/Executor.h +++ b/runtimes/neurun/core/src/exec/Executor.h @@ -41,12 +41,12 @@ public: * @param[in] plan Execution plan generated by compiled result */ Executor(const std::shared_ptr &model, + const std::shared_ptr &operand_context, std::unique_ptr>> subg_set, std::unique_ptr lower_info, - const std::shared_ptr &operand_context, const std::shared_ptr &plan) - : ExecutorBase{model, std::move(subg_set), std::move(lower_info)}, - _operand_context{operand_context}, _plan{plan} + : ExecutorBase{model, operand_context, std::move(subg_set), std::move(lower_info)}, + _plan{plan} { } @@ -54,7 +54,6 @@ public: virtual void execute(void) override; private: - std::shared_ptr _operand_context; std::shared_ptr _plan; }; diff --git a/runtimes/neurun/core/src/exec/ExecutorBase.cc b/runtimes/neurun/core/src/exec/ExecutorBase.cc index 9c18a83..d3cf0ea 100644 --- a/runtimes/neurun/core/src/exec/ExecutorBase.cc +++ b/runtimes/neurun/core/src/exec/ExecutorBase.cc @@ -23,9 +23,11 @@ namespace exec ExecutorBase::ExecutorBase( const std::shared_ptr &model, + const std::shared_ptr &operand_context, std::unique_ptr>> subg_set, std::unique_ptr lower_info) - : _model{model}, _subg_set{std::move(subg_set)}, _lower_info{std::move(lower_info)} + : _model{model}, _operand_context{operand_context}, _subg_set{std::move(subg_set)}, + _lower_info{std::move(lower_info)} { _sources.resize(_model->inputs.size()); _sinks.resize(_model->outputs.size()); diff --git a/runtimes/neurun/core/src/exec/ExecutorBase.h b/runtimes/neurun/core/src/exec/ExecutorBase.h index 8d4be6f..a427c31 100644 --- a/runtimes/neurun/core/src/exec/ExecutorBase.h +++ b/runtimes/neurun/core/src/exec/ExecutorBase.h @@ -26,6 +26,7 @@ #include "model/operand/Info.h" #include "model/operation/Subgraph.h" #include "backend/Backend.h" +#include "compiler/OperandContext.h" namespace neurun { @@ -36,6 +37,7 @@ class ExecutorBase : public IExecutor { public: ExecutorBase(const std::shared_ptr &model, + const std::shared_ptr &operand_context, std::unique_ptr>> subg_set, std::unique_ptr lower_info); @@ -115,6 +117,7 @@ private: protected: std::shared_ptr _model; + std::shared_ptr _operand_context; std::unique_ptr>> _subg_set; std::unique_ptr _lower_info; std::vector> _sources; -- 2.7.4