[neurun] Rename "make_subgraph" helper (#6042)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 31 Jul 2019 06:19:51 +0000 (15:19 +0900)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 31 Jul 2019 06:19:51 +0000 (15:19 +0900)
Graph::lower internally declares "make_subgraph", but its role is more
than subgraph construction.

This commit renames "make_subgraph" as "append_fresh_single_op_subgraph"
to make it easy to understand its behavior.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
runtimes/neurun/core/src/graph/Graph.cc

index ae25686..ee4cbe5 100644 (file)
@@ -177,13 +177,20 @@ void Graph::lower(void)
       return false;
     };
 
-    auto make_subgraph = [&](const model::OperationIndex &node_index, const model::Operation &node,
-                             model::Layout layout) {
-      auto subg_index = _subgraphs->emplace(node_index, node, layout);
-      auto &subg = _subgraphs->at(subg_index);
-      subg.setOutputs(node.getOutputs());
-      subg.setInputs(node.getInputs());
-      return subg_index;
+    // Create a fresh subgraph with one operation, and append it to subgraphs
+    auto append_fresh_single_op_subgraph = [&](const model::OperationIndex &node_index,
+                                               const model::Operation &node, model::Layout layout) {
+      // Create a fresh subgraph
+      auto subg = nnfw::cpp14::make_unique<model::Subgraph>(layout);
+
+      // Add an operation
+      subg->appendOperation(node_index, node);
+
+      // Update input/output
+      subg->setOutputs(node.getOutputs());
+      subg->setInputs(node.getInputs());
+
+      return _subgraphs->emplace(std::move(subg));
     };
 
     model::Subgraph *subg = nullptr;
@@ -229,7 +236,7 @@ void Graph::lower(void)
           if (!subg || is_profiling || !mergeable(subg_index, node_index))
           {
             // TODO Determines how to set the layout of the subgraph
-            auto new_subg_index = make_subgraph(node_index, node, layout);
+            auto new_subg_index = append_fresh_single_op_subgraph(node_index, node, layout);
 
             // Subgraph LowerInfo
             setLowerInfo(new_subg_index,