Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Fix mvn unit test fails (#28372)

Jade Cho4b1f82492955
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
index e59749c69d1..333afe18775 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/add_required_reorders.cpp
@@ -246,18 +246,42 @@ void add_required_reorders::run(program& p) {
}
// Remove padded-inputs in spatial axes not to use ref kernel which causes huge perf drop
- if (usr->is_type<mvn>() && usr->as<mvn>().input().is_padded_spatial()) {
- auto out_layout = usr->get_output_layout();
- // Check formats of implemented opt kernels without a spatial padding support
- if (out_layout.format == format::b_fs_yx_fsv16 || out_layout.format == format::b_fs_zyx_fsv16 ||
- out_layout.format == format::bs_fs_yx_bsv32_fsv16 || out_layout.format == format::bs_fs_yx_bsv32_fsv32) {
- auto& dep = usr->as<mvn>().input();
- cldnn::layout layout_wo_padding = dep.get_output_layout();
- layout_wo_padding.data_padding = cldnn::padding{};
- auto new_reorder = std::make_shared<reorder>(dep.id() + "_no_pad_reorder", dep.id(), layout_wo_padding);
- auto& new_reorder_node = p.get_or_create(new_reorder);
- p.add_intermediate(new_reorder_node, *usr, dep);
- new_reorder_node.recalc_output_layout(false);
+ if (usr->is_type<mvn>()) {
+ if (usr->as<mvn>().input().is_padded_spatial()) {
+ auto out_layout = usr->get_output_layout();
+ // Check formats of implemented opt kernels without a spatial padding support
+ if (out_layout.format == format::b_fs_yx_fsv16 || out_layout.format == format::b_fs_zyx_fsv16 ||
+ out_layout.format == format::bs_fs_yx_bsv32_fsv16 || out_layout.format == format::bs_fs_yx_bsv32_fsv32) {
+ auto& dep = usr->as<mvn>().input();
+ cldnn::layout layout_wo_padding = dep.get_output_layout();
+ layout_wo_padding.data_padding = cldnn::padding{};
+ auto new_reorder = std::make_shared<reorder>(dep.id() + "_no_pad_reorder", dep.id(), layout_wo_padding);
+ auto& new_reorder_node = p.get_or_create(new_reorder);
+ p.add_intermediate(new_reorder_node, *usr, dep);
+ new_reorder_node.recalc_output_layout(false);
+ }
+ }
+
+ auto input_layout = usr->get_input_layout();
+ auto input_pshape = input_layout.get_partial_shape();
+ auto prim = usr->as<mvn>().get_primitive();
+
+ if (prim->requires_alignment(input_pshape)) {
+ auto block_sizes = format::block_sizes(input_layout.format);
+ auto axes = prim->reduction_axes;
+ if (input_layout.is_dynamic() || block_sizes.size() > 1
+ || (block_sizes.size() == 1 &&
+ input_pshape[block_sizes[0].first].get_length() % block_sizes[0].second != 0 &&
+ std::count(axes.begin(), axes.end(), block_sizes[0].first) == 0)) {
+ auto rank = input_pshape.size();
+ input_layout.format = format::get_default_format(rank);
+ auto& dep = usr->as<mvn>().input();
+ auto new_reorder = std::make_shared<reorder>(dep.id() + "_to_plain", dep.id(), input_layout);
+ auto& new_reorder_node = p.get_or_create(new_reorder);
+ p.add_intermediate(new_reorder_node, *usr, dep);
+ // Need to invalidate users because the output format of mvn follows input format.
+ new_reorder_node.recalc_output_layout(true);
+ }
}
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/mvn.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/mvn.cpp
index 143b775008b..a12980646cd 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/mvn.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/mvn.cpp
@@ -63,7 +63,18 @@ struct mvn_impl : typed_primitive_impl_ocl<mvn> {
ov::PartialShape shape = ov::PartialShape::dynamic(new_rank);
auto& output_layout = updated_impl_params.output_layouts[0];
+
if (input_pshape.is_static()) {
+ size_t flatten_axis = 0;
+ // Change flatten axis if the format is single fsv.
+ auto block_sizes = format::block_sizes(input_layout.format);
+ if (block_sizes.size() == 1
+ && (input_pshape[block_sizes[0].first].get_length() % block_sizes[0].second == 0)
+ && (std::count(axes.begin(), axes.end(), block_sizes[0].first) == 0)
+ && block_sizes[0].first == 1) {
+ flatten_axis = 1;
+ }
+
for (size_t i = 0; i < new_rank; i++) {
shape[i] = 1;
}
@@ -72,7 +83,7 @@ struct mvn_impl : typed_primitive_impl_ocl<mvn> {
// 1. normalized dimensions which are flattened and written to the last dim
// 2. not normalized dims which are flattened and written to the first dim
for (size_t i = 0; i < input_rank; i++) {
- shape[static_cast<int64_t>(i) < min ? 0 : (new_rank - 1)] *= input_pshape[i];
+ shape[static_cast<int64_t>(i) < min ? flatten_axis : (new_rank - 1)] *= input_pshape[i];
}
}
diff --git a/src/plugins/intel_gpu/tests/unit/fusions/mvn_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/mvn_fusion_test.cpp
index 59e535123b9..da9b2c8011b 100644
--- a/src/plugins/intel_gpu/tests/unit/fusions/mvn_fusion_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fusions/mvn_fusion_test.cpp
@@ -80,6 +80,7 @@ public:
#define CASE_MVN_I8_6 { 2, 16, 8, 8 }, { 1, 1, 1, 1 }, data_types::i8, format::b_fs_yx_fsv16, {1, 2, 3}, true, data_types::f32, format::bfyx
#define CASE_MVN_I8_7 { 2, 16, 1, 8 }, { 1, 1, 8, 1 }, data_types::i8, format::b_fs_yx_fsv16, {1, 2, 3}, true, data_types::f32, format::bfyx
#define CASE_MVN_I8_8 { 2, 16, 3, 8 }, { 1, 1, 3, 8 }, data_types::i8, format::b_fs_yx_fsv16, {3}, true, data_types::f32, format::bfyx
+#define CASE_MVN_I8_8_NA { 2, 15, 3, 8 }, { 1, 1, 3, 8 }, data_types::i8, format::b_fs_yx_fsv16, {3}, true, data_types::f32, format::bfyx
#define CASE_MVN_3D_I8_1 { 1, 16, 8, 8, 8 }, { 1, 16, 8, 8, 8 }, data_types::i8, format::bfzyx, {2, 3, 4}, true, data_types::f32, format::bfzyx
#define CASE_MVN_3D_I8_2 { 2, 16, 8, 8, 8 }, { 2, 16, 8, 8, 8 }, data_types::i8, format::bfzyx, {1, 2, 3, 4}, true, data_types::f32, format::bfzyx
#define CASE_MVN_3D_I8_3 { 2, 16, 8, 8, 8 }, { 2, 1, 8, 8, 1 }, data_types::i8, format::bfzyx, {1, 2, 3, 4}, true, data_types::f32, format::bfzyx
@@ -170,7 +171,8 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, mvn_scale_quantize_i8, ::testing::ValuesIn
mvn_test_params{ CASE_MVN_I8_2, 2, 2, 4 },
mvn_test_params{ CASE_MVN_I8_3, 2, 2, 4 },
mvn_test_params{ CASE_MVN_I8_4, 2, 2, 4 },
- // mvn_test_params{ CASE_MVN_I8_8, 3, 3, 4 }, // TODO: It will be fix soon, test reference is wrong in new driver.
+ mvn_test_params{ CASE_MVN_I8_8, 3, 3, 4 },
+ mvn_test_params{ CASE_MVN_I8_8_NA, 3, 3, 4 },
mvn_test_params{ CASE_MVN_3D_I8_1, 2, 2, 4 },
mvn_test_params{ CASE_MVN_3D_I8_2, 2, 2, 4 },
mvn_test_params{ CASE_MVN_U8_1, 2, 2, 4 },
@@ -221,7 +223,7 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, mvn_scale_activation_eltwise_fp32_quantize
mvn_test_params{ CASE_MVN_I8_5, 2, 4, 6 },
mvn_test_params{ CASE_MVN_I8_6, 2, 4, 6 },
mvn_test_params{ CASE_MVN_I8_7, 3, 4, 6 },
- // mvn_test_params{ CASE_MVN_I8_8, 3, 5, 6 }, // TODO: It will be fix soon, test reference is wrong in new driver.
+ mvn_test_params{ CASE_MVN_I8_8, 3, 5, 6 },
mvn_test_params{ CASE_MVN_3D_I8_1, 2, 4, 6 },
mvn_test_params{ CASE_MVN_3D_I8_2, 2, 4, 6 },
mvn_test_params{ CASE_MVN_3D_I8_3, 2, 4, 6 },