| 269 | } |
| 270 | |
| 271 | std::vector<std::vector<std::string>> |
| 272 | Optimizer::ProduceSplitOpInfo( |
| 273 | const std::vector<int32_t>& subset, DAGDef* dag, |
| 274 | std::unordered_map<std::string, int32_t>* op_key_input2split_info_idx) { |
| 275 | std::unordered_map<std::string, int32_t> op_inputidx2fusion_input_idx; |
| 276 | std::unordered_set<int32_t> set(subset.begin(), subset.end()); |
| 277 | std::vector<std::vector<std::string>> results; |
| 278 | int32_t fusion_input_cnt = 0; |
| 279 | for (int32_t id : subset) { |
| 280 | std::shared_ptr<NodeDef> node_def = dag->GetNodeById(id); |
| 281 | std::string op_name = node_def->name_; |
| 282 | int32_t node_id = node_def->id_; |
| 283 | int32_t input_idx = 0; |
| 284 | for (EdgeDef& input : node_def->input_edges_) { |
| 285 | if (set.find(input.src_id_) == set.end()) { // outside input |
| 286 | op_inputidx2fusion_input_idx[ |
| 287 | ToString(op_name, ",", node_id, ":", input_idx)] = |
| 288 | fusion_input_cnt++; |
| 289 | } |
| 290 | ++input_idx; |
| 291 | } |
| 292 | } |
| 293 | for (int32_t id : subset) { |
| 294 | std::shared_ptr<NodeDef> node_def = dag->GetNodeById(id); |
| 295 | std::string op_name = node_def->name_; |
| 296 | int32_t node_id = node_def->id_; |
| 297 | int32_t input_idx = 0; |
| 298 | for (EdgeDef& input : node_def->input_edges_) { |
| 299 | if (set.find(input.src_id_) == set.end()) { // outside input |
| 300 | std::string split_op_info = |
| 301 | graph_part_mode_split_map_[ToString(op_name, ":", input_idx)]; |
| 302 | if (split_op_info.empty()) { |
| 303 | EULER_LOG(FATAL) << op_name << ":" << input_idx << " split op error"; |
| 304 | } |
| 305 | std::vector<std::string> split_op_and_inputs = |
| 306 | Split(split_op_info, ':'); |
| 307 | std::string split_op_name = split_op_and_inputs[0]; |
| 308 | std::vector<std::string> inputs = |
| 309 | Split(split_op_and_inputs[1], ','); |
| 310 | std::vector<std::string> fusion_inputs; |
| 311 | for (std::string& input : inputs) { |
| 312 | fusion_inputs.push_back( |
| 313 | ToString(op_inputidx2fusion_input_idx[ |
| 314 | ToString(op_name, ",", node_id, ":", input)])); |
| 315 | } |
| 316 | results.push_back({split_op_name, Join(fusion_inputs, ",")}); |
| 317 | (*op_key_input2split_info_idx)[ |
| 318 | ToString(op_name, ",", node_id, ":", input_idx)] = |
| 319 | results.size() - 1; |
| 320 | } |
| 321 | ++input_idx; |
| 322 | } |
| 323 | } |
| 324 | return results; |
| 325 | } |
| 326 | |
| 327 | std::vector<std::string> Optimizer::GetMergeOpInfo( |
| 328 | const std::string& op_name, int32_t output_idx, |