From edb4124806185def4c80ed9ae210ff4eafa608f4 Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Thu, 28 Nov 2024 13:39:21 +0800 Subject: [PATCH 01/11] Skip mark_node in shape flow for reorder node if dependency node is broadcase Signed-off-by: yuan.xiong --- .../src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index 9539117bcf4b18..bb165babb44427 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "broadcast_inst.h" +#include "reorder_inst.h" #include "shape_of_inst.h" #include "read_value_inst.h" #include "reshape_inst.h" @@ -26,6 +28,10 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { bool has_shape_of_subgraph_dep = false; for (auto& dependency : node.get_dependencies()) { if (dependency.first->is_in_shape_of_subgraph()) { + // skip mark_node for reorder node if dependency node is broadcast + if (dependency.first->is_type() && node.is_type()) { + break; + } has_shape_of_subgraph_dep = true; } else if (!dependency.first->is_constant()) { can_execute_in_subgraph = false; From cb0b1864d4ccd49168cc7a328ce3a82aa24cf6d5 Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Mon, 2 Dec 2024 09:36:55 +0800 Subject: [PATCH 02/11] Change to skip mark_node in shape flow for broadcast node if dependency node is shape_of Signed-off-by: yuan.xiong --- .../src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index bb165babb44427..d7cfdc2ceb3278 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -3,7 +3,6 @@ // #include "broadcast_inst.h" -#include "reorder_inst.h" #include "shape_of_inst.h" #include "read_value_inst.h" #include "reshape_inst.h" @@ -28,8 +27,8 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { bool has_shape_of_subgraph_dep = false; for (auto& dependency : node.get_dependencies()) { if (dependency.first->is_in_shape_of_subgraph()) { - // skip mark_node for reorder node if dependency node is broadcast - if (dependency.first->is_type() && node.is_type()) { + // skip mark_node for broadcast node if dependency node is shape_of + if (dependency.first->is_type() && node.is_type()) { break; } has_shape_of_subgraph_dep = true; From f85ca506a06d2dc410a0966896920f3c8131e25f Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Tue, 3 Dec 2024 14:58:31 +0800 Subject: [PATCH 03/11] Change to skip mark reorder node (added for conv) in shape_of flow for quantized model Signed-off-by: yuan.xiong --- .../mark_shape_of_subgraphs.cpp | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index d7cfdc2ceb3278..a28ddb3d1b619a 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "broadcast_inst.h" #include "shape_of_inst.h" #include "read_value_inst.h" #include "reshape_inst.h" @@ -16,21 +15,45 @@ using namespace cldnn; +namespace { + bool conv_reorder_with_fake_quantize(program_node& node) { + if (!node.is_type()) { + return false; + } + + std::string dequantize_name = "DequantizationMultiply"; + for (auto& dependency : node.get_dependencies()) { + if (dependency.first->is_type()) { + auto& conv_deps = dependency.first->get_dependencies(); + + for (auto& conv_dep : conv_deps) { + if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { + return true; + } + } + } + } + + return false; + } +} // namespace + void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { if (node.is_type()) { mark_node(node); return; } + // skip mark_node for reorder node (after convolution node) for quantized model + if (conv_reorder_with_fake_quantize(node)) { + return; + } + // Check if all dependencies are constant or marked as a part of shape_of subgraph bool can_execute_in_subgraph = true; bool has_shape_of_subgraph_dep = false; for (auto& dependency : node.get_dependencies()) { if (dependency.first->is_in_shape_of_subgraph()) { - // skip mark_node for broadcast node if dependency node is shape_of - if (dependency.first->is_type() && node.is_type()) { - break; - } has_shape_of_subgraph_dep = true; } else if (!dependency.first->is_constant()) { can_execute_in_subgraph = false; From b429d493083c2327276b89be167dd2eb739bb179 Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Mon, 9 Dec 2024 12:51:13 +0800 Subject: [PATCH 04/11] Check dependencies of reorder node all the way to input_layout node for quantized model Signed-off-by: yuan.xiong --- .../mark_shape_of_subgraphs.cpp | 99 ++++++++++++++++--- 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index a28ddb3d1b619a..d8e4f2288ada85 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "broadcast_inst.h" #include "shape_of_inst.h" #include "read_value_inst.h" #include "reshape_inst.h" @@ -16,26 +17,102 @@ using namespace cldnn; namespace { - bool conv_reorder_with_fake_quantize(program_node& node) { - if (!node.is_type()) { - return false; + bool has_input_layout_dep(const std::vector>& shape_of_deps) { + for (auto& shape_of_dep : shape_of_deps) { + // input_layout node + if (shape_of_dep.first->is_type()) { + return true; + } } + return false; + } - std::string dequantize_name = "DequantizationMultiply"; - for (auto& dependency : node.get_dependencies()) { - if (dependency.first->is_type()) { - auto& conv_deps = dependency.first->get_dependencies(); + bool has_shape_of_dep(const std::vector>& broadcast_deps) { + for (auto& broadcast_dep : broadcast_deps) { + // shape_of node + if (broadcast_dep.first->is_type()) { + auto& shape_of_deps = broadcast_dep.first->get_dependencies(); + return has_input_layout_dep(shape_of_deps); + } + } + return false; + } + + bool has_broadcast_dep(const std::vector>& reorder_deps) { + for (auto& reorder_dep : reorder_deps) { + // broadcast node + if (reorder_dep.first->is_type()) { + auto& broadcast_deps = reorder_dep.first->get_dependencies(); + return has_shape_of_dep(broadcast_deps); + } + } + return false; + } - for (auto& conv_dep : conv_deps) { - if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { - return true; + bool has_reorder_reoder_dep(const std::vector>& eltwise_deps) { + for (auto& eltwise_dep : eltwise_deps) { + // reorder node (reorder -> eltwise) + if (eltwise_dep.first->is_type()) { + auto& eltwise_dep_reorder_deps = eltwise_dep.first->get_dependencies(); + + for (auto& eltwise_dep_reorder_dep : eltwise_dep_reorder_deps) { + // reorder node (broadcast -> reorder) + if (eltwise_dep_reorder_dep.first->is_type()) { + auto& reorder_dep_reorder_deps = eltwise_dep_reorder_dep.first->get_dependencies(); + return has_broadcast_dep(reorder_dep_reorder_deps); } } } } + return false; + } + + bool has_eltwise_dep(const std::vector>& reorder_deps) { + for (auto& reorder_dep : reorder_deps) { + // eltwise node + if (reorder_dep.first->is_type()) { + auto& eltwise_deps = reorder_dep.first->get_dependencies(); + return has_reorder_reoder_dep(eltwise_deps); + } + } + return false; + } + + bool has_reorder_dep(const std::vector>& conv_deps) { + for (auto& conv_dep : conv_deps) { + //if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { + + // reorder node ( reorder -> convolution) + if (conv_dep.first->is_type()) { + auto& reorder_deps = conv_dep.first->get_dependencies(); + return has_eltwise_dep(reorder_deps); + } + } + return false; + } + bool has_convolution_dep(const std::vector>& dependencies) { + for (auto& dependency : dependencies) { + // convolution node + if (dependency.first->is_type()) { + auto& conv_deps = dependency.first->get_dependencies(); + return has_reorder_dep(conv_deps); + } + } return false; } + + // check dependencies for reorder node added for convolution in quantized model + bool skip_quantization_conv_reorder(const program_node& node) { + // reorder -> convolution -> reorder -> eltwise -> reorder -> reorder -> broadcast -> shape_of -> input_layout + if (!node.is_type()) { + return false; + } + + auto& dependencies = node.get_dependencies(); + return has_convolution_dep(dependencies); + } + } // namespace void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { @@ -45,7 +122,7 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { } // skip mark_node for reorder node (after convolution node) for quantized model - if (conv_reorder_with_fake_quantize(node)) { + if (skip_quantization_conv_reorder(node)) { return; } From 94c5739015c2ba2d42559a297db0dc2eac37c6df Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Thu, 12 Dec 2024 13:46:56 +0800 Subject: [PATCH 05/11] Skip mark_node in shape flow for broadcast node if dependency nodes are data and shape_of Signed-off-by: yuan.xiong --- .../mark_shape_of_subgraphs.cpp | 109 +----------------- 1 file changed, 6 insertions(+), 103 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index d8e4f2288ada85..7108a4870289c2 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -16,119 +16,22 @@ using namespace cldnn; -namespace { - bool has_input_layout_dep(const std::vector>& shape_of_deps) { - for (auto& shape_of_dep : shape_of_deps) { - // input_layout node - if (shape_of_dep.first->is_type()) { - return true; - } - } - return false; - } - - bool has_shape_of_dep(const std::vector>& broadcast_deps) { - for (auto& broadcast_dep : broadcast_deps) { - // shape_of node - if (broadcast_dep.first->is_type()) { - auto& shape_of_deps = broadcast_dep.first->get_dependencies(); - return has_input_layout_dep(shape_of_deps); - } - } - return false; - } - - bool has_broadcast_dep(const std::vector>& reorder_deps) { - for (auto& reorder_dep : reorder_deps) { - // broadcast node - if (reorder_dep.first->is_type()) { - auto& broadcast_deps = reorder_dep.first->get_dependencies(); - return has_shape_of_dep(broadcast_deps); - } - } - return false; - } - - bool has_reorder_reoder_dep(const std::vector>& eltwise_deps) { - for (auto& eltwise_dep : eltwise_deps) { - // reorder node (reorder -> eltwise) - if (eltwise_dep.first->is_type()) { - auto& eltwise_dep_reorder_deps = eltwise_dep.first->get_dependencies(); - - for (auto& eltwise_dep_reorder_dep : eltwise_dep_reorder_deps) { - // reorder node (broadcast -> reorder) - if (eltwise_dep_reorder_dep.first->is_type()) { - auto& reorder_dep_reorder_deps = eltwise_dep_reorder_dep.first->get_dependencies(); - return has_broadcast_dep(reorder_dep_reorder_deps); - } - } - } - } - return false; - } - - bool has_eltwise_dep(const std::vector>& reorder_deps) { - for (auto& reorder_dep : reorder_deps) { - // eltwise node - if (reorder_dep.first->is_type()) { - auto& eltwise_deps = reorder_dep.first->get_dependencies(); - return has_reorder_reoder_dep(eltwise_deps); - } - } - return false; - } - - bool has_reorder_dep(const std::vector>& conv_deps) { - for (auto& conv_dep : conv_deps) { - //if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { - - // reorder node ( reorder -> convolution) - if (conv_dep.first->is_type()) { - auto& reorder_deps = conv_dep.first->get_dependencies(); - return has_eltwise_dep(reorder_deps); - } - } - return false; - } - - bool has_convolution_dep(const std::vector>& dependencies) { - for (auto& dependency : dependencies) { - // convolution node - if (dependency.first->is_type()) { - auto& conv_deps = dependency.first->get_dependencies(); - return has_reorder_dep(conv_deps); - } - } - return false; - } - - // check dependencies for reorder node added for convolution in quantized model - bool skip_quantization_conv_reorder(const program_node& node) { - // reorder -> convolution -> reorder -> eltwise -> reorder -> reorder -> broadcast -> shape_of -> input_layout - if (!node.is_type()) { - return false; - } - - auto& dependencies = node.get_dependencies(); - return has_convolution_dep(dependencies); - } - -} // namespace - void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { if (node.is_type()) { mark_node(node); return; } - // skip mark_node for reorder node (after convolution node) for quantized model - if (skip_quantization_conv_reorder(node)) { - return; - } + // skip mark_node for broadcast node if dependency nodes are data and shape_of + auto& dependencies = node.get_dependencies(); + if (node.is_type() && dependencies.size() == 2) { + if (dependencies[0].first->is_type() && dependencies[1].first->is_type()) + return; // Check if all dependencies are constant or marked as a part of shape_of subgraph bool can_execute_in_subgraph = true; bool has_shape_of_subgraph_dep = false; + for (auto& dependency : node.get_dependencies()) { if (dependency.first->is_in_shape_of_subgraph()) { has_shape_of_subgraph_dep = true; From dbc53ee2f329d163bfb45fb221b2687bab8cc753 Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Thu, 12 Dec 2024 15:17:48 +0800 Subject: [PATCH 06/11] Fix typo Signed-off-by: yuan.xiong --- .../src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index 7108a4870289c2..2d7a6ea8183cd4 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -27,11 +27,11 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { if (node.is_type() && dependencies.size() == 2) { if (dependencies[0].first->is_type() && dependencies[1].first->is_type()) return; + } // Check if all dependencies are constant or marked as a part of shape_of subgraph bool can_execute_in_subgraph = true; bool has_shape_of_subgraph_dep = false; - for (auto& dependency : node.get_dependencies()) { if (dependency.first->is_in_shape_of_subgraph()) { has_shape_of_subgraph_dep = true; From f2f6971424a5313da17c353f5a9380dedd8cf50e Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Fri, 13 Dec 2024 13:31:24 +0800 Subject: [PATCH 07/11] Check broadcast node in can_mark_node Signed-off-by: yuan.xiong --- .../graph_optimizer/mark_shape_of_subgraphs.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index 2d7a6ea8183cd4..a40c7dfebb9de6 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -22,13 +22,6 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { return; } - // skip mark_node for broadcast node if dependency nodes are data and shape_of - auto& dependencies = node.get_dependencies(); - if (node.is_type() && dependencies.size() == 2) { - if (dependencies[0].first->is_type() && dependencies[1].first->is_type()) - return; - } - // Check if all dependencies are constant or marked as a part of shape_of subgraph bool can_execute_in_subgraph = true; bool has_shape_of_subgraph_dep = false; @@ -94,6 +87,13 @@ bool mark_shape_of_subgraphs::can_mark_node(const program_node& node) { return false; } + // skip mark_node for broadcast node if dependency nodes are data and shape_of + auto& dependencies = node.get_dependencies(); + if (node.is_type() && dependencies.size() == 2) { + if (dependencies[0].first->is_type() && dependencies[1].first->is_type()) + return false; + } + return true; } From cd23de01d13574ea8d3a25ccf0a2935cc118a88d Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Tue, 17 Dec 2024 08:54:43 +0800 Subject: [PATCH 08/11] Extend mark_shape_of_subgraphs_test for broaccast with shape_of for quantized models Signed-off-by: yuan.xiong --- .../passes/mark_shape_of_subgraphs_test.cpp | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp index 493ab79bf8e2cb..5215c0a75e83f6 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp @@ -318,3 +318,56 @@ TEST(mark_shape_of_subgraphs, gather_compressed_no_mark) { ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("gather_compressed"))); ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("concat"))); } + +TEST(mark_shape_of_subgraphs, conv_without_broadcast) { + auto& engine = get_test_engine(); + auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + data_types::f32, format::bfyx}; + auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); + + topology topology; + topology.add(input_layout("input", input_layout_dynamic)); + topology.add(data("weights", weights)); + topology.add(convolution("convolution", input_info("input"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + config.set_property(ov::intel_gpu::optimize_data(true)); + network network(engine, topology, config); + + auto prog = network.get_program(); + ASSERT_NE(prog, nullptr); + + ASSERT_FALSE(check_subgraph(prog->get_node("input"), prog->get_node("convolution"))); +} + +TEST(mark_shape_of_subgraphs, conv_with_broadcast_no_mark) { + auto& engine = get_test_engine(); + auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + data_types::f32, format::bfyx}; + auto data_0 = engine.allocate_memory({ ov::PartialShape{1}, data_types::i32, format::bfyx }); + set_values(data_0, {0}); + auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); + + topology topology; + topology.add(input_layout("input", input_layout_dynamic)); + topology.add(data("data_0", data_0)); + topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); + topology.add(broadcast("broadcast", input_info("data_0"), input_info("shape_of"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); + + topology.add(data("weights", weights)); + topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + config.set_property(ov::intel_gpu::optimize_data(true)); + network network(engine, topology, config); + + auto prog = network.get_program(); + ASSERT_NE(prog, nullptr); + + ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("shape_of"))); + ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); + ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("convolution"))); +} + From 7cdbe333289e249dd64e7222229dca883bb7194f Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Wed, 18 Dec 2024 14:17:34 +0800 Subject: [PATCH 09/11] fix broadcast with shape of and data testcases Signed-off-by: yuan.xiong --- .../passes/mark_shape_of_subgraphs_test.cpp | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp index 5215c0a75e83f6..74c02b2b9a241a 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp @@ -341,7 +341,31 @@ TEST(mark_shape_of_subgraphs, conv_without_broadcast) { ASSERT_FALSE(check_subgraph(prog->get_node("input"), prog->get_node("convolution"))); } -TEST(mark_shape_of_subgraphs, conv_with_broadcast_no_mark) { +TEST(mark_shape_of_subgraphs, broadcast_w_shapeof_and_data) { + auto& engine = get_test_engine(); + auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; + auto target_shape = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); + set_values(target_shape, {4, 4, 1, 1}); + + topology topology; + topology.add(input_layout("input", input_layout_dynamic)); + topology.add(data("target_shape", target_shape)); + topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); + topology.add(broadcast("broadcast", input_info("shape_of"), input_info("target_shape"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); + topology.add(reshape("reshape", input_info("input"), input_info("broadcast"), false, ov::PartialShape{4, 4, 1, 1})); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + config.set_property(ov::intel_gpu::optimize_data(true)); + network network(engine, topology, config); + + auto prog = network.get_program(); + ASSERT_NE(prog, nullptr); + + ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); +} + +TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { auto& engine = get_test_engine(); auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, data_types::f32, format::bfyx}; @@ -354,7 +378,6 @@ TEST(mark_shape_of_subgraphs, conv_with_broadcast_no_mark) { topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); topology.add(broadcast("broadcast", input_info("data_0"), input_info("shape_of"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); - topology.add(data("weights", weights)); topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); @@ -366,8 +389,5 @@ TEST(mark_shape_of_subgraphs, conv_with_broadcast_no_mark) { auto prog = network.get_program(); ASSERT_NE(prog, nullptr); - ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("shape_of"))); ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); - ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("convolution"))); } - From ccfb6fe1ee35f6c62e12bfae3154ef2bf32c48cf Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Thu, 19 Dec 2024 10:43:22 +0800 Subject: [PATCH 10/11] Add shape_of testcase for broadcast indirectly connected to shape_of Signed-off-by: yuan.xiong --- .../passes/mark_shape_of_subgraphs_test.cpp | 74 ++++++++++++++----- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp index 74c02b2b9a241a..19d94d05119f28 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp @@ -319,16 +319,23 @@ TEST(mark_shape_of_subgraphs, gather_compressed_no_mark) { ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("concat"))); } -TEST(mark_shape_of_subgraphs, conv_without_broadcast) { +TEST(mark_shape_of_subgraphs, broadcast_not_existed_after_shapeof) { auto& engine = get_test_engine(); + auto reshape_pattern = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); + set_values(reshape_pattern, {1, 4, 1, 1}); auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, data_types::f32, format::bfyx}; - auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); + auto data_0 = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); + auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 1, 1} }); topology topology; topology.add(input_layout("input", input_layout_dynamic)); + topology.add(data("data_0", data_0)); + topology.add(data("reshape_pattern", reshape_pattern)); topology.add(data("weights", weights)); - topology.add(convolution("convolution", input_info("input"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); + topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); + topology.add(reshape("reshape", input_info("shape_of"), input_info("reshape_pattern"), false, {})); + topology.add(convolution("convolution", input_info("reshape"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -338,21 +345,24 @@ TEST(mark_shape_of_subgraphs, conv_without_broadcast) { auto prog = network.get_program(); ASSERT_NE(prog, nullptr); - ASSERT_FALSE(check_subgraph(prog->get_node("input"), prog->get_node("convolution"))); + ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("convolution"))); } -TEST(mark_shape_of_subgraphs, broadcast_w_shapeof_and_data) { +TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { auto& engine = get_test_engine(); - auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; - auto target_shape = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); - set_values(target_shape, {4, 4, 1, 1}); + auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + data_types::f32, format::bfyx}; + auto data_0 = engine.allocate_memory({ ov::PartialShape{1}, data_types::i32, format::bfyx }); + set_values(data_0, {0}); + auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); topology topology; topology.add(input_layout("input", input_layout_dynamic)); - topology.add(data("target_shape", target_shape)); + topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); - topology.add(broadcast("broadcast", input_info("shape_of"), input_info("target_shape"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); - topology.add(reshape("reshape", input_info("input"), input_info("broadcast"), false, ov::PartialShape{4, 4, 1, 1})); + topology.add(broadcast("broadcast", input_info("data_0"), input_info("shape_of"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); + topology.add(data("weights", weights)); + topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -362,24 +372,24 @@ TEST(mark_shape_of_subgraphs, broadcast_w_shapeof_and_data) { auto prog = network.get_program(); ASSERT_NE(prog, nullptr); - ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); + ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); } -TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { +TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_gather) { auto& engine = get_test_engine(); - auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, - data_types::f32, format::bfyx}; + auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; auto data_0 = engine.allocate_memory({ ov::PartialShape{1}, data_types::i32, format::bfyx }); set_values(data_0, {0}); - auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); + //auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); topology topology; topology.add(input_layout("input", input_layout_dynamic)); topology.add(data("data_0", data_0)); topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); - topology.add(broadcast("broadcast", input_info("data_0"), input_info("shape_of"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); - topology.add(data("weights", weights)); - topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); + topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, 0, {})); + topology.add(broadcast("broadcast", input_info("data_0"), input_info("gather"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); + //topology.add(data("weights", weights)); + //topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -389,5 +399,29 @@ TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { auto prog = network.get_program(); ASSERT_NE(prog, nullptr); - ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); + ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); +} + +TEST(mark_shape_of_subgraphs, broadcast_w_shapeof_and_data) { + auto& engine = get_test_engine(); + auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; + auto target_shape = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); + set_values(target_shape, {4, 4, 1, 1}); + + topology topology; + topology.add(input_layout("input", input_layout_dynamic)); + topology.add(data("target_shape", target_shape)); + topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); + topology.add(broadcast("broadcast", input_info("shape_of"), input_info("target_shape"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); + topology.add(reshape("reshape", input_info("input"), input_info("broadcast"), false, ov::PartialShape{4, 4, 1, 1})); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); + config.set_property(ov::intel_gpu::optimize_data(true)); + network network(engine, topology, config); + + auto prog = network.get_program(); + ASSERT_NE(prog, nullptr); + + ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); } From 697f77ee26240c304cc2c69a9191b00904e2aa3a Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Thu, 19 Dec 2024 11:28:21 +0800 Subject: [PATCH 11/11] Clean code Signed-off-by: yuan.xiong --- .../passes/mark_shape_of_subgraphs_test.cpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp index 19d94d05119f28..ee4382e51645cd 100644 --- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp @@ -321,20 +321,18 @@ TEST(mark_shape_of_subgraphs, gather_compressed_no_mark) { TEST(mark_shape_of_subgraphs, broadcast_not_existed_after_shapeof) { auto& engine = get_test_engine(); - auto reshape_pattern = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); - set_values(reshape_pattern, {1, 4, 1, 1}); auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, data_types::f32, format::bfyx}; auto data_0 = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); + set_values(data_0, {1, 4, 1, 1}); auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 1, 1} }); topology topology; topology.add(input_layout("input", input_layout_dynamic)); topology.add(data("data_0", data_0)); - topology.add(data("reshape_pattern", reshape_pattern)); topology.add(data("weights", weights)); topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); - topology.add(reshape("reshape", input_info("shape_of"), input_info("reshape_pattern"), false, {})); + topology.add(reshape("reshape", input_info("shape_of"), input_info("data_0"), false, {})); topology.add(convolution("convolution", input_info("reshape"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); ExecutionConfig config = get_test_default_config(engine); @@ -348,7 +346,7 @@ TEST(mark_shape_of_subgraphs, broadcast_not_existed_after_shapeof) { ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("convolution"))); } -TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { +TEST(mark_shape_of_subgraphs, broadcast_w_data_and_direct_shapeof_no_mark) { auto& engine = get_test_engine(); auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, data_types::f32, format::bfyx}; @@ -372,15 +370,16 @@ TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_no_mark) { auto prog = network.get_program(); ASSERT_NE(prog, nullptr); + ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("convolution"))); ASSERT_FALSE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); } -TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_gather) { +TEST(mark_shape_of_subgraphs, broadcast_w_data_and_indirect_shapeof) { auto& engine = get_test_engine(); - auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; + auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + data_types::f32, format::bfyx}; auto data_0 = engine.allocate_memory({ ov::PartialShape{1}, data_types::i32, format::bfyx }); set_values(data_0, {0}); - //auto weights = engine.allocate_memory({ data_types::f16, format::bfyx, {1152, 4, 2, 2} }); topology topology; topology.add(input_layout("input", input_layout_dynamic)); @@ -388,8 +387,6 @@ TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_gather) { topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); topology.add(gather("gather", input_info("shape_of"), input_info("data_0"), 0, 0, {})); topology.add(broadcast("broadcast", input_info("data_0"), input_info("gather"), {}, ov::op::BroadcastType::BIDIRECTIONAL)); - //topology.add(data("weights", weights)); - //topology.add(convolution("convolution", input_info("broadcast"), "weights", "", 1, {1, 1}, {1, 1}, {0, 0}, {0, 0}, false)); ExecutionConfig config = get_test_default_config(engine); config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); @@ -402,9 +399,10 @@ TEST(mark_shape_of_subgraphs, broadcast_w_data_and_shapeof_gather) { ASSERT_TRUE(check_subgraph(prog->get_node("shape_of"), prog->get_node("broadcast"))); } -TEST(mark_shape_of_subgraphs, broadcast_w_shapeof_and_data) { +TEST(mark_shape_of_subgraphs, broadcast_w_direct_shapeof_and_data) { auto& engine = get_test_engine(); - auto input_layout_dynamic = layout{ov::PartialShape{1, 4, 2, 2}, data_types::f32, format::bfyx}; + auto input_layout_dynamic = layout{ov::PartialShape{ov::Dimension::dynamic(), 4, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + data_types::f32, format::bfyx}; auto target_shape = engine.allocate_memory({ ov::PartialShape{4}, data_types::i32, format::bfyx }); set_values(target_shape, {4, 4, 1, 1});