| 310 | } |
| 311 | |
| 312 | bool OptimizerFusionImpl::Optimize() { |
| 313 | bool changed = false; |
| 314 | // TODO(minmin) check Template consistency before really optimizing |
| 315 | for (Node* node : g_->nodes()) { |
| 316 | if (node->type_string() == temp_node_map_[t_->first_key_].op) { |
| 317 | matched_node_map_.clear(); |
| 318 | t_->node_to_temp_key_.clear(); |
| 319 | fused_op_deps_inputs_.clear(); |
| 320 | fused_op_input_dynamic_.clear(); |
| 321 | fused_op_outputs_dynamic_.clear(); |
| 322 | fused_op_inputs_.resize(t_->num_inputs_); |
| 323 | fused_op_outputs_.resize(t_->num_outputs_); |
| 324 | for (int i = 0; i < fused_op_inputs_.size(); ++i) { |
| 325 | fused_op_inputs_[i] = nullptr; |
| 326 | } |
| 327 | for (int i = 0; i < fused_op_outputs_.size(); ++i) { |
| 328 | fused_op_outputs_[i].clear(); |
| 329 | } |
| 330 | VLOG(2) << "try to match: " << t_->name() << " " << node->name(); |
| 331 | VLOG(2) << "First Matched: " << node->name() |
| 332 | << ", t->first_key:" << t_->first_key_ |
| 333 | << ", t->first_value:" << temp_node_map_[t_->first_key_].key; |
| 334 | // check dynamic inputs |
| 335 | auto search_itr = |
| 336 | t_->nodes_dynamic_iedges_.find(temp_node_map_[t_->first_key_].key); |
| 337 | if (search_itr != t_->nodes_dynamic_iedges_.end()) { |
| 338 | if (!t_->CheckDynamicInputs(node, &temp_node_map_[t_->first_key_], |
| 339 | search_itr->second, fused_op_inputs_, temp_node_map_, |
| 340 | matched_node_map_)) { |
| 341 | continue; |
| 342 | } |
| 343 | } else { |
| 344 | if (!CheckInputs(node, &temp_node_map_[t_->first_key_])) { |
| 345 | continue; |
| 346 | } |
| 347 | } |
| 348 | // check dynamic outputs |
| 349 | search_itr = |
| 350 | t_->nodes_dynamic_oedges_.find(temp_node_map_[t_->first_key_].key); |
| 351 | if (search_itr != t_->nodes_dynamic_oedges_.end()) { |
| 352 | if (!t_->CheckDynamicOutputs(node, &temp_node_map_[t_->first_key_], |
| 353 | search_itr->second, fused_op_outputs_, temp_node_map_, |
| 354 | matched_node_map_)) { |
| 355 | continue; |
| 356 | } |
| 357 | } else { |
| 358 | if (!CheckOutputs(node, &temp_node_map_[t_->first_key_])) { |
| 359 | continue; |
| 360 | } |
| 361 | } |
| 362 | MatchedNode matched_node(node, true); |
| 363 | matched_node_map_.insert( |
| 364 | std::make_pair(t_->first_key_, matched_node)); |
| 365 | if (!VisitMatchedNodes()) { |
| 366 | VLOG(2) << "VisitMatchedNodes failed"; |
| 367 | continue; |
| 368 | } |
| 369 | // double check the matched nodes |
nothing calls this directly
no test coverage detected