Skip to content

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

[GPU]Fix Interpolate when input/output have same size (#32615)

Zhang Yicba5ebd0a2ae
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_runtime_skippable_nodes.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_runtime_skippable_nodes.cpp
index 59057433355..5a28094d5d8 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_runtime_skippable_nodes.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_runtime_skippable_nodes.cpp
@@ -19,6 +19,7 @@
#include "scatter_nd_update_inst.h"
#include "dynamic_quantize_inst.h"
#include "lora_inst.h"
+#include "resample_inst.h"
#include "program_helpers.h"
using namespace cldnn;
@@ -288,5 +289,22 @@ void mark_runtime_skippable_nodes::run(program& p) {
GPU_DEBUG_TRACE_DETAIL << "[mark_runtime_skippable_nodes] : " << node.id() << " can_be_optimized" << std::endl;
}
});
+
+ program_helpers::do_for_types<resample>(*node, [](resample_node& node) {
+ // try to skip resample when inpu/ouput are same
+ auto impl_params = node.get_kernel_impl_params();
+ auto prim = impl_params->typed_desc<resample>();
+ bool can_be_optimized = all_zeroes(prim->pads_begin) && all_zeroes(prim->pads_end);
+ // for dynamic case, postpone the judgement to runtime
+ // for static case, judge if input/output are same here.
+ if (!node.is_dynamic()) {
+ can_be_optimized = node.get_input_layout(0) == node.get_output_layout(0);
+ }
+ if (!node.has_fused_primitives() && can_be_optimized) {
+ node.can_be_optimized(true);
+ node.set_runtime_skippable(true);
+ GPU_DEBUG_TRACE_DETAIL << "[mark_runtime_skippable_nodes] : " << node.id() << " can_be_optimized" << std::endl;
+ }
+ });
}
}
diff --git a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
index 3177b90881a..807142cf34a 100644
--- a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
+++ b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
@@ -503,6 +503,7 @@ private:
void do_runtime_in_place_crop();
void do_runtime_skip_scatter_update();
void do_runtime_skip_lora();
+ void do_runtime_skip_resample();
};
/*
diff --git a/src/plugins/intel_gpu/src/graph/include/resample_inst.h b/src/plugins/intel_gpu/src/graph/include/resample_inst.h
index 23bc7f6aa92..66d691279a9 100644
--- a/src/plugins/intel_gpu/src/graph/include/resample_inst.h
+++ b/src/plugins/intel_gpu/src/graph/include/resample_inst.h
@@ -44,9 +44,12 @@ public:
static std::vector<layout> calc_output_layouts(resample_node const& /*node*/, const kernel_impl_params& impl_param);
static layout calc_output_layout(resample_node const& node, kernel_impl_params const& impl_param);
static std::string to_string(resample_node const& node);
+ void update_output_memory() override;
public:
typed_primitive_inst(network& network, resample_node const& node);
+private:
+ void on_execute() override;
};
using resample_inst = typed_primitive_inst<resample>;
diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
index d8bdb0b9e9f..c521f390f7a 100644
--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
@@ -1898,6 +1898,24 @@ void primitive_inst::do_runtime_skip_lora() {
}
}
+void primitive_inst::do_runtime_skip_resample() {
+ OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("do_runtime_skip_resample: " + id()));
+ if (!get_node().is_type<resample>() || !get_node().is_runtime_skippable())
+ return;
+
+ const auto& input_layout = _impl_params->get_input_layout(0);
+ const auto& output_layout = _impl_params->get_output_layout();
+ bool is_unchanged = input_layout == output_layout;
+ if (is_unchanged) {
+ set_can_be_optimized(true);
+ GPU_DEBUG_TRACE_DETAIL << "[do_runtime_skip_resample] " << id() << " can be optimized due to same input/output" << std::endl;
+ } else {
+ set_can_be_optimized(false);
+ GPU_DEBUG_TRACE_DETAIL << "[do_runtime_skip_resample] " << id() << " cannot be optimized, input: " << input_layout.to_short_string()
+ << " , output: " << output_layout.to_short_string() << std::endl;
+ }
+}
+
bool primitive_inst::has_inner_networks() const {
return (_impl_params->inner_nets.size() > 0);
}
@@ -2008,6 +2026,7 @@ void primitive_inst::prepare_primitive() {
do_runtime_skip_scatter_update();
do_runtime_skip_lora();
do_runtime_in_place_crop();
+ do_runtime_skip_resample();
if (!is_valid_fusion()) {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("unfused_subgraph_build: " + id()));
diff --git a/src/plugins/intel_gpu/src/graph/resample.cpp b/src/plugins/intel_gpu/src/graph/resample.cpp
index 1aaa1c99136..ed44ccd6025 100644
--- a/src/plugins/intel_gpu/src/graph/resample.cpp
+++ b/src/plugins/intel_gpu/src/graph/resample.cpp
@@ -216,4 +216,30 @@ std::string resample_inst::to_string(resample_node const& node) {
resample_inst::typed_primitive_inst(network& network, resample_node const& node) : parent(network, node) {
}
+
+void resample_inst::on_execute() {
+ update_output_memory();
+}
+
+void resample_inst::update_output_memory() {
+ if (!can_be_optimized() || _impl_params->is_dynamic())
+ return;
+
+ build_deps();
+
+ if (get_node().get_program().is_new_shape_infer() && input_memory_ptr() == nullptr)
+ return;
+
+ if (_outputs[0] && get_network().get_engine().is_the_same_buffer(output_memory(), input_memory()))
+ return;
+
+ // Can_be_optimized nodes are allocating from memory_pool too. In this case,
+ // we need release the legacy output memory from memory pool explicitly.
+ if (static_cast<bool>(_outputs[0]) &&
+ get_node().get_program().get_config().get_enable_memory_pool()) {
+ get_network().get_memory_pool().release_memory(_outputs[0].get(), get_node().get_unique_id(), get_node().id(), get_network_id());
+ }
+ _outputs[0] = _network.get_engine().reinterpret_buffer(input_memory(), _impl_params->get_output_layout());
+ _mem_allocated = false;
+}
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
index 357a69ff385..4405021ec14 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/interpolate.cpp
@@ -345,4 +345,24 @@ INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_11_Pillow_Vertical_BF, Interpolate11L
::testing::Values(ov::test::utils::DEVICE_GPU),
::testing::Values(additional_config)),
Interpolate11LayerTest::getTestCaseName);
+
+
+INSTANTIATE_TEST_SUITE_P(smoke_Interpolate_11_Pillow_Same, Interpolate11LayerTest, ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(modesPillow),
+ ::testing::Values(ov::op::util::InterpolateBase::ShapeCalcMode::SIZES),
+ ::testing::Values(ov::op::util::InterpolateBase::CoordinateTransformMode::PYTORCH_HALF_PIXEL),
+ ::testing::Values(ov::op::util::InterpolateBase::NearestMode::FLOOR),
+ ::testing::Values(false),
+ ::testing::Values(std::vector<size_t>{0, 0, 0, 0}),
+ ::testing::Values(std::vector<size_t>{0, 0, 0, 0}),
+ ::testing::ValuesIn(cubeCoefs),
+ ::testing::Values(std::vector<int64_t>{0, 1}),
+ ::testing::Values(std::vector<float>{1.f, 1.f})),
+ ::testing::Values(ov::element::f32),
+ ::testing::Values(ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>{{1, 32, 32, 16}})),
+ ::testing::Values(ov::Shape{1, 32, 32, 16}),
+ ::testing::Values(ov::test::utils::DEVICE_GPU),
+ ::testing::Values(additional_config)),
+ Interpolate11LayerTest::getTestCaseName);
} // namespace