From bb0155a8da236cdc48ede905bb44a30a91dcef6c Mon Sep 17 00:00:00 2001 From: Lyamin-Roman Date: Thu, 19 Dec 2024 02:52:32 +0900 Subject: [PATCH] [GPU] Extend the cases where layouts are compatible --- src/plugins/intel_gpu/src/runtime/layout.cpp | 17 ++++++++++++++--- .../tests/unit/module_tests/layout_test.cpp | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/plugins/intel_gpu/src/runtime/layout.cpp b/src/plugins/intel_gpu/src/runtime/layout.cpp index a2b7e62ea0cae2..5c6c6dc83aeaea 100644 --- a/src/plugins/intel_gpu/src/runtime/layout.cpp +++ b/src/plugins/intel_gpu/src/runtime/layout.cpp @@ -446,8 +446,6 @@ bool layout::compatible(const layout& other) const { if (l1.is_dynamic() || l2.is_dynamic()) return false; - auto l1_size = l1.get_tensor(); - auto l2_size = l2.get_tensor(); if (l1 == l2) return true; if (check_redundant_1d_along_feature(l1, l2)) @@ -459,7 +457,7 @@ bool layout::compatible(const layout& other) const { if (format::is_default_format(l1.format) && format::is_default_format(l2.format) && !l1.data_padding && !l2.data_padding && l1.get_linear_size() == l2.get_linear_size()) return true; - if (l1_size != l2_size) + if (l1.get_shape() != l2.get_shape()) return false; if (l1.get_linear_size() != l2.get_linear_size()) return false; @@ -505,6 +503,19 @@ bool layout::compatible(const layout& other) const { auto l1_pitch = l1.get_pitches(); auto l2_pitch = l2.get_pitches(); + auto l1_padded_dims = l1.get_padded_dims(); + auto l2_padded_dims = l2.get_padded_dims(); + + // Ignore pitches which will never be used (for padded dims with size == 1) + for (size_t i = 0; i < l1_padded_dims.size(); ++i) { + if (l1_padded_dims[i] == 1) { + l1_pitch[i] = 0; + } + if (l2_padded_dims[i] == 1) { + l2_pitch[i] = 0; + } + } + auto l1_offset = l1.get_linear_offset(); auto l2_offset = l2.get_linear_offset(); if (l1_pitch == l2_pitch && l1_offset == l2_offset) diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/layout_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/layout_test.cpp index 7c666819176a13..279a86c73f55bf 100644 --- a/src/plugins/intel_gpu/tests/unit/module_tests/layout_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/module_tests/layout_test.cpp @@ -261,6 +261,10 @@ INSTANTIATE_TEST_SUITE_P(smoke, layout_cmp_test, layout{ov::PartialShape{4, 2, 3, 4, 5}, data_types::f16, format::is_os_zyx_isv16_osv16}, false, false}, {layout{ov::PartialShape{4, 2, 3, 4, 5}, data_types::f16, format::goiyx}, layout{ov::PartialShape{4, 2, 3, 4, 5}, data_types::f16, format::gioyx}, false, false}, + {layout{ov::PartialShape{4, 1, 16, 16}, data_types::f16, format::bfyx}, + layout{ov::PartialShape{4, 1, 16, 16}, data_types::f16, format::byxf}, false, true}, + {layout{ov::PartialShape{2, 1, 2, 4}, data_types::f16, format::bfyx, padding({0, 0, 1, 0}, {0, 0, 1, 0})}, + layout{ov::PartialShape{2, 1, 2, 4}, data_types::f16, format::bfyx, padding({0, 1, 0, 0}, {0, 0, 0, 0})}, false, false}, })); struct layouts_transform_test_params {