[graph_core] Implement input_list, output_list for multi input, output
authorhyeonseok lee <hs89.lee@samsung.com>
Fri, 25 Jun 2021 06:39:53 +0000 (15:39 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 22 Jul 2021 11:47:24 +0000 (20:47 +0900)
- Make input_list, output_list and its getter to support multi input, output

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
nntrainer/graph/graph_core.h
nntrainer/graph/network_graph.cpp

index 261aa74..1c7f928 100644 (file)
@@ -206,6 +206,36 @@ public:
   void addLossToSorted();
 
   /**
+   * @brief   getter of graph input nodes with index number
+   * @param   idx
+   * @return  graph node of input node
+   */
+  const std::shared_ptr<GraphNode> &getInputNode(unsigned int idx) const {
+    return input_list[idx];
+  }
+
+  /**
+   * @brief   getter of number of input nodes
+   * @return  number of input nodes
+   */
+  unsigned int getNumInputNodes() const { return input_list.size(); }
+
+  /**
+   * @brief   getter of graph output nodes with index number
+   * @param   idx
+   * @return  graph node of output node
+   */
+  const std::shared_ptr<GraphNode> &getOutputNode(unsigned int idx) const {
+    return output_list[idx];
+  }
+
+  /**
+   * @brief   getter of number of output nodes
+   * @return  number of output nodes
+   */
+  unsigned int getNumOutputNodes() const { return output_list.size(); }
+
+  /**
    * @brief     Verify if the node exists
    */
   inline bool verifyNode(const std::string &name) {
@@ -215,6 +245,8 @@ public:
   }
 
 private:
+  std::vector<std::shared_ptr<GraphNode>> input_list;
+  std::vector<std::shared_ptr<GraphNode>> output_list;
   std::vector<std::shared_ptr<GraphNode>>
     node_list;                                    /**< Unordered Node List  */
   std::vector<std::shared_ptr<GraphNode>> Sorted; /**< Ordered Node List  */
index 2303b67..2405f22 100644 (file)
@@ -185,7 +185,7 @@ int NetworkGraph::realizeActivationType(
   in_node->setProperty({"activation=none"});
 
   lnode->setInputLayers({in_node->getName()});
-  /** output layers for layer aobj will be set in setOutputLayers() */
+  /** output layers for layer obj will be set in setOutputLayers() */
 
   updateConnectionName(in_node->getName(), lnode->getName());
   graph.addNode(lnode, false);
@@ -308,7 +308,6 @@ int NetworkGraph::addLossLayer(const std::string &loss_type) {
 
 void NetworkGraph::setOutputLayers() {
 
-  size_t last_layer_count = 0;
   for (auto iter_idx = cbegin(); iter_idx != cend(); iter_idx++) {
     auto &layer_idx = *iter_idx;
     for (auto iter_i = cbegin(); iter_i != cend(); iter_i++) {
@@ -332,15 +331,6 @@ void NetworkGraph::setOutputLayers() {
         }
       }
     }
-
-    if (layer_idx->getNumOutputConnections() == 0) {
-      last_layer_count += 1;
-    }
-  }
-
-  if (last_layer_count != 1) {
-    throw std::invalid_argument(
-      "Error: Multiple last layers in the model not supported");
   }
 }
 
@@ -439,6 +429,7 @@ int NetworkGraph::realizeGraph() {
     }
   }
   /// @todo add check that input_layers <-> output_layers does match.
+  /// @todo check whether graph has a cycle or graph is seperated to subgraph
 
   return status;
 }