Move Subgraph and SubgraphContext to upper dir (#5143)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Tue, 7 May 2019 09:29:19 +0000 (18:29 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 7 May 2019 09:29:19 +0000 (18:29 +0900)
Move Subgraph and SubgraphContext from `model::operation::` to
`model::`.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
20 files changed:
runtimes/neurun/core/include/backend/IStageGenerator.h
runtimes/neurun/core/include/graph/Graph.h
runtimes/neurun/core/include/model/OperationVisitor.h
runtimes/neurun/core/include/model/Subgraph.h [moved from runtimes/neurun/core/include/model/operation/Subgraph.h with 88% similarity]
runtimes/neurun/core/include/model/SubgraphContext.h [moved from runtimes/neurun/core/include/model/operation/SubgraphContext.h with 89% similarity]
runtimes/neurun/core/src/compiler/Compiler.cc
runtimes/neurun/core/src/dumper/dot/DotDumper.cc
runtimes/neurun/core/src/dumper/dot/DotSubgraphInfo.cc
runtimes/neurun/core/src/dumper/dot/DotSubgraphInfo.h
runtimes/neurun/core/src/exec/DataflowExecutor.cc
runtimes/neurun/core/src/exec/DataflowExecutor.h
runtimes/neurun/core/src/exec/ExecutorBase.cc
runtimes/neurun/core/src/exec/ExecutorBase.h
runtimes/neurun/core/src/exec/LinearExecutor.h
runtimes/neurun/core/src/graph/Graph.cc
runtimes/neurun/core/src/linear/Element.h
runtimes/neurun/core/src/linear/Linear.cc
runtimes/neurun/core/src/linear/Linear.h
runtimes/neurun/core/src/model/Subgraph.cc [moved from runtimes/neurun/core/src/model/operation/Subgraph.cc with 94% similarity]
runtimes/neurun/core/src/model/SubgraphContext.cc [moved from runtimes/neurun/core/src/model/operation/SubgraphContext.cc with 93% similarity]

index 1834f0f..d266ff4 100644 (file)
@@ -23,7 +23,7 @@
 #include "ITensorBuilder.h"
 #include "IStage.h"
 #include "model/OperationVisitor.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
 #include "cpp14/memory.h"
 
 // TODO Remove dependencies for below header. Should include only interface.
index ddf461a..deec840 100644 (file)
@@ -22,8 +22,8 @@
 #include "model/Operation.h"
 #include "model/Model.h"
 #include "graph/LowerInfoMap.h"
-#include "model/operation/Subgraph.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/Subgraph.h"
+#include "model/SubgraphContext.h"
 
 namespace neurun
 {
@@ -126,10 +126,7 @@ public:
   bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; }
   std::shared_ptr<const model::Model> shareModel() { return _model; }
   std::unique_ptr<graph::LowerInfoMap> releaseLowerInfo() { return std::move(_lower_info_map); }
-  std::unique_ptr<model::operation::SubgraphContext> releaseSubgraphContext()
-  {
-    return std::move(_subg_ctx);
-  }
+  std::unique_ptr<model::SubgraphContext> releaseSubgraphContext() { return std::move(_subg_ctx); }
 
 private:
   void initializeUseDef();
@@ -159,18 +156,18 @@ public:
   operand::LowerInfo *getLowerInfo(const model::OperandIndex &index);
   void setLowerInfo(const model::OperandIndex &index,
                     std::unique_ptr<operand::LowerInfo> &&lower_info);
-  model::operation::SubgraphContext &subg_ctx()
+  model::SubgraphContext &subg_ctx()
   {
     assert(_subg_ctx);
     return *_subg_ctx;
   }
-  const model::operation::SubgraphContext *subg_ctx() const { return _subg_ctx.get(); }
+  const model::SubgraphContext *subg_ctx() const { return _subg_ctx.get(); }
 
 private:
   std::unique_ptr<compiler::BackendResolver> _backend_resolver;
   std::unique_ptr<LowerInfoMap> _lower_info_map;
   // Pass(for Perm) can accept only graph so that Graph has SubgraphContext as a member
-  std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+  std::unique_ptr<model::SubgraphContext> _subg_ctx;
 };
 
 } // namespace graph
index 64863c0..f9f7d3f 100644 (file)
@@ -18,7 +18,7 @@
 #define __NEURUN_MODEL_OPERATION_VISITOR_H__
 
 #include "Operations.Include.h"
