| 114 | } |
| 115 | |
| 116 | Graph* GraphTask::MergeSubgraph(Graph* origin_graph, const std::vector<Subgraph*>& sub_list) |
| 117 | { |
| 118 | std::string graph_name = origin_graph->GetName() + ".optimized"; |
| 119 | |
| 120 | Graph* graph = new Graph(graph_name); |
| 121 | int subgraph_number = sub_list.size(); |
| 122 | |
| 123 | /* first: search the graph input nodes and graph output nodes |
| 124 | and collect all nodes and tensors */ |
| 125 | |
| 126 | graph->input_nodes = origin_graph->input_nodes; |
| 127 | |
| 128 | for(int i = 0; i < subgraph_number; i++) |
| 129 | { |
| 130 | Subgraph* sub = sub_list[i]; |
| 131 | |
| 132 | graph->seq_nodes.insert(graph->seq_nodes.end(), sub->seq_nodes.begin(), sub->seq_nodes.end()); |
| 133 | |
| 134 | for(unsigned int k = 0; k < sub->output_nodes.size(); k++) |
| 135 | { |
| 136 | Node* node = sub->output_nodes[k]; |
| 137 | |
| 138 | unsigned int l; |
| 139 | |
| 140 | for(l = 0; l < node->GetOutputNum(); l++) |
| 141 | { |
| 142 | Tensor* tensor = node->GetOutputTensor(l); |
| 143 | |
| 144 | if(tensor->consumer.size() == 0) |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | if(l < node->GetOutputNum()) |
| 149 | graph->output_nodes.push_back(node); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /*second: setup the tensor map */ |
| 154 | |
| 155 | for(unsigned int i = 0; i < graph->seq_nodes.size(); i++) |
| 156 | { |
| 157 | Node* node = graph->seq_nodes[i]; |
| 158 | node->SetNodeIndex(i); |
| 159 | |
| 160 | for(unsigned int l = 0; l < node->GetOutputNum(); l++) |
| 161 | { |
| 162 | Tensor* tensor = node->GetOutputTensor(l); |
| 163 | graph->AddTensorMap(tensor->GetName(), tensor); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /*third: get the output nodes order*/ |
| 168 | |
| 169 | if(graph->output_nodes.size() > 1) |
| 170 | { |
| 171 | graph->output_nodes = origin_graph->output_nodes; |
| 172 | } |
| 173 |
nothing calls this directly
no test coverage detected