Skip to content

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

[GPU] Set ExecutionFlags::SHAPE_CHANGED to true when subgraph input changes (#31451)

David Nama23eb108aaa6
diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
index 0fcf99812cb..7b2775a3eb6 100644
--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
@@ -378,11 +378,15 @@ void primitive_inst::update_shape() {
break;
}
}
+
if (!subgraph_input_changed) {
GPU_DEBUG_TRACE_DETAIL << id() << ": skip shape_update, because it is in shape_of_subgraph and input shape is not changed\n";
unset_flag(ExecutionFlags::SHAPE_CHANGED);
return;
}
+
+ // If the input shape of root ShapeOf node has changed, update node's parameters as well.
+ set_flag(ExecutionFlags::SHAPE_CHANGED, subgraph_input_changed);
}
// Even though the predecessors' shapes are not changed, the output shape might be updated by the mem_dep
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp
index de86713571b..3fb35fea5d0 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/scatter_nd_update_gpu_test.cpp
@@ -6,6 +6,8 @@
#include "random_generator.hpp"
#include "openvino/reference/scatter_nd_update.hpp"
#include "scatter_nd_update_inst.h"
+#include "shape_of_inst.h"
+#include "reshape_inst.h"
#include <intel_gpu/primitives/input_layout.hpp>
#include <intel_gpu/primitives/scatter_update.hpp>
@@ -4676,3 +4678,39 @@ TEST_P(scatter_nd_update_random_test, random_cached)
TEST(scatter_nd_update_gpu_fp16, d222222_i211111_cached) {
test_d222222_i211111<ov::float16>(true);
}
+
+TEST(scatter_nd_update_gpu, subgraph_input_changed) {
+ auto& engine = get_test_engine();
+
+ auto input1 = engine.allocate_memory({ ov::PartialShape{2, 1}, data_types::f32, format::bfyx }); // Dictionary
+ auto input2 = engine.allocate_memory({ ov::PartialShape{2, 1}, data_types::i32, format::bfyx }); // Indexes
+ auto input3 = engine.allocate_memory({ ov::PartialShape{2, 1}, data_types::i32, format::bfyx }); // Updates
+ layout in_layout = {ov::PartialShape::dynamic(2), data_types::f32, format::bfyx};
+
+ set_values(input2, {0, 1});
+ set_values(input3, {2, 5});
+
+ std::vector<int32_t> expected_results = {2, 5};
+
+ topology topology;
+ topology.add(input_layout("input_data", in_layout));
+ topology.add(data("input_indices", input2));
+ topology.add(data("input_updates", input3));
+ topology.add(shape_of("shape_of", input_info("input_data"), data_types::i32));
+ topology.add(reshape("reshape", input_info("shape_of"), false, {}, ov::PartialShape{2, 1}));
+ topology.add(scatter_nd_update("scatter_nd_update", input_info("reshape"), input_info("input_indices"), input_info("input_updates"), 2));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+
+ network network(engine, topology, config);
+ network.set_input_data("input_data", input1);
+
+ auto outputs = network.execute();
+ auto output = outputs.at("scatter_nd_update").get_memory();
+ cldnn::mem_lock<int32_t> output_ptr(output, get_test_stream());
+
+ for (size_t i = 0; i < 2; ++i) {
+ ASSERT_EQ(expected_results[i], output_ptr[i]);
+ }
+}