[GPU] Fix a bug of remove redundant reorder pass (#7995)
+ Avoid dangling node exception
This commit is contained in:
1 parent
5b176f28cc
commit
d4820b1bc7
1 file changed
+21
-17
+21
-17
@@ -340,28 +340,28 @@ void remove_redundant_reorders::run(program& p) {
|
||||
}
|
||||
|
||||
// Remove reorder for Convolution bfyx -> fs_b_yx_fsv32 (+ onednn: bfyx -> b_fs_yx_fsv32)
|
||||
auto try_fuse_reorder_bfyx_to_fsv32 = [&](reorder_node* node) {
|
||||
auto try_fuse_reorder_bfyx_to_fsv32 = [&](reorder_node* node) -> bool {
|
||||
if (node->get_users().size() != 1)
|
||||
return;
|
||||
return false;
|
||||
|
||||
auto& usr = node->get_users().front();
|
||||
auto& dep = node->get_dependency(0);
|
||||
if (!(usr->is_type<convolution>()) ||
|
||||
usr->get_output_layout().data_type != dep.get_output_layout().data_type ||
|
||||
dep.get_output_layout().format != format::bfyx)
|
||||
return;
|
||||
return false;
|
||||
if (usr->as<convolution>().get_preferred_impl_type() != impl_types::onednn &&
|
||||
usr->get_output_layout().format != format::fs_b_yx_fsv32)
|
||||
return;
|
||||
return false;
|
||||
if (usr->as<convolution>().get_preferred_impl_type() == impl_types::onednn &&
|
||||
usr->get_output_layout().format != format::b_fs_yx_fsv32)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (dep.is_type<input_layout>())
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (usr->as<convolution>().get_primitive()->groups != 1)
|
||||
return;
|
||||
return false;
|
||||
|
||||
dep.merge_output_padding(node->get_output_layout().data_padding);
|
||||
p.replace_all_usages(*node, dep);
|
||||
@@ -369,36 +369,37 @@ void remove_redundant_reorders::run(program& p) {
|
||||
p.add_optimized_primitive_info(node->id());
|
||||
p.remove_all_connections(*node);
|
||||
p.remove_if_dangling(*node);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Remove reorder for Convolution b_fs_yx_fsv16 -> bfyx
|
||||
auto try_fuse_reorder_fsv16_to_bfyx = [&](reorder_node* node) {
|
||||
auto try_fuse_reorder_fsv16_to_bfyx = [&](reorder_node* node) -> bool {
|
||||
if (!node->get_fused_activations_funcs().empty() ||
|
||||
!node->get_fused_primitives().empty())
|
||||
return;
|
||||
return false;
|
||||
|
||||
auto& input = node->input();
|
||||
|
||||
if (!(input.is_type<convolution>()) ||
|
||||
!(input.get_output_layout().format == format::b_fs_yx_fsv16) ||
|
||||
!(node->get_output_layout().format == format::bfyx))
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (input.as<convolution>().get_primitive()->groups != 1)
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Avoid onednn convolution selects ref kernel for fsv16 -> bfyx
|
||||
if (input.as<convolution>().get_preferred_impl_type() == impl_types::onednn)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (input.get_users().size() != 1)
|
||||
return;
|
||||
return false;
|
||||
|
||||
auto& input_dep = input.get_dependency(0);
|
||||
if (input_dep.get_output_layout().format != format::b_fs_yx_fsv16 ||
|
||||
input_dep.get_output_layout().data_type == data_types::u8 ||
|
||||
input_dep.get_output_layout().data_type == data_types::i8)
|
||||
return;
|
||||
return false;
|
||||
|
||||
for (auto& user : node->get_users()) {
|
||||
// if concat is reorder's user and concat's axis is 0(Batch) or 1(Feature), conv's output would have padding.
|
||||
@@ -407,7 +408,7 @@ void remove_redundant_reorders::run(program& p) {
|
||||
auto& concat_node = user->as<concatenation>();
|
||||
auto concat_axis = concat_node.get_primitive()->axis;
|
||||
if (concat_axis == 0 || concat_axis == 1)
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,6 +432,7 @@ void remove_redundant_reorders::run(program& p) {
|
||||
p.add_optimized_primitive_info(node->id());
|
||||
p.extract_and_remove(*node);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if (enable_reorder_fusing) {
|
||||
@@ -446,9 +448,11 @@ void remove_redundant_reorders::run(program& p) {
|
||||
auto& r_node = node->as<reorder>();
|
||||
|
||||
// Remove reorder for Convolution bfyx -> fs_b_yx_fsv32
|
||||
try_fuse_reorder_bfyx_to_fsv32(&r_node);
|
||||
if (try_fuse_reorder_bfyx_to_fsv32(&r_node))
|
||||
continue;
|
||||
// Remove reorder for Convolution b_fs_yx_fsv16 -> bfyx
|
||||
try_fuse_reorder_fsv16_to_bfyx(&r_node);
|
||||
if (try_fuse_reorder_fsv16_to_bfyx(&r_node))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user