@@ -120,7 +120,10 @@ void TransferLayoutElimPass::PutTranferlayoutAfterOp(
120
120
auto *new_transfer_layout_node =
121
121
graph->CreateOpNode (&new_transfer_layout_desc);
122
122
123
- for (auto other_op : var2->outputs ) {
123
+ // must use a tmp variable var_out, because var2->outputs will be changed in
124
+ // loop.
125
+ auto var_out = var2->outputs ;
126
+ for (auto other_op : var_out) {
124
127
IR_NODE_UNLINK (var2, other_op);
125
128
other_op->Op ()->RenameInput (var2->Name (), var2_dot_name);
126
129
IR_NODE_LINK_TO (var2_dot, other_op);
@@ -244,6 +247,9 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
244
247
return " " ;
245
248
};
246
249
250
+ int move_down_count = 0 ;
251
+ int elim_count = 0 ;
252
+
247
253
while (true ) {
248
254
auto op_node_sorted = framework::ir::TopologyVarientSort (
249
255
*graph, static_cast <framework::ir::SortKind>(0 ));
@@ -309,6 +315,7 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
309
315
}
310
316
op_node->Op ()->SetAttr (" axis" , modify_axis);
311
317
modify = true ;
318
+ move_down_count++;
312
319
break ;
313
320
}
314
321
if (is_pool_like_op) {
@@ -318,21 +325,26 @@ void TransferLayoutElimPass::ApplyImpl(ir::Graph *graph) const {
318
325
transfer_format (
319
326
op_node->Op ()->GetAttrIfExists <std::string>(" data_format" )));
320
327
modify = true ;
328
+ move_down_count++;
321
329
break ;
322
330
}
323
331
if (is_act_like_op) {
324
332
PutTranferlayoutAfterOp (op_node, graph, nullptr );
325
333
modify = true ;
334
+ move_down_count++;
326
335
break ;
327
336
}
328
337
if (is_elim_op) {
329
338
ElimTwoTranferlayout (op_node, graph, &modify);
339
+ elim_count++;
330
340
break ;
331
341
}
332
342
}
333
343
}
334
344
if (!modify) break ;
335
345
}
346
+ LOG (INFO) << " move down " << move_down_count << " transfer_layout" ;
347
+ LOG (INFO) << " eliminate " << elim_count << " pair of transfer_layout" ;
336
348
}
337
349
338
350
} // namespace ir
0 commit comments