Skip to content

Commit

Permalink
[GPU] Fix static_impl != nullptr assertion for reorder node (#27786)
Browse files Browse the repository at this point in the history
### Details:
- Fix ”Assertion `static_impl != nullptr' failed“ issue for reorder
(Convolution_0_reorder_1) node by skipping mark node in shape flow.

### Tickets:
 - [CVS-154336](https://jira.devtools.intel.com/browse/CVS-154336)

---------

Signed-off-by: yuan.xiong <[email protected]>
  • Loading branch information
yuanxion authored Dec 23, 2024
1 parent 6e02445 commit d52f1da
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -86,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<broadcast>() && dependencies.size() == 2) {
if (dependencies[0].first->is_type<data>() && dependencies[1].first->is_type<shape_of>())
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,108 @@ 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, broadcast_not_existed_after_shapeof) {
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{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("weights", weights));
topology.add(shape_of("shape_of", input_info("input"), data_types::i32));
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);
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("convolution")));
}

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};
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_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_indirect_shapeof) {
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});

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(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));

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_direct_shapeof_and_data) {
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 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")));
}

0 comments on commit d52f1da

Please sign in to comment.