-#include "operation/Subgraph.h"
+#include "Subgraph.h"
 
 namespace neurun
 {
@@ -36,7 +36,7 @@ struct OperationVisitor
 
   // This Subgraph node should be handled specially so that
   // Op.lst doesn't have Subgraph
-  virtual void visit(const operation::Subgraph &subgraph)
+  virtual void visit(const Subgraph &subgraph)
   {
     for (const auto &e : subgraph.operations())
     {
  * limitations under the License.
  */
 
-#ifndef __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
-#define __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
+#ifndef __NEURUN_MODEL_SUBGRAPH_H__
+#define __NEURUN_MODEL_SUBGRAPH_H__
 
 #include <vector>
 #include <string>
 #include <memory>
 
-#include "model/Index.h"
-#include "model/Operation.h"
+#include "Index.h"
+#include "Operation.h"
 
 namespace neurun
 {
 namespace model
 {
-namespace operation
-{
 
 // To support ValueSwappable, Element doesn't have members which are classes
 // as value(or can have members which are classes as value and the classes
@@ -75,8 +73,7 @@ private:
   std::vector<Element> _operations;
 };
 
-} // namespace operation
 } // namespace model
 } // namespace neurun
 
-#endif // __NEURUN_MODEL_OPERATION_SUBGRAPH_H__
+#endif // __NEURUN_MODEL_SUBGRAPH_H__
  * limitations under the License.
  */
 
-#ifndef __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
-#define __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
+#ifndef __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
+#define __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
 
 #include <memory>
 
 #include "Subgraph.h"
-#include "model/Index.h"
+#include "Index.h"
 
 #include <unordered_map>
 
@@ -28,8 +28,6 @@ namespace neurun
 {
 namespace model
 {
-namespace operation
-{
 
 class SubgraphContext
 {
@@ -72,8 +70,7 @@ private:
   uint32_t _index_count;
 };
 
-} // namespace operation
 } // namespace model
 } // namespace neurun
 
-#endif // __NEURUN_MODEL_OPERATION_SUBGRAPH_CONTEXT_H__
+#endif // __NEURUN_MODEL_SUBGRAPH_CONTEXT_H__
index 8f78c2a..8db086a 100644 (file)
@@ -152,7 +152,7 @@ std::shared_ptr<exec::IExecutor> Compiler::createDataflowExecutor(graph::Graph &
   std::unordered_map<model::SubgraphIndex, std::unique_ptr<backend::IStage>> stages;
 
   model.subg_ctx().iterate(
-      [&](const model::SubgraphIndex &subg_index, const model::operation::Subgraph &subg) {
+      [&](const model::SubgraphIndex &subg_index, const model::Subgraph &subg) {
         auto backend = model.getLowerInfo(subg_index)->backend();
 
         // Generate Stage
index db57962..42015a2 100644 (file)
@@ -19,7 +19,7 @@
 #include "DotDumper.h"
 #include "DotBuilder.h"
 #include "DotSubgraphInfo.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
 
 namespace neurun
 {
@@ -98,11 +98,10 @@ void DotDumper::dumpIfNeeded(const std::string &tag)
   const auto subg_ctx = _graph.subg_ctx();
   if (subg_ctx)
   {
-    subg_ctx->iterate(
-        [&](const model::SubgraphIndex &index, const model::operation::Subgraph &subgraph) {
-          DotSubgraphInfo subgraph_info{index, subgraph};
-          dot_builder.addSubgraph(subgraph_info);
-        });
+    subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::Subgraph &subgraph) {
+      DotSubgraphInfo subgraph_info{index, subgraph};
+      dot_builder.addSubgraph(subgraph_info);
+    });
   }
 
   // Dump to file
index 6f64dca..dd6fda4 100644 (file)
@@ -25,8 +25,7 @@ namespace dumper
 namespace dot
 {
 
-DotSubgraphInfo::DotSubgraphInfo(const model::SubgraphIndex &index,
-                                 const model::operation::Subgraph &subgraph)
+DotSubgraphInfo::DotSubgraphInfo(const model::SubgraphIndex &index, const model::Subgraph &subgraph)
     : _index{index}
 {
   for (const auto &element : subgraph.operations())
index 4aa409d..ae1d274 100644 (file)
@@ -20,7 +20,7 @@
 #include <unordered_set>
 
 #include "model/Index.h"
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
 
 namespace neurun
 {
@@ -32,7 +32,7 @@ namespace dot
 class DotSubgraphInfo
 {
 public:
-  DotSubgraphInfo(const model::SubgraphIndex &index, const model::operation::Subgraph &subgraph);
+  DotSubgraphInfo(const model::SubgraphIndex &index, const model::Subgraph &subgraph);
 
   std::string index_str() const;
   const std::unordered_set<model::OperationIndex> &operations() const { return _operations; }
index 8dae120..04f98ff 100644 (file)
@@ -47,7 +47,7 @@ void DataflowExecutor::notify(const model::OperandIndexSequence &operands)
 }
 
 DataflowExecutor::DataflowExecutor(const std::shared_ptr<const model::Model> &model,
-                                   std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+                                   std::unique_ptr<model::SubgraphContext> subg_ctx,
                                    const std::shared_ptr<compiler::OperandContext> &operand_context,
                                    std::unique_ptr<graph::LowerInfoMap> lower_info,
                                    CodeMap &&code_map)
@@ -59,13 +59,12 @@ DataflowExecutor::DataflowExecutor(const std::shared_ptr<const model::Model> &mo
   assert(_subg_ctx);
 
   // Create jobs
-  _subg_ctx->iterate(
-      [&](const model::SubgraphIndex &subg_index, const model::operation::Subgraph &subg) {
-        VERBOSE(DataflowExecutor) << "Add a job #" << subg_index.value() << std::endl;
-        _finished_jobs.emplace_back(nnfw::cpp14::make_unique<Job>(
-            subg_index, _code_map.at(subg_index).get(),
-            _lower_info->operation.at(subg_index)->backend(), subg.getInputs(), subg.getOutputs()));
-      });
+  _subg_ctx->iterate([&](const model::SubgraphIndex &subg_index, const model::Subgraph &subg) {
+    VERBOSE(DataflowExecutor) << "Add a job #" << subg_index.value() << std::endl;
+    _finished_jobs.emplace_back(nnfw::cpp14::make_unique<Job>(
+        subg_index, _code_map.at(subg_index).get(),
+        _lower_info->operation.at(subg_index)->backend(), subg.getInputs(), subg.getOutputs()));
+  });
 
   // Save operands that are initially ready
   {
index 64a8e6d..83ec7b4 100644 (file)
@@ -52,7 +52,7 @@ public:
    * @param code_map Compiled code map
    */
   DataflowExecutor(const std::shared_ptr<const model::Model> &model,
-                   std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+                   std::unique_ptr<model::SubgraphContext> subg_ctx,
                    const std::shared_ptr<compiler::OperandContext> &operand_context,
                    std::unique_ptr<graph::LowerInfoMap> lower_info, CodeMap &&code_map);
 
index 8b1aa94..7481419 100644 (file)
@@ -22,7 +22,7 @@ namespace exec
 {
 
 ExecutorBase::ExecutorBase(const std::shared_ptr<const model::Model> &model,
-                           std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+                           std::unique_ptr<model::SubgraphContext> subg_ctx,
                            const std::shared_ptr<compiler::OperandContext> &operand_context,
                            std::unique_ptr<graph::LowerInfoMap> lower_info)
     : _model{model}, _subg_ctx{std::move(subg_ctx)}, _operand_context{operand_context},
index ff24e7e..7c907d7 100644 (file)
@@ -26,7 +26,7 @@
 #include "model/OperandInfo.h"
 #include "backend/Backend.h"
 #include "compiler/OperandContext.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
 
 namespace neurun
 {
@@ -37,7 +37,7 @@ class ExecutorBase : public IExecutor
 {
 public:
   ExecutorBase(const std::shared_ptr<const model::Model> &model,
-               std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+               std::unique_ptr<model::SubgraphContext> subg_ctx,
                const std::shared_ptr<compiler::OperandContext> &operand_context,
                std::unique_ptr<graph::LowerInfoMap> lower_info);
 
@@ -118,7 +118,7 @@ private:
 
 protected:
   std::shared_ptr<const model::Model> _model;
-  std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+  std::unique_ptr<model::SubgraphContext> _subg_ctx;
   std::shared_ptr<compiler::OperandContext> _operand_context;
   std::unique_ptr<graph::LowerInfoMap> _lower_info;
   std::vector<std::unique_ptr<ISource>> _sources;
index 44e5fa6..bc60424 100644 (file)
@@ -43,7 +43,7 @@ public:
    * @param[in] plan  Execution plan generated by compiled result
    */
   LinearExecutor(const std::shared_ptr<const model::Model> &model,
-                 std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+                 std::unique_ptr<model::SubgraphContext> subg_ctx,
                  const std::shared_ptr<compiler::OperandContext> &operand_context,
                  std::unique_ptr<graph::LowerInfoMap> lower_info,
                  std::unique_ptr<std::vector<linear::Element>> elements,
index f0e5b44..63325e9 100644 (file)
@@ -92,7 +92,7 @@ void Graph::lower(void)
 {
   assert(_phase == Phase::MODEL);
 
-  _subg_ctx = nnfw::cpp14::make_unique<model::operation::SubgraphContext>();
+  _subg_ctx = nnfw::cpp14::make_unique<model::SubgraphContext>();
 
   // Lower
   {
@@ -133,7 +133,7 @@ void Graph::lower(void)
         const auto &node_outputs = node.getOutputs();
 
         // subg's operations are in order so that we just check the first and the last
-        std::vector<model::operation::Element> subg_ops{subg.operations()[0]};
+        std::vector<model::Element> subg_ops{subg.operations()[0]};
         if (subg.operations().size() > 1)
           subg_ops.emplace_back(subg.operations()[subg.operations().size() - 1]);
 
@@ -185,7 +185,7 @@ void Graph::lower(void)
       return subg_index;
     };
 
-    model::operation::Subgraph *subg = nullptr;
+    model::Subgraph *subg = nullptr;
     model::SubgraphIndex subg_index;
 
     // Make subgraphs while checking whether a node can be merged into a subgraph.
@@ -280,7 +280,7 @@ void Graph::lower(void)
             subg = nullptr;
         });
 
-    _subg_ctx->iterate([&](const model::SubgraphIndex &, model::operation::Subgraph &subg) {
+    _subg_ctx->iterate([&](const model::SubgraphIndex &, model::Subgraph &subg) {
       assert(subg.operations().size() > 0);
       std::reverse(std::begin(subg.operations()), std::end(subg.operations()));
     });
index c605a0f..03a6999 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __NEURUN_LINEAR_ELEMENT_H__
 #define __NEURUN_LINEAR_ELEMENT_H__
 
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
 #include "graph/LowerInfoMap.h"
 
 namespace neurun
@@ -27,10 +27,10 @@ namespace linear
 
 struct Element
 {
-  const model::operation::Subgraph *subgraph;
+  const model::Subgraph *subgraph;
   const graph::operation::LowerInfo *lower_info;
 
-  Element(const model::operation::Subgraph *subgraph, const graph::operation::LowerInfo *lower_info)
+  Element(const model::Subgraph *subgraph, const graph::operation::LowerInfo *lower_info)
       : subgraph{subgraph}, lower_info{lower_info}
   {
     // DO NOTHING
index eccdc52..5dbcdb2 100644 (file)
@@ -35,7 +35,7 @@ namespace linear
 {
 
 Linear::Linear(const std::shared_ptr<const model::Model> &model,
-               std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+               std::unique_ptr<model::SubgraphContext> subg_ctx,
                std::unique_ptr<graph::LowerInfoMap> lower_info_map)
     : _model(model), _subg_ctx{std::move(subg_ctx)}, _lower_info_map{std::move(lower_info_map)}
 {
@@ -63,7 +63,7 @@ Linear::Linear(const std::shared_ptr<const model::Model> &model,
     //       [SUBG3]
     //         |
     //        [4]
-    _subg_ctx->iterate([&](const model::SubgraphIndex &subg_idx, model::operation::Subgraph &subg) {
+    _subg_ctx->iterate([&](const model::SubgraphIndex &subg_idx, model::Subgraph &subg) {
       for (auto input : subg.getInputs())
       {
         // only valid_inputs
@@ -85,12 +85,12 @@ Linear::Linear(const std::shared_ptr<const model::Model> &model,
     });
 
     std::unordered_map<model::SubgraphIndex, bool> visited;
-    _subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::operation::Subgraph &) {
+    _subg_ctx->iterate([&](const model::SubgraphIndex &index, const model::Subgraph &) {
       visited[index] = false;
     });
 
-    std::function<void(const model::SubgraphIndex &, model::operation::Subgraph &)> dfs_recursive =
-        [&](const model::SubgraphIndex &index, model::operation::Subgraph &subg) -> void {
+    std::function<void(const model::SubgraphIndex &, model::Subgraph &)> dfs_recursive =
+        [&](const model::SubgraphIndex &index, model::Subgraph &subg) -> void {
       if (visited[index])
         return;
       visited[index] = true;
index 15d4c46..ceb784f 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "Element.h"
 #include "model/Model.h"
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
 #include "backend/ITensorBuilder.h"
 #include "graph/LowerInfoMap.h"
 
@@ -46,7 +46,7 @@ class Linear
 {
 public:
   Linear(const std::shared_ptr<const model::Model> &model,
-         std::unique_ptr<model::operation::SubgraphContext> subg_ctx,
+         std::unique_ptr<model::SubgraphContext> subg_ctx,
          std::unique_ptr<graph::LowerInfoMap> lower_info_map);
 
 public:
@@ -63,10 +63,7 @@ public:
   std::unique_ptr<graph::LowerInfoMap> releaseLowerInfo() { return std::move(_lower_info_map); }
   graph::LowerInfoMap *getLowerInfo() { return _lower_info_map.get(); }
 
-  std::unique_ptr<model::operation::SubgraphContext> releaseSubgraphContext()
-  {
-    return std::move(_subg_ctx);
-  }
+  std::unique_ptr<model::SubgraphContext> releaseSubgraphContext() { return std::move(_subg_ctx); }
 
   std::unique_ptr<std::vector<Element>> releaseElements() { return std::move(_elements); }
 
@@ -77,7 +74,7 @@ private:
 
 private:
   std::shared_ptr<const model::Model> _model;
-  std::unique_ptr<model::operation::SubgraphContext> _subg_ctx;
+  std::unique_ptr<model::SubgraphContext> _subg_ctx;
   std::unique_ptr<graph::LowerInfoMap> _lower_info_map;
   std::unique_ptr<std::vector<Element>> _elements;
 };
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "model/operation/Subgraph.h"
+#include "model/Subgraph.h"
 #include "model/OperationVisitor.h"
 #include <sstream>
 
@@ -22,8 +22,6 @@ namespace neurun
 {
 namespace model
 {
-namespace operation
-{
 
 Subgraph::Subgraph() : Operation{OperandConstraint::createAny()}
 {
@@ -56,6 +54,5 @@ std::string Subgraph::getStr() const
   return ss.str();
 }
 
-} // namespace operation
 } // namespace model
 } // neurun
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "model/operation/SubgraphContext.h"
+#include "model/SubgraphContext.h"
 #include "util/logging.h"
 #include "cpp14/memory.h"
 
@@ -26,8 +26,6 @@ namespace neurun
 {
 namespace model
 {
-namespace operation
-{
 
 SubgraphIndex SubgraphContext::generateIndex()
 {
@@ -45,7 +43,7 @@ SubgraphIndex SubgraphContext::append(std::unique_ptr<Subgraph> &&subgraph)
 
 SubgraphIndex SubgraphContext::append(const OperationIndex &index, const Operation &node)
 {
-  std::unique_ptr<Subgraph> subg = nnfw::cpp14::make_unique<model::operation::Subgraph>();
+  std::unique_ptr<Subgraph> subg = nnfw::cpp14::make_unique<model::Subgraph>();
   subg->appendOperation(index, node);
   return append(std::move(subg));
 }
@@ -117,11 +115,10 @@ void SubgraphContext::iterate(const std::function<void(const SubgraphIndex &, Su
 void SubgraphContext::dump(const std::string &msg) const
 {
   VERBOSE(SubgraphContext) << "SubgraphContext(" << msg << ")" << std::endl;
-  iterate([&](const SubgraphIndex &idx, const model::operation::Subgraph &subg) {
+  iterate([&](const SubgraphIndex &idx, const model::Subgraph &subg) {
     VERBOSE(SubgraphContext) << idx.value() << "] " << subg.getStr() << std::endl;
   });
 }
 
-} // namespace operation
 } // namespace model
 } // namespace neurun