Skip to content

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

[GPU] Add new_shape_infer support in deconvolution (#28916)

Wilson Seok11cacc96217f
diff --git a/src/plugins/intel_gpu/src/graph/deconvolution.cpp b/src/plugins/intel_gpu/src/graph/deconvolution.cpp
index 975f77c77cf..103bf96039f 100644
--- a/src/plugins/intel_gpu/src/graph/deconvolution.cpp
+++ b/src/plugins/intel_gpu/src/graph/deconvolution.cpp
@@ -134,7 +134,7 @@ std::vector<layout> deconvolution_inst::calc_output_layouts(deconvolution_node c
out_fmt = node.get_preferred_output_fmt();
}
- if (desc->with_output_size) {
+ if (!node.get_program().is_new_shape_infer() && desc->with_output_size) {
CLDNN_ERROR_LESS_OR_EQUAL_THAN(desc->id,
"User-defined output spatial X",
desc->output_size.spatial[0],
@@ -207,7 +207,7 @@ std::vector<layout> deconvolution_inst::calc_output_layouts(deconvolution_node c
op.set_output_shape(output_partial_shape.to_shape());
input_shapes.push_back(ov::Shape{output_partial_shape.size()});
output_shapes = ov::op::v1::shape_infer(&op, input_shapes, pads_begin, pads_end);
- } else if (memory_deps.count(2)) {
+ } else if ((desc->output_shape_id != "" || desc->output_partial_shape.size() > 0) && memory_deps.count(2)) {
auto mem = memory_deps.at(2);
auto dims = read_vector<int64_t>(mem, impl_param.get_stream());
auto dims_shape = ov::Shape{dims.size()};
@@ -275,19 +275,20 @@ deconvolution_inst::typed_primitive_inst(network& network, deconvolution_node co
"output size",
output_layout.get_rank(),
"Input/output number of dimension does not match.");
- CLDNN_ERROR_NOT_EQUAL(node.id(),
- "Stride size",
- stride.size(),
- "output size",
- output_layout.get_spatial_rank(),
- "Stride/output number of dimension does not match.");
-
- CLDNN_ERROR_NOT_EQUAL(node.id(),
- "Input offset size",
- pad.size(),
- "input number of dimensions",
- output_layout.get_spatial_rank(),
- "");
+ if (!node.get_program().is_new_shape_infer()) {
+ CLDNN_ERROR_NOT_EQUAL(node.id(),
+ "Stride size",
+ stride.size(),
+ "output size",
+ output_layout.get_spatial_rank(),
+ "Stride/output number of dimension does not match.");
+ CLDNN_ERROR_NOT_EQUAL(node.id(),
+ "Input offset size",
+ pad.size(),
+ "input number of dimensions",
+ output_layout.get_spatial_rank(),
+ "");
+ }
auto filter_inst = node.weights().get_output_layout().convert_to_weights_layout(argument->grouped_weights_shape);
diff --git a/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp b/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
index 0c44a524f17..c565bc7ee73 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
@@ -132,7 +132,7 @@ static void CreateConvolutionBackpropDataOp(ProgramBuilder& p, const std::shared
auto pads_end = op->get_pads_end();
auto output_padding = op->get_output_padding();
- if (!op->is_dynamic()) {
+ if (!op->is_dynamic() && !p.use_new_shape_infer()) {
// Extend 1d vectors to 2d as 1d can't be handled properly by the graph optimizer for now
strides.resize(std::max<size_t>(2, strides.size()), 1);
dilations.resize(std::max<size_t>(2, strides.size()), 1);
diff --git a/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp
index 3a3598fc1e0..5cc38bd435a 100644
--- a/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp
@@ -56,6 +56,25 @@ struct deconv_eltw_test_params {
size_t expected_not_fused_primitives;
};
+struct deconv_new_shape_infer_test_params {
+ ov::PartialShape in_shape;
+ ov::PartialShape out_shape;
+ ov::PartialShape kernel;
+ ov::Strides stride;
+ ov::CoordinateDiff pad;
+ ov::Strides dilation;
+ uint32_t groups;
+ data_types data_type;
+ format input_format;
+ data_types weights_type;
+ format weights_format;
+ data_types default_type;
+ format default_format;
+ size_t expected_fused_primitives;
+ size_t expected_fused_primitives_onednn;
+ size_t expected_not_fused_primitives;
+};
+
class DeconvolutionFusingTest : public ::BaseFusingTest<deconv_test_params> {
public:
void execute(deconv_test_params& p, bool is_caching_test = false) {
@@ -94,6 +113,60 @@ public:
}
};
+class DeconvolutionFusingNewShapeInferTest : public ::BaseFusingTest<deconv_new_shape_infer_test_params> {
+public:
+ void SetUp() override {
+ rg.set_seed(GET_SUITE_NAME);
+ cfg_fused = get_test_default_config(engine);
+ cfg_not_fused = get_test_default_config(engine);
+
+ cfg_fused.set_property(ov::intel_gpu::optimize_data(true));
+ cfg_fused.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ cfg_not_fused.set_property(ov::intel_gpu::optimize_data(false));
+ cfg_not_fused.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ cfg_not_fused.set_property(ov::intel_gpu::allow_static_input_reorder(true));
+ }
+
+ void execute(deconv_new_shape_infer_test_params& p, bool is_caching_test = false) {
+ execute(p, get_mem(get_input_layout(p)), is_caching_test);
+ }
+ void execute(deconv_new_shape_infer_test_params& p, cldnn::memory::ptr input_prim, bool is_caching_test = false) {
+ if (engine.get_device_info().supports_immad)
+ p.expected_fused_primitives = p.expected_fused_primitives_onednn;
+
+ network::ptr network_not_fused = get_network(this->engine, this->topology_non_fused, cfg_not_fused, get_test_stream_ptr(cfg_not_fused), is_caching_test);
+ network::ptr network_fused = get_network(this->engine, this->topology_fused, cfg_fused, get_test_stream_ptr(cfg_fused), is_caching_test);
+ network_fused->set_input_data("input", input_prim);
+ network_not_fused->set_input_data("input", input_prim);
+
+ compare(*network_not_fused, *network_fused, p);
+ auto find_conv = [](primitive_info& p) -> bool {
+ if (p.original_id == "deconv")
+ return true;
+ return false;
+ };
+
+ auto pi_fused = network_fused->get_primitives_info();
+ auto info_fused = std::find_if(pi_fused.begin(), pi_fused.end(), find_conv);
+ if (info_fused != pi_fused.end())
+ std::cout << "kernel: " << info_fused->kernel_id << std::endl;
+ }
+
+ layout get_input_layout(deconv_new_shape_infer_test_params& p) {
+ auto pad = p.pad;
+ std::vector<int> pad_ = { 0, 0, static_cast<int>(pad[0]) };
+ return layout{ p.in_shape, p.data_type, p.input_format, padding{ pad_ } };
+ }
+
+ layout get_weights_layout(deconv_new_shape_infer_test_params& p) {
+ return layout{ p.kernel, p.weights_type, p.weights_format };
+ }
+
+ layout get_bias_layout(deconv_new_shape_infer_test_params& p) {
+ return layout{ ov::PartialShape{1, static_cast<int64_t>(p.out_shape.get_shape().at(1)), 1}, p.default_type, format::bfyx };
+ }
+};
+
class ConvEltwTest : public ::BaseFusingTest<deconv_eltw_test_params> {
public:
@@ -147,6 +220,9 @@ public:
#define CASE_DECONV_FP32_7 { 1, 16, 4, 5 }, { 1, 32, 7, 9 }, { 1, 1, 1, 1 }, { 2, 2 }, { 0, 0 }, { 1, 1 }, 1, data_types::f32, format::b_fs_yx_fsv16, data_types::f32, format::is_os_yx_isv16_osv16, data_types::f32, format::bfyx
#define CASE_DECONV_FP32_8 { 1, 32, 4, 5 }, { 1, 32, 7, 9 }, { 1, 1, 3, 3 }, { 2, 2 }, { 1, 1 }, { 1, 1 }, 32, data_types::f32, format::b_fs_yx_fsv16, data_types::f32, format::gs_oiyx_gsv16, data_types::f32, format::bfyx
+// 1D deconv
+#define CASE_DECONV_1D_FP32_1 { 1, 512, 1500 }, { 1, 256, 12008 }, { 256, 512, 16 }, { 8 }, { 0 }, { 1 }, 1, data_types::f32, format::bfyx, data_types::f32, format::oiyx, data_types::f32, format::bfyx
+
#define CASE_DECONV_FP16_1 { 1, 15, 4, 5 }, { 1, 30, 6, 7 }, { 1, 1, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::bfyx, data_types::f16, format::oiyx, data_types::f16, format::bfyx
#define CASE_DECONV_FP16_2 { 1, 16, 4, 5 }, { 1, 32, 6, 7 }, { 1, 1, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::is_os_yx_isv16_osv16, data_types::f16, format::bfyx
#define CASE_DECONV_FP16_3 { 1, 16, 4, 5 }, { 1, 32, 4, 5 }, { 1, 1, 1, 1 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::is_os_yx_isv16_osv16, data_types::f16, format::bfyx
@@ -390,6 +466,33 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, deconv_bias, ::testing::ValuesIn(std::vect
deconv_test_params{ CASE_DECONV_S8S8_3D_3, 2, 2, 3 },
}));
+class deconv_bias_1d : public DeconvolutionFusingNewShapeInferTest {};
+TEST_P(deconv_bias_1d, basic) {
+ auto p = GetParam();
+ create_topologies(
+ input_layout("input", get_input_layout(p)),
+ data("weights", get_mem(get_weights_layout(p))),
+ data("bias", get_mem(get_bias_layout(p))),
+ deconvolution("deconv", input_info("input"), { "weights" }, p.groups, p.stride, p.pad, p.dilation),
+ eltwise("bias_add", { input_info("deconv"), input_info("bias") }, eltwise_mode::sum),
+ reorder("out", input_info("bias_add"), p.default_format, data_types::f32)
+ );
+
+ if (engine.get_device_info().supports_immad &&
+ p.default_type == data_types::f16 &&
+ p.weights_format == format::is_os_yx_isv16_osv16) {
+ GTEST_SKIP(); // Issue: 94154
+ }
+
+ // Need much higher tolerance because of deconvolution -> convolution optimization
+ tolerance = 1.f;
+ execute(p);
+}
+
+INSTANTIATE_TEST_SUITE_P(fusings_gpu, deconv_bias_1d, ::testing::ValuesIn(std::vector<deconv_new_shape_infer_test_params>{
+ deconv_new_shape_infer_test_params{ CASE_DECONV_1D_FP32_1, 2, 2, 3 },
+}));
+
class deconv_scale : public DeconvolutionFusingTest {};
TEST_P(deconv_scale, basic) {
auto p = GetParam();