diff --git a/src/core/include/openvino/op/interpolate.hpp b/src/core/include/openvino/op/interpolate.hpp index 6bd2b9cbb6a..748f0be0f93 100644 --- a/src/core/include/openvino/op/interpolate.hpp +++ b/src/core/include/openvino/op/interpolate.hpp @@ -253,6 +253,9 @@ public: const InterpolateAttrs& get_attrs() const { return m_attrs; } + void set_attrs(const InterpolateAttrs& attrs) { + this->m_attrs = attrs; + } protected: /// \return The interpolation axes. diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/build_options.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/build_options.hpp index 1fcefbbed4e..0ba9fba6e8b 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/graph/build_options.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/graph/build_options.hpp @@ -60,7 +60,8 @@ enum class build_option_type { serialize_network, load_program, force_implementations, - partial_build_program + partial_build_program, + allow_new_shape_infer }; /// @brief Tuning mode. @@ -143,6 +144,9 @@ struct build_option { static std::shared_ptr force_implementations(implementation_forcing_map forcing); static std::shared_ptr partial_build_program(bool set = false); + + static std::shared_ptr allow_new_shape_infer(bool set = false); + virtual ~build_option() = default; private: @@ -363,12 +367,16 @@ struct build_option_traits { using object_type = build_option_force_implementations; static std::shared_ptr make_default() { return build_option::force_implementations({}); } }; - template <> struct build_option_traits { typedef build_option_bool object_type; static std::shared_ptr make_default() { return build_option::partial_build_program(); } }; +template <> +struct build_option_traits { + typedef build_option_bool object_type; + static std::shared_ptr make_default() { return build_option::allow_new_shape_infer(); } +}; #endif } // namespace detail @@ -423,6 +431,10 @@ inline std::shared_ptr build_option::partial_build_program(b return std::make_shared>(enable); } +inline std::shared_ptr build_option::allow_new_shape_infer(bool enable) { + return std::make_shared>(enable); +} + #endif /// @brief Represents program build options list. diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/resample.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/resample.hpp index 32dd227ef0d..fe4d01a84a6 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/resample.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/resample.hpp @@ -40,6 +40,7 @@ struct resample : public primitive_base { : primitive_base(id, {input}, ext_prim_id, output_padding), output_size(output_size), num_filter(num_filter), + output_pattern({}), scales({}), axes({}), pads_begin({}), @@ -57,18 +58,14 @@ struct resample : public primitive_base { } } - /// @brief Constructs Resample primitive with Interpolate operation. - /// @param id This primitive id. - /// @param input Input primitive id. - /// @param pads_begin Optional begin padding for input. - /// @param pads_end Optional end padding for input. + /// @brief resample with dynamic pattern resample(const primitive_id& id, const primitive_id& input, - tensor output_size, - std::vector scales, - std::vector axes, - std::vector pads_begin = {}, - std::vector pads_end = {}, + const primitive_id& pattern_id, + const std::vector& scales, + const std::vector& axes, + const std::vector& pads_begin = {}, + const std::vector& pads_end = {}, int32_t antialias = 0, float cube_coeff = -0.75f, InterpolateOp::InterpolateMode operation_type = InterpolateOp::InterpolateMode::LINEAR, @@ -77,9 +74,10 @@ struct resample : public primitive_base { InterpolateOp::NearestMode nm = InterpolateOp::NearestMode::ROUND_PREFER_FLOOR, const primitive_id& ext_prim_id = "", const padding& output_padding = padding()) - : primitive_base(id, {input}, ext_prim_id, output_padding), - output_size(output_size), + : primitive_base(id, {input, pattern_id}, ext_prim_id, output_padding), + output_size(tensor()), num_filter(0), + output_pattern({}), scales(scales), axes(axes), pads_begin(pads_begin), @@ -94,7 +92,41 @@ struct resample : public primitive_base { throw std::runtime_error("Resample's scales/axes count does not match"); } - InterpolateOp::InterpolateAttrs get_attrs() { + /// @brief reshape with static pattern + resample(const primitive_id& id, + const primitive_id& input, + const std::vector& output_pattern, + const std::vector& scales, + const std::vector& axes, + const std::vector& pads_begin = {}, + const std::vector& pads_end = {}, + int32_t antialias = 0, + float cube_coeff = -0.75f, + InterpolateOp::InterpolateMode operation_type = InterpolateOp::InterpolateMode::LINEAR, + InterpolateOp::ShapeCalcMode shape_calc_mode = InterpolateOp::ShapeCalcMode::SIZES, + InterpolateOp::CoordinateTransformMode ctm = InterpolateOp::CoordinateTransformMode::HALF_PIXEL, + InterpolateOp::NearestMode nm = InterpolateOp::NearestMode::ROUND_PREFER_FLOOR, + const primitive_id& ext_prim_id = "", + const padding& output_padding = padding()) + : primitive_base(id, {input}, ext_prim_id, output_padding), + output_size(tensor()), + num_filter(0), + output_pattern(output_pattern), + scales(scales), + axes(axes), + pads_begin(pads_begin), + pads_end(pads_end), + operation_type(operation_type), + shape_calc_mode(shape_calc_mode), + antialias(antialias), + cube_coeff(cube_coeff), + coord_trans_mode(ctm), + round_mode(nm) { + if (scales.size() != axes.size()) + throw std::runtime_error("Resample's scales/axes count does not match"); + } + + InterpolateOp::InterpolateAttrs get_attrs() const { return InterpolateOp::InterpolateAttrs(this->operation_type, this->shape_calc_mode, this->pads_begin, @@ -102,13 +134,14 @@ struct resample : public primitive_base { this->coord_trans_mode, this->round_mode, static_cast(this->antialias), - cube_coeff); + this->cube_coeff); } - /// @param scale Resample scale. tensor output_size; /// @param num_filter Input filter. Only used by bilinear sample_type. uint32_t num_filter; + /// @param output_pattern Describing output shape for spatial axes. + std::vector output_pattern; /// @param scales Scales of spatial axes, i.e. output_shape / input_shape std::vector scales; /// @param axes Interpolation axes. diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp index 2349e05f361..cac1e45d9e1 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp @@ -81,7 +81,8 @@ inline std::vector convert_pads(const std::vector& pad, size_t new_pad = std::vector(rank, 0); } else { new_pad = std::vector(pad.begin(), pad.end()); - std::reverse(new_pad.begin() + 2, new_pad.end()); + if (new_pad.size() > 2) + std::reverse(new_pad.begin() + 2, new_pad.end()); for (size_t i = new_pad.size(); i < rank || i < 4; ++i) new_pad.push_back(0); } 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 7f6183247ad..b0f1a1f0335 100644 --- a/src/plugins/intel_gpu/src/graph/include/resample_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/resample_inst.h @@ -33,6 +33,8 @@ class typed_primitive_inst : public typed_primitive_inst_base + static std::vector calc_output_layouts(resample_node const& node, const kernel_impl_params& impl_param); static std::string to_string(resample_node const& node); public: diff --git a/src/plugins/intel_gpu/src/graph/program_node.cpp b/src/plugins/intel_gpu/src/graph/program_node.cpp index 0dd9f138496..be653d2a8bf 100644 --- a/src/plugins/intel_gpu/src/graph/program_node.cpp +++ b/src/plugins/intel_gpu/src/graph/program_node.cpp @@ -226,6 +226,14 @@ bool program_node::is_detached(bool whole_branch) { } layout program_node::calc_output_layout() const { + bool allow_new_shape_infer = + get_program().get_options().get()->enabled(); + if (allow_new_shape_infer) { + auto out_layouts = type()->calc_output_layouts(*this, *get_kernel_impl_params()); + if (!out_layouts.empty()) { + return out_layouts[0]; + } + } return type()->calc_output_layout(*this, *get_kernel_impl_params()); } diff --git a/src/plugins/intel_gpu/src/graph/resample.cpp b/src/plugins/intel_gpu/src/graph/resample.cpp index eb1367baf02..5b88cde3a44 100644 --- a/src/plugins/intel_gpu/src/graph/resample.cpp +++ b/src/plugins/intel_gpu/src/graph/resample.cpp @@ -9,6 +9,8 @@ #include #include "json_object.h" +#include "interpolate_shape_inference.hpp" + namespace cldnn { primitive_type_id resample::type_id() { static primitive_type_base instance; @@ -28,13 +30,69 @@ layout resample_inst::calc_output_layout(resample_node const& node, kernel_impl_ output_type = impl_param.get_fused_output_layout().data_type; } - auto result_sizes = desc->output_size; + return desc->output_pattern.empty() ? layout({output_type, input_layout.format, desc->output_size}) : + layout({desc->output_pattern, output_type, input_layout.format}); +} - CLDNN_ERROR_NOT_EQUAL(desc->id, "Input batch size", input_layout.batch(), "output batch size", result_sizes.batch[0], ""); - CLDNN_ERROR_NOT_EQUAL(desc->id, "Input feature size", input_layout.feature(), "output feature size", result_sizes.feature[0], ""); +template +std::vector resample_inst::calc_output_layouts(resample_node const& node, const kernel_impl_params& impl_param) { + auto desc = impl_param.typed_desc(); + auto input_layout = impl_param.get_input_layout(0); - auto result = layout({output_type, input_layout.format, result_sizes}); - return result; + auto& memory_deps = impl_param.memory_deps; + + ov::op::v4::Interpolate op; + op.set_attrs(desc->get_attrs()); + + ShapeType pattern_shape = impl_param.input_layouts.size() == 2 ? impl_param.input_layouts[1].get() + : ov::Shape{ desc->output_pattern.size() }; + std::vector output_shapes = {ShapeType()}; + std::vector input_shapes = { + impl_param.input_layouts[0].get(), + pattern_shape, + ov::Shape{ desc->scales.size() }, + ov::Shape{ desc->axes.size() } + }; + + std::map const_data; + + auto scales_data = desc->scales; + auto scales_tensor = make_host_tensor({ ov::PartialShape{ ov::Shape{scales_data.size()} }, data_types::f32, format::bfyx }, + static_cast(scales_data.data())); + const_data.emplace(2, scales_tensor); + + auto axes_data = desc->axes; + if (axes_data.empty()) { + axes_data.resize(input_layout.get_rank()); + std::iota(axes_data.begin(), axes_data.end(), 0); + } + auto axes_tensor = make_host_tensor({ ov::PartialShape{ ov::Shape{axes_data.size()} }, data_types::i64, format::bfyx }, + static_cast(axes_data.data())); + const_data.emplace(3, axes_tensor); + + auto pads_begin = desc->pads_begin; + auto pads_end = desc->pads_end; + ov::op::v4::correct_pads_attr(&op, pads_begin, pads_end, input_shapes); + + auto pattern_data = desc->output_pattern; + if (!memory_deps.empty()) { + auto pattern_mem = memory_deps.at(1); + + cldnn::mem_lock pattern_lock(pattern_mem, node.get_program().get_stream()); + + auto pattern_ptr = pattern_lock.data(); + auto pattern_tensor = make_host_tensor(pattern_mem->get_layout(), pattern_ptr); + + const_data.emplace(1, pattern_tensor); + ov::op::v4::shape_infer(&op, pads_begin, pads_end, input_shapes, output_shapes, {const_data}); + } else { + auto pattern_tensor = make_host_tensor({ pattern_shape, data_types::i64, format::bfyx }, + static_cast(pattern_data.data())); + const_data.emplace(1, pattern_tensor); + ov::op::v4::shape_infer(&op, pads_begin, pads_end, input_shapes, output_shapes, {const_data}); + } + + return { layout{output_shapes[0], input_layout.data_type, format::adjust_to_rank(input_layout.format, output_shapes[0].size())} }; } std::string resample_inst::to_string(resample_node const& node) { diff --git a/src/plugins/intel_gpu/src/graph/reshape.cpp b/src/plugins/intel_gpu/src/graph/reshape.cpp index e514932a121..27900241c68 100644 --- a/src/plugins/intel_gpu/src/graph/reshape.cpp +++ b/src/plugins/intel_gpu/src/graph/reshape.cpp @@ -74,7 +74,6 @@ std::vector reshape_inst::calc_output_layouts(reshape_node const& node, pattern_shape, }; - if (!memory_deps.empty()) { auto pattern_mem = memory_deps.at(1); diff --git a/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp b/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp index ec124344f5c..9ee48ed5944 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp @@ -24,7 +24,8 @@ static void CreateInterpolateOp(Program& p, const std::shared_ptrget_attrs(); auto inputRank = op->get_input_shape(0).size(); - auto outTensor = tensor_from_dims(op->get_output_shape(0)); + auto outShape = op->get_output_shape(0); + auto outputPattern = std::vector(outShape.begin(), outShape.end()); auto scales_constant = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(SCALES_INDEX)); if (!scales_constant) { @@ -76,7 +77,7 @@ static void CreateInterpolateOp(Program& p, const std::shared_ptr { @@ -44,7 +44,7 @@ public: TEST_P(format_adjust_test, shape_infer) { auto p = GetParam(); - if (p.expected_format == format::any) { + if (p.expected_format == cldnn::format::any) { cldnn::format fmt = cldnn::format::any; ASSERT_ANY_THROW(fmt = format::adjust_to_rank(p.in_format, p.new_rank)) << fmt.to_string(); } else { @@ -54,17 +54,17 @@ TEST_P(format_adjust_test, shape_infer) { INSTANTIATE_TEST_SUITE_P(smoke, format_adjust_test, testing::ValuesIn(std::vector{ - {format::bfyx, 3, format::bfyx}, - {format::bfyx, 4, format::bfyx}, - {format::bfyx, 5, format::bfzyx}, - {format::bfyx, 6, format::bfwzyx}, - {format::bfzyx, 4, format::bfyx}, - {format::bfzyx, 6, format::bfwzyx}, - {format::bfwzyx, 3, format::bfyx}, - {format::b_fs_yx_fsv16, 5, format::b_fs_zyx_fsv16}, - {format::b_fs_zyx_fsv16, 4, format::b_fs_yx_fsv16}, - {format::fs_b_yx_fsv32, 5, format::any}, - {format::nv12, 5, format::any}, - {format::oiyx, 5, format::any}, + {cldnn::format::bfyx, 3, cldnn::format::bfyx}, + {cldnn::format::bfyx, 4, cldnn::format::bfyx}, + {cldnn::format::bfyx, 5, cldnn::format::bfzyx}, + {cldnn::format::bfyx, 6, cldnn::format::bfwzyx}, + {cldnn::format::bfzyx, 4, cldnn::format::bfyx}, + {cldnn::format::bfzyx, 6, cldnn::format::bfwzyx}, + {cldnn::format::bfwzyx, 3, cldnn::format::bfyx}, + {cldnn::format::b_fs_yx_fsv16, 5, cldnn::format::b_fs_zyx_fsv16}, + {cldnn::format::b_fs_zyx_fsv16, 4, cldnn::format::b_fs_yx_fsv16}, + {cldnn::format::fs_b_yx_fsv32, 5, cldnn::format::any}, + {cldnn::format::nv12, 5, cldnn::format::any}, + {cldnn::format::oiyx, 5, cldnn::format::any}, }), format_adjust_test::PrintToString); diff --git a/src/plugins/intel_gpu/tests/shape_infer/interpolate_si_test.cpp b/src/plugins/intel_gpu/tests/shape_infer/interpolate_si_test.cpp new file mode 100644 index 00000000000..c00c637af0b --- /dev/null +++ b/src/plugins/intel_gpu/tests/shape_infer/interpolate_si_test.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils.h" + +#include +#include +#include + +#include "resample_inst.h" + +#include "program_wrapper.h" + +#include +#include + +using namespace cldnn; +using namespace ::tests; + +namespace shape_infer_tests { + +using InterpolateOp = ov::op::v4::Interpolate; +struct InterpolateAttrs { + InterpolateAttrs(InterpolateOp::ShapeCalcMode shape_calc_mode) : shape_calc_mode(shape_calc_mode) {} + InterpolateOp::InterpolateMode mode = InterpolateOp::InterpolateMode::LINEAR; + InterpolateOp::ShapeCalcMode shape_calc_mode = InterpolateOp::ShapeCalcMode::SIZES; + std::vector pads_begin; + std::vector pads_end; + InterpolateOp::CoordinateTransformMode coordinate_transformation_mode = InterpolateOp::CoordinateTransformMode::HALF_PIXEL; + InterpolateOp::NearestMode nearest_mode = InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; + bool antialias = false; + double cube_coeff = -0.75f; +}; + +struct interpolate_test_params { + layout in_layout; + layout pattern_layout; + std::vector pattern_data; + std::vector scales; + std::vector axes; + InterpolateAttrs attrs; + layout expected_layout; +}; + +class interpolate_test_two_inputs : public testing::TestWithParam { }; +TEST_P(interpolate_test_two_inputs, shape_infer) { + auto p = GetParam(); + + auto& engine = get_test_engine(); + + auto input_prim = std::make_shared("input", p.in_layout); + auto pattern_prim = std::make_shared("pattern", p.pattern_layout); + auto resample_prim = std::make_shared("output", "input", "pattern", p.scales, p.axes, + p.attrs.pads_begin, p.attrs.pads_end, + p.attrs.antialias, p.attrs.cube_coeff, + p.attrs.mode, p.attrs.shape_calc_mode, + p.attrs.coordinate_transformation_mode, p.attrs.nearest_mode); + cldnn::program prog(engine); + + auto pattern_mem = engine.allocate_memory(p.pattern_layout); + set_values(pattern_mem, p.pattern_data); + + auto& input_node = prog.get_or_create(input_prim); + auto& pattern_node = prog.get_or_create(pattern_prim); + auto& resample_node = prog.get_or_create(resample_prim); + program_wrapper::add_connection(prog, input_node, resample_node); + program_wrapper::add_connection(prog, pattern_node, resample_node); + auto params = resample_node.get_kernel_impl_params(); + + params->memory_deps = {{1, pattern_mem}}; + auto res_w_data = resample_inst::calc_output_layouts(resample_node, *params); + + ASSERT_EQ(res_w_data.size(), 1); + ASSERT_EQ(res_w_data[0], p.expected_layout); +} + +INSTANTIATE_TEST_SUITE_P(smoke, interpolate_test_two_inputs, + testing::ValuesIn(std::vector{ + { + layout{ov::PartialShape{1, 2, 48, 80}, data_types::f32, format::bfyx}, + layout{ov::PartialShape{4}, data_types::i64, format::bfyx}, {-1, -1, -1, -1}, + {0.5, 2.0}, {2, 3}, InterpolateAttrs{InterpolateOp::ShapeCalcMode::SCALES}, + layout{ov::PartialShape{1, 2, 24, 160}, data_types::f32, format::bfyx} + }, + { + layout{ov::PartialShape{2, 2, 3, 2}, data_types::f32, format::bfyx}, + layout{ov::PartialShape{4}, data_types::i64, format::bfyx}, {2, 2, 2, 3}, + {}, {}, InterpolateAttrs(InterpolateOp::ShapeCalcMode::SIZES), + layout{ov::PartialShape{2, 2, 2, 3}, data_types::f32, format::bfyx} + } + })); + +class interpolate_test_single_input : public testing::TestWithParam { }; +TEST_P(interpolate_test_single_input, shape_infer) { + auto p = GetParam(); + + auto& engine = get_test_engine(); + + auto input_prim = std::make_shared("input", p.in_layout); + auto resample_prim = std::make_shared("output", "input", p.pattern_data, p.scales, p.axes, + p.attrs.pads_begin, p.attrs.pads_end, + p.attrs.antialias, p.attrs.cube_coeff, + p.attrs.mode, p.attrs.shape_calc_mode, + p.attrs.coordinate_transformation_mode, p.attrs.nearest_mode); + cldnn::program prog(engine); + + auto& input_node = prog.get_or_create(input_prim); + auto& resample_node = prog.get_or_create(resample_prim); + program_wrapper::add_connection(prog, input_node, resample_node); + + auto params = resample_node.get_kernel_impl_params(); + auto res = resample_inst::calc_output_layouts(resample_node, *params); + + ASSERT_EQ(res.size(), 1); + ASSERT_EQ(res[0], p.expected_layout); +} + +INSTANTIATE_TEST_SUITE_P(smoke, interpolate_test_single_input, + testing::ValuesIn(std::vector{ + { + layout{ov::PartialShape{1, 2, 48, 80}, data_types::f32, format::bfyx}, + layout{ov::PartialShape{4}, data_types::i64, format::bfyx}, {-1, -1, -1, -1}, + {0.5, 2.0}, {2, 3}, InterpolateAttrs{InterpolateOp::ShapeCalcMode::SCALES}, + layout{ov::PartialShape{1, 2, 24, 160}, data_types::f32, format::bfyx} + }, + { + layout{ov::PartialShape{2, 2, 3, 2}, data_types::f32, format::bfyx}, + layout{ov::PartialShape{4}, data_types::i64, format::bfyx}, {2, 2, 2, 3}, + {}, {}, InterpolateAttrs(InterpolateOp::ShapeCalcMode::SIZES), + layout{ov::PartialShape{2, 2, 2, 3}, data_types::f32, format::bfyx} + } + })); + +} // shape_infer_tests diff --git a/src/plugins/intel_gpu/tests/test_cases/resample_gpu_test.cpp b/src/plugins/intel_gpu/tests/test_cases/resample_gpu_test.cpp index cc3b1bbdd45..62401c5a32a 100644 --- a/src/plugins/intel_gpu/tests/test_cases/resample_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/test_cases/resample_gpu_test.cpp @@ -48,7 +48,7 @@ TEST(resample_gpu, basic_in2x3x2x2_nearest) { 12.f, 9.f, -17.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology }; net.set_input_data("input", input); @@ -652,7 +652,7 @@ struct caffe_resample_random_test : testing::TestWithParam output_pattern {b, f, y*2, x*2}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -744,7 +746,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest1) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::CEIL; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -757,7 +759,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest1) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -814,6 +816,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest2) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -822,7 +826,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest2) { tensor shape = tensor{batch(b), feature(f), spatial(x, y)}; auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape }); - auto output_size = tensor(batch(b), feature(f), spatial(x*2, y*2)); + std::vector output_pattern {b, f, y*2, x*2}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -832,7 +836,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest2) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -845,7 +849,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest2) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -902,6 +906,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest3) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -910,7 +916,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest3) { tensor shape = tensor{batch(b), feature(f), spatial(x, y)}; auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape }); - auto output_size = tensor(batch(b), feature(f), spatial(x*2, y*2)); + std::vector output_pattern {b, f, y*2, x*2}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -920,7 +926,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest3) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_CEIL; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -933,7 +939,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest3) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -990,6 +996,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest4) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -998,7 +1006,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest4) { tensor shape = tensor{batch(b), feature(f), spatial(x, y)}; auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape }); - auto output_size = tensor(batch(b), feature(f), spatial(x*2, y*2)); + std::vector output_pattern {b, f, y*2, x*2}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1008,7 +1016,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest4) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1021,7 +1029,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest4) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1078,6 +1086,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest5) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1086,7 +1096,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest5) { tensor shape = tensor{batch(b), feature(f), spatial(x, y)}; auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape }); - auto output_size = tensor(batch(b), feature(f), spatial(x*2, y*2)); + std::vector output_pattern {b, f, y*2, x*2}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1096,7 +1106,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest5) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::SIMPLE; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1109,7 +1119,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_nearest5) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1166,6 +1176,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode1) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1176,7 +1188,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode1) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1186,7 +1198,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode1) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1199,7 +1211,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode1) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1234,6 +1246,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode2) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1244,7 +1258,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode2) { y = 1; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1254,7 +1268,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode2) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::PYTORCH_HALF_PIXEL; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1267,7 +1281,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode2) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1296,6 +1310,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode3) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1306,7 +1322,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode3) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1316,7 +1332,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode3) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::ASYMMETRIC; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1329,7 +1345,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode3) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1364,6 +1380,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode4) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1374,7 +1392,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode4) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1384,7 +1402,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode4) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1397,7 +1415,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode4) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1432,6 +1450,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode5) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1442,7 +1462,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode5) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1452,7 +1472,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode5) { auto ctm = resample::InterpolateOp::CoordinateTransformMode::ALIGN_CORNERS; auto nm = resample::InterpolateOp::NearestMode::ROUND_PREFER_FLOOR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode, ctm, nm)); set_values(input, { 0.f, 1.f, 2.f, @@ -1465,7 +1485,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_coord_transform_mode5) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1500,6 +1520,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1510,7 +1532,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1518,7 +1540,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic) { float cube_coeff = -0.75f; auto mode = resample::InterpolateOp::InterpolateMode::CUBIC; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); set_values(input, { 0.f, 1.f, 2.f, @@ -1531,7 +1553,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1566,6 +1588,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic2) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 1; int f = 1; @@ -1575,7 +1599,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic2) { auto input = engine.allocate_memory({ data_types::f32, format::bfyx, shape }); x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1583,14 +1607,14 @@ TEST(resample_gpu, interpolate_in2x2x3x2_cubic2) { float cube_coeff = -0.75f; auto mode = resample::InterpolateOp::InterpolateMode::CUBIC; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); set_values(input, { 5.f, 1.f, 2.f, 3.f, 4.f, 5.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1617,6 +1641,8 @@ TEST(resample_gpu, interpolate_in2x2x3x2_linear) { // Sample Type: Nearest auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 2; int f = 2; @@ -1627,7 +1653,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_linear) { y = 2; x = 3; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1635,7 +1661,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_linear) { float cube_coeff = -0.75f; auto mode = resample::InterpolateOp::InterpolateMode::LINEAR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SIZES; - topology.add(resample("interpolate", "input", output_size, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); + topology.add(resample("interpolate", "input", output_pattern, {}, {}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); set_values(input, { 0.f, 1.f, 2.f, @@ -1648,7 +1674,7 @@ TEST(resample_gpu, interpolate_in2x2x3x2_linear) { 21.f, 22.f, 23.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input); @@ -1683,6 +1709,8 @@ TEST(resample_gpu, interpolate_in1x1x2x4_linear_scale) { // Sample Type: Linear auto& engine = get_test_engine(); + cldnn::build_options options; + options.set_option(cldnn::build_option::allow_new_shape_infer(true)); int b = 1; int f = 1; @@ -1693,7 +1721,7 @@ TEST(resample_gpu, interpolate_in1x1x2x4_linear_scale) { y = 1; x = 2; - auto output_size = tensor(batch(b), feature(f), spatial(x, y)); + std::vector output_pattern {b, f, y, x}; topology topology; topology.add(input_layout("input", input->get_layout())); @@ -1702,14 +1730,14 @@ TEST(resample_gpu, interpolate_in1x1x2x4_linear_scale) { auto mode = resample::InterpolateOp::InterpolateMode::LINEAR; auto shapeCalcMode = resample::InterpolateOp::ShapeCalcMode::SCALES; - topology.add(resample("interpolate", "input", output_size, {0.6f, 0.6f}, {2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); + topology.add(resample("interpolate", "input", output_pattern, {0.6f, 0.6f}, {2, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, antialias, cube_coeff, mode, shapeCalcMode)); set_values(input, { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, }); - cldnn::network net {engine, topology }; + cldnn::network net{ engine, topology, options }; net.set_input_data("input", input);