[neurun] Fix Concat Elimination was not working (#4538)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 4 Mar 2019 02:00:30 +0000 (11:00 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 4 Mar 2019 02:00:30 +0000 (11:00 +0900)
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 <hanjoung.lee@samsung.com>
runtimes/neurun/src/backend/interface/IStageGenerator.h
runtimes/neurun/src/compiler/Compiler.cc
runtimes/neurun/src/compiler/SubTensorAnalyzer.cc
runtimes/neurun/src/compiler/SubTensorAnalyzer.h
runtimes/neurun/src/model/operation/NodeVisitor.h

index fbc03a3..1935676 100644 (file)
@@ -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)
index 73f8fa5..a2b5020 100644 (file)
@@ -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
index 4fd3e24..9084add 100644 (file)
@@ -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<int32_t> offset = {0, 0, 0, 0};
index 689703a..73253c1 100644 (file)
@@ -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
index 5a4ce23..a68a4dd 100644 (file)
@@ -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