OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] fix ybfx transpose in type incompatible (#29829)
jag.Xub182cd223777
diff --git a/src/plugins/intel_gpu/src/graph/reshape.cpp b/src/plugins/intel_gpu/src/graph/reshape.cppindex 341ea425085..84988b37ee9 100644--- a/src/plugins/intel_gpu/src/graph/reshape.cpp+++ b/src/plugins/intel_gpu/src/graph/reshape.cpp@@ -237,6 +237,29 @@ std::vector<layout> reshape_inst::calc_output_layouts(reshape_node const& node,output_format = node.get_preferred_output_fmt();}+ auto areVectorsCompatible = [](const ov::Shape& vec1, const ov::Shape& vec2) -> bool {+ std::unordered_map<size_t, size_t> countMap1, countMap2;++ for (auto num : vec1) {+ if (num != 1)+ countMap1[num]++;+ }+ for (auto num : vec2) {+ if (num != 1)+ countMap2[num]++;+ }++ return countMap1 == countMap2;+ };++ auto candidate_layout = layout {output_shapes[0], input_layout.data_type, format::adjust_to_rank(output_format, output_shapes[0].size()), out_pad};+ if ((!node.is_dynamic()) && areVectorsCompatible(impl_param.get_output_layout().get_shape(), output_shapes[0].get_shape())) {+ if (impl_param.get_output_layout().format != output_format && !candidate_layout.compatible(input_layout)) {+ if (!impl_param.get_output_layout(false).compatible(candidate_layout))+ output_format = impl_param.get_output_layout().format;+ }+ }+auto new_out_pad = out_pad;if (new_out_pad == padding())new_out_pad = impl_param.get_output_layout(0).data_padding;diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/reshape_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/reshape_gpu_test.cppindex ee8e9c681dd..f810e590830 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/reshape_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/reshape_gpu_test.cpp@@ -12,8 +12,11 @@#include <intel_gpu/primitives/eltwise.hpp>#include <intel_gpu/primitives/permute.hpp>#include <intel_gpu/primitives/activation.hpp>+#include <intel_gpu/primitives/gemm.hpp>#include "reshape_inst.h"+#include "program_wrapper.h"+using namespace cldnn;using namespace ::tests;@@ -540,6 +543,76 @@ TEST(reshape_gpu_f32, calc_output_shape) {test_calc_output_shape<float>(false);}++template <typename T>+void test_calc_output_support_shape(bool is_caching_test) {+ // reshape does not handle some cases when format is updated.+ // some of which will be incompatible between output and input.+ // for example, a default input layout of [1, 1, 157, 1024] with bfyx+ // is compatible with the output layout of [157,1, 1024] with bfyx.+ // but if the format is updated by some pass to i.e, ybfx.+ // the layout becames incompatible.+ // thus the primitie will refuse to update shape when running calc_output_layouts.+ //+ // This situation is observed in RNNT model, whose format is updated by ov::pass::reorder_input.+ // The incompatible caused by refuse update will be fixed by the following passes.++ auto& engine = get_test_engine();+ ov::Shape in1_shape = { 1, 1, 3, 3 };+ ov::Shape in2_shape = { 1, 1, 7, 3 };+ ov::Shape out1_shape = { 3, 1, 7, 1 };+ auto in1_layout = layout{in1_shape, data_types::f32, format::bfyx};+ auto in2_layout = layout{in2_shape, data_types::f32, format::bfyx};+ auto out1_layout = layout{out1_shape, data_types::f32, format::bfyx};+ auto input1 = engine.allocate_memory(layout{ov::PartialShape(in1_shape), data_types::f32, format::bfyx});+ auto input2 = engine.allocate_memory(layout{ov::PartialShape(in2_shape), data_types::f32, format::bfyx});+ topology topology;++ topology.add(input_layout("input1", in1_layout),+ input_layout("input2", in2_layout),+ gemm("gemm", { input_info("input1"), input_info("input2") }, data_types::f32, false, true, 1.0f, 0.0f, 4, 4)+ );+ topology.add(input_layout("input", out1_layout));+ topology.add(shape_of("shape_of_input", input_info("input"), data_types::i32));++ topology.add(reshape("reshape", input_info("gemm"), false, { 3, 1, 7, 1 }, ov::PartialShape{ 3, 1, 7, 1 }));++ set_values(input1, {-1.f, 2.f, -3.f,+ -4.f, 5.f, -6.f});+ set_values(input2, {-1.f, 2.f, -3.f,+ -4.f, 5.f, -6.f,+ -7.f, 8.f, -9.f,+ 1.f, -2.f, 3.f,+ 4.f, -5.f, 6.f,+ 7.f, -8.f, 9.f,+ -7.f, 8.f, -9.f});++ ExecutionConfig config = get_test_default_config(engine);+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));++ auto prog = program::build_program(engine, topology, config, false, true);+ reorder_factory rf;+ program_wrapper::apply_opt_pass<basic_memory_dependencies>(*prog);+ program_wrapper::apply_opt_pass<skipped_branch_memory_dependencies>(*prog);+ program_wrapper::apply_opt_pass<oooq_memory_dependencies>(*prog);+ program_wrapper::apply_opt_pass<reorder_inputs>(*prog, rf);+ auto& node = prog->get_node("gemm");+ node.set_preferred_output_fmt(0, format::ybfx);+ node.recalc_output_layouts(false);++ auto& reshape_node = prog->get_node("reshape");+ auto ori_layout = reshape_node.get_output_layout(0);+ reshape_node.get_kernel_impl_params()->memory_deps = {{1,input1}};+ reshape_node.recalc_output_layouts(false);++ ASSERT_TRUE(reshape_node.get_output_layout(0) == ori_layout);++}++TEST(reshape_gpu_f32, calc_output_support_shape) {+ test_calc_output_support_shape<float>(false);+}+template <typename T>void test_basic_bfwzyx(bool is_caching_test) {// input: bfwzyx, (3, 3, 2, 2, 1, 1)