From 7783a6cc9b0a6a72cfe95e975f51537bdc20ae10 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: Mon, 4 Mar 2019 11:00:30 +0900 Subject: [PATCH] [neurun] Fix Concat Elimination was not working (#4538) Implement default implementation for `NodeVisitor::visit(Subgraph)`. Remove override implementation of `IStageGenerator`. The default implementation is NOP so SubTensorAnalyzer was not working. SubTensorAnalyzer changes are necessary for this commit otherwise it crashes. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/backend/interface/IStageGenerator.h | 7 ------- runtimes/neurun/src/compiler/Compiler.cc | 2 +- runtimes/neurun/src/compiler/SubTensorAnalyzer.cc | 2 +- runtimes/neurun/src/compiler/SubTensorAnalyzer.h | 9 ++++++--- runtimes/neurun/src/model/operation/NodeVisitor.h | 11 ++++++++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/runtimes/neurun/src/backend/interface/IStageGenerator.h b/runtimes/neurun/src/backend/interface/IStageGenerator.h index fbc03a3..1935676 100644 --- a/runtimes/neurun/src/backend/interface/IStageGenerator.h +++ b/runtimes/neurun/src/backend/interface/IStageGenerator.h @@ -55,13 +55,6 @@ protected: virtual void visit(const model::operation::InternalName &) override {} #include "model/operation/Op.lst" #undef OP - virtual void visit(const model::operation::Subgraph &subgraph) final override - { - for (const auto &e : subgraph.operations()) - { - e.node->accept(std::move(*this)); - } - } protected: void returnStage(const StageFn fn) diff --git a/runtimes/neurun/src/compiler/Compiler.cc b/runtimes/neurun/src/compiler/Compiler.cc index 73f8fa5..a2b5020 100644 --- a/runtimes/neurun/src/compiler/Compiler.cc +++ b/runtimes/neurun/src/compiler/Compiler.cc @@ -86,7 +86,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{*_model}); + linear->accept(SubTensorAnalyzer{*linear->getLowerInfo(), _model->operands()}); /********************************************************** * Backend dependent analysis & optimization phase finished diff --git a/runtimes/neurun/src/compiler/SubTensorAnalyzer.cc b/runtimes/neurun/src/compiler/SubTensorAnalyzer.cc index 4fd3e24..9084add 100644 --- a/runtimes/neurun/src/compiler/SubTensorAnalyzer.cc +++ b/runtimes/neurun/src/compiler/SubTensorAnalyzer.cc @@ -59,7 +59,7 @@ void SubTensorAnalyzer::visit(const model::operation::ConcatNode &node) int32_t axis_point = 0; for (auto &input_index : inputs) { - auto lower_info = _graph.getLowerInfo(input_index); + auto lower_info = _lower_info.operand.at(input_index).get(); assert(lower_info != nullptr); auto input_shape_4D = lower_info->shape(); std::vector offset = {0, 0, 0, 0}; diff --git a/runtimes/neurun/src/compiler/SubTensorAnalyzer.h b/runtimes/neurun/src/compiler/SubTensorAnalyzer.h index 689703a..73253c1 100644 --- a/runtimes/neurun/src/compiler/SubTensorAnalyzer.h +++ b/runtimes/neurun/src/compiler/SubTensorAnalyzer.h @@ -52,14 +52,17 @@ public: * @brief Construct a new SubTensorAnalyzer object * @param[in] ctx Graph operand set */ - SubTensorAnalyzer(graph::Graph &graph) : _graph{graph}, _ctx{graph.operands()} {} + SubTensorAnalyzer(const graph::LowerInfoMap &lower_info, neurun::model::operand::Set &ctx) + : _lower_info{lower_info}, _ctx{ctx} + { + } public: virtual void visit(const model::operation::ConcatNode &) override; private: - const neurun::graph::Graph &_graph; - neurun::model::operand::Set &_ctx; + const graph::LowerInfoMap &_lower_info; + neurun::model::operand::Set &_ctx; // TODO Refactor : Do not update operand::Set }; } // namespace compiler diff --git a/runtimes/neurun/src/model/operation/NodeVisitor.h b/runtimes/neurun/src/model/operation/NodeVisitor.h index 5a4ce23..a68a4dd 100644 --- a/runtimes/neurun/src/model/operation/NodeVisitor.h +++ b/runtimes/neurun/src/model/operation/NodeVisitor.h @@ -18,6 +18,7 @@ #define __NEURUN_MODEL_OPERATION_NODE_VISITOR_H__ #include "Node.Include.h" +#include "Subgraph.h" namespace neurun { @@ -26,8 +27,6 @@ namespace model namespace operation { -class Subgraph; - struct NodeVisitor { virtual ~NodeVisitor() = default; @@ -39,7 +38,13 @@ struct NodeVisitor // This Subgraph node should be handled specially so that // Op.lst doesn't have Subgraph - virtual void visit(const Subgraph &) {} + virtual void visit(const Subgraph &subgraph) + { + for (const auto &e : subgraph.operations()) + { + e.node->accept(std::move(*this)); + } + } }; } // namespace operation -- 2.7.4