From 7f5ba4e0740c7324c15375ab530ce39c671804d5 Mon Sep 17 00:00:00 2001 From: "Min, Byungil" Date: Wed, 22 Nov 2023 20:47:16 +0900 Subject: [PATCH] [GPU] Update space_to_depth to use nGraph shape inference (#21135) * [GPU] Update space_to_depth to use nGraph shape inference + Added calc_output_layouts to use shape_infer + Added relevant test-cases for static and dynamic + Modified typo of filename Signed-off-by: Min, Byungil --- .../intel_gpu/primitives/space_to_depth.hpp | 17 +- .../src/graph/impls/ocl/space_to_depth.cpp | 2 +- .../src/graph/include/space_to_depth_inst.h | 14 ++ .../intel_gpu/src/graph/space_to_depth.cpp | 36 +++- .../src/plugin/ops/space_to_depth.cpp | 12 +- .../{deth_to_space.cpp => depth_to_space.cpp} | 0 .../dynamic/space_to_depth.cpp | 195 ++++++++++++++++++ .../fusions/space_to_depth_fusion_test.cpp | 19 +- .../shape_infer/space_to_depth_si_test.cpp | 60 ++++++ .../test_cases/space_to_depth_gpu_test.cpp | 37 ++-- 10 files changed, 341 insertions(+), 51 deletions(-) rename src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/{deth_to_space.cpp => depth_to_space.cpp} (100%) create mode 100644 src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_depth.cpp create mode 100644 src/plugins/intel_gpu/tests/unit/shape_infer/space_to_depth_si_test.cpp diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/space_to_depth.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/space_to_depth.hpp index 91c2ff3bdc9..1f35aec7360 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/space_to_depth.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/space_to_depth.hpp @@ -3,9 +3,11 @@ // #pragma once +#include "openvino/op/space_to_depth.hpp" #include "primitive.hpp" namespace cldnn { +using SpaceToDepth = ov::op::v0::SpaceToDepth; /// @brief SpaceToDepth operation rearranges data from the spatial dimensions of the input tensor into depth dimension of the output tensor. /// @details SpaceToDepth operation permutes element from the input tensor with shape [b, f, y, x] @@ -44,25 +46,20 @@ struct space_to_depth : public primitive_base { space_to_depth() : primitive_base("", {}) {} - enum depth_mode { - depth_first, - blocks_first - }; - /// @brief Constructs space_to_depth primitive. /// @param id This primitive id. /// @param input Input dictionary primitive id. - /// @param depth_mode Depth mode (blocks_first / depth_first). + /// @param depth_mode Depth mode (BLOCKS_FIRST / DEPTH_FIRST). /// @param block_size Block size (optional). space_to_depth(const primitive_id& id, const input_info& input, - depth_mode mode, + SpaceToDepth::SpaceToDepthMode mode, const size_t block_size = 1, const padding& output_padding = padding()) : primitive_base(id, {input}, {output_padding}), mode(mode), block_size(block_size) {} /// @brief Depth mode. - depth_mode mode = depth_mode::depth_first; + SpaceToDepth::SpaceToDepthMode mode = SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST; /// @brief Block size. size_t block_size = 1; @@ -86,13 +83,13 @@ struct space_to_depth : public primitive_base { void save(BinaryOutputBuffer& ob) const override { primitive_base::save(ob); - ob << make_data(&mode, sizeof(depth_mode)); + ob << make_data(&mode, sizeof(SpaceToDepth::SpaceToDepthMode)); ob << block_size; } void load(BinaryInputBuffer& ib) override { primitive_base::load(ib); - ib >> make_data(&mode, sizeof(depth_mode)); + ib >> make_data(&mode, sizeof(SpaceToDepth::SpaceToDepthMode)); ib >> block_size; } }; diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/space_to_depth.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/space_to_depth.cpp index 5b72a5572cb..6c30057873e 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/space_to_depth.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/space_to_depth.cpp @@ -27,7 +27,7 @@ struct space_to_depth_impl : typed_primitive_impl_ocl { auto params = get_default_params(impl_param); auto optional_params = get_default_optional_params(impl_param.get_program()); - params.depth_mode = (primitive->mode == space_to_depth::blocks_first) ? + params.depth_mode = (primitive->mode == SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST) ? kernel_selector::SpaceToDepthMode::BLOCKS_FIRST : kernel_selector::SpaceToDepthMode::DEPTH_FIRST; diff --git a/src/plugins/intel_gpu/src/graph/include/space_to_depth_inst.h b/src/plugins/intel_gpu/src/graph/include/space_to_depth_inst.h index df0941ba558..efbe0b8b300 100644 --- a/src/plugins/intel_gpu/src/graph/include/space_to_depth_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/space_to_depth_inst.h @@ -8,9 +8,21 @@ #include "primitive_inst.h" #include +#include namespace cldnn { +template <> +struct typed_program_node : public typed_program_node_base { + using parent = typed_program_node_base; + +public: + using parent::parent; + + program_node& input(size_t index = 0) const { return get_dependency(index); } + std::vector get_shape_infer_dependencies() const override { return {}; } +}; + using space_to_depth_node = typed_program_node; template <> @@ -19,6 +31,8 @@ class typed_primitive_inst : public typed_primitive_inst_base + static std::vector calc_output_layouts(space_to_depth_node const& node, kernel_impl_params const& impl_param); static layout calc_output_layout(space_to_depth_node const& node, kernel_impl_params const& impl_param); static std::string to_string(space_to_depth_node const& node); diff --git a/src/plugins/intel_gpu/src/graph/space_to_depth.cpp b/src/plugins/intel_gpu/src/graph/space_to_depth.cpp index 5adac8bb84b..543fd245852 100644 --- a/src/plugins/intel_gpu/src/graph/space_to_depth.cpp +++ b/src/plugins/intel_gpu/src/graph/space_to_depth.cpp @@ -2,16 +2,48 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/space_to_depth.hpp" #include "space_to_depth_inst.h" #include "primitive_type_base.h" #include "intel_gpu/runtime/error_handler.hpp" #include "json_object.h" +#include "data_inst.h" #include +#include "space_to_depth_shape_inference.hpp" + namespace cldnn { GPU_DEFINE_PRIMITIVE_TYPE_ID(space_to_depth) +using SpaceToDepth = ov::op::v0::SpaceToDepth; + +template +std::vector space_to_depth_inst::calc_output_layouts(space_to_depth_node const& node, kernel_impl_params const& impl_param) { + auto desc = impl_param.typed_desc(); + auto input_layout = impl_param.get_input_layout(0); + + auto output_type = desc->output_data_types[0].value_or(input_layout.data_type); + if (impl_param.has_fused_primitives()) + output_type = impl_param.get_fused_output_layout().data_type; + + auto output_format = input_layout.format; + + ov::op::v0::SpaceToDepth op; + op.set_block_size(desc->block_size); + op.set_mode(desc->mode); + + std::vector output_shapes = { ShapeType() }; + std::vector input_shapes = { + input_layout.get() + }; + output_shapes = ov::op::v0::shape_infer(&op, input_shapes); + + return { layout{output_shapes[0], output_type, output_format} }; +} + +template std::vector space_to_depth_inst::calc_output_layouts(space_to_depth_node const& node, const kernel_impl_params& impl_param); + layout space_to_depth_inst::calc_output_layout(space_to_depth_node const& node, kernel_impl_params const& impl_param) { auto desc = impl_param.typed_desc(); @@ -26,7 +58,7 @@ layout space_to_depth_inst::calc_output_layout(space_to_depth_node const& node, output_type = impl_param.get_fused_output_layout().data_type; } - if (depth_mode != space_to_depth::depth_first && depth_mode != space_to_depth::blocks_first) + if (depth_mode != SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST && depth_mode != SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST) CLDNN_ERROR_MESSAGE(desc->id, "Invalid mode for spaceToDepth: must be \"blocks_first\" or \"depth_first\" only"); @@ -79,7 +111,7 @@ std::string space_to_depth_inst::to_string(space_to_depth_node const& node) { std::stringstream primitive_description; - std::string depth_mode = (desc->mode == cldnn::space_to_depth::depth_mode::blocks_first) ? + std::string depth_mode = (desc->mode == SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST) ? "blocks_first" : "depth_first"; diff --git a/src/plugins/intel_gpu/src/plugin/ops/space_to_depth.cpp b/src/plugins/intel_gpu/src/plugin/ops/space_to_depth.cpp index 762992dc092..5868ff6faf2 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/space_to_depth.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/space_to_depth.cpp @@ -11,23 +11,13 @@ namespace ov { namespace intel_gpu { - -static cldnn::space_to_depth::depth_mode GetDepthMode(ov::op::v0::SpaceToDepth::SpaceToDepthMode mode) { - switch (mode) { - case ov::op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST: return cldnn::space_to_depth::blocks_first; - case ov::op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST: return cldnn::space_to_depth::depth_first; - default: OPENVINO_THROW("[GPU] Unsupported SpaceToDepthMode value: ", static_cast(mode)); - } - return cldnn::space_to_depth::blocks_first; -} - static void CreateSpaceToDepthOp(ProgramBuilder& p, const std::shared_ptr& op) { validate_inputs_count(op, {1}); auto inputs = p.GetInputInfo(op); std::string layerName = layer_type_name_ID(op); auto spaceToDepthPrim = cldnn::space_to_depth(layerName, inputs[0], - GetDepthMode(op->get_mode()), + op->get_mode(), op->get_block_size()); p.add_primitive(*op, spaceToDepthPrim); diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/deth_to_space.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/depth_to_space.cpp similarity index 100% rename from src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/deth_to_space.cpp rename to src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/depth_to_space.cpp diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_depth.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_depth.cpp new file mode 100644 index 00000000000..2976a845e2a --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_depth.cpp @@ -0,0 +1,195 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/space_to_depth.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "ie_precision.hpp" +#include "ov_models/builders.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include + +using namespace ov::op::v0; +using namespace ov::test; + +namespace GPULayerTestsDefinitions { + +typedef std::tuple< + InputShape, // Input shape + ElementType, // Input element type + SpaceToDepth::SpaceToDepthMode, // Mode + std::size_t // Block size +> SpaceToDepthLayerGPUTestParams; + +class SpaceToDepthLayerGPUTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + InputShape shapes; + ElementType inType; + SpaceToDepth::SpaceToDepthMode mode; + std::size_t blockSize; + std::tie(shapes, inType, mode, blockSize) = obj.param; + + std::ostringstream results; + results << "IS=" << ov::test::utils::partialShape2str({shapes.first}) << "_"; + results << "TS="; + for (const auto& item : shapes.second) { + results << ov::test::utils::vec2str(item) << "_"; + } + results << "Prc=" << inType << "_"; + switch (mode) { + case SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST: + results << "BLOCKS_FIRST_"; + break; + case SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST: + results << "DEPTH_FIRST_"; + break; + default: + throw std::runtime_error("Unsupported SpaceToDepthMode"); + } + results << "BS=" << blockSize; + + return results.str(); + } + +protected: + void SetUp() override { + InputShape shapes; + SpaceToDepth::SpaceToDepthMode mode; + std::size_t blockSize; + std::tie(shapes, inType, mode, blockSize) = this->GetParam(); + + targetDevice = ov::test::utils::DEVICE_GPU; + init_input_shapes({shapes}); + + ov::ParameterVector params; + for (auto&& shape : inputDynamicShapes) + params.push_back(std::make_shared(inType, shape)); + + auto d2s = std::make_shared(params[0], mode, blockSize); + + ov::ResultVector results; + for (size_t i = 0; i < d2s->get_output_size(); i++) + results.push_back(std::make_shared(d2s->output(i))); + function = std::make_shared(results, params, "SpaceToDepth"); + } +}; + +TEST_P(SpaceToDepthLayerGPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + run(); +} + +namespace { + +const std::vector inputElementType = { + ElementType::f32, + ElementType::f16, + ElementType::i8 +}; + +const std::vector SpaceToDepthModes = { + SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, + SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST +}; + +// ======================== Static Shapes Tests ======================== +namespace static_shapes { + +const std::vector inputShapesBS2_4D = { + {1, 16, 8, 8}, + {1, 5, 8, 16}, + {2, 1, 8, 4}, + {1, 32, 4, 4}, + {2, 16, 64, 8} +}; + +const std::vector inputShapesBS3_4D = { + {1, 1, 27, 27}, + {1, 4, 9, 18}, + {3, 18, 9, 9}, + {2, 18, 3, 3} +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthStaticBS2_4D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(static_shapes_to_test_representation(inputShapesBS2_4D)), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 4)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthStaticBS3_4D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(static_shapes_to_test_representation(inputShapesBS3_4D)), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 3)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +const std::vector inputShapesBS2_5D = { + {1, 1, 4, 8, 8}, + {2, 5, 4, 8, 4}, + {4, 1, 4, 4, 4}, + {2, 1, 4, 20, 4}, + {2, 16, 4, 32, 4} +}; + +const std::vector inputShapesBS3_5D = { + {1, 3, 3, 6, 6}, + {1, 1, 9, 27, 27}, + {2, 1, 3, 3, 3}, + {1, 3, 27, 27, 27} +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthStaticBS2_5D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(static_shapes_to_test_representation(inputShapesBS2_5D)), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 4)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthStaticBS3_5D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(static_shapes_to_test_representation(inputShapesBS3_5D)), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 3)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +} // namespace static_shapes + +//======================== Dynamic Shapes Tests ======================== +namespace dynamic_shapes { + +const std::vector inputShapes4D = { + {{-1, -1, -1, -1}, {{2, 3, 12, 24}}}, +}; + +const std::vector inputShapes5D = { + {{-1, -1, -1, -1, -1}, {{2, 3, 2, 4, 8}}}, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthDynamic4D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(inputShapes4D), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 2, 3)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_GPUSpaceToDepthDynamic5D, SpaceToDepthLayerGPUTest, + testing::Combine( + testing::ValuesIn(inputShapes5D), + testing::ValuesIn(inputElementType), + testing::ValuesIn(SpaceToDepthModes), + testing::Values(1, 2)), + SpaceToDepthLayerGPUTest::getTestCaseName); + +} // namespace dynamic_shapes + +} // namespace +} // namespace GPULayerTestsDefinitions diff --git a/src/plugins/intel_gpu/tests/unit/fusions/space_to_depth_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/space_to_depth_fusion_test.cpp index a3513ec4b88..81f2de1dedd 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/space_to_depth_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/space_to_depth_fusion_test.cpp @@ -15,12 +15,13 @@ using namespace cldnn; using namespace ::tests; +using namespace ov::op::v0; namespace { struct space_to_depth_params { tensor input_size; tensor output_size; - space_to_depth::depth_mode mode; + SpaceToDepth::SpaceToDepthMode mode; data_types input_type; format input_format; size_t block_size; @@ -63,14 +64,14 @@ public: /* -------------------------------- SpaceToDepth cases ------------------------------------------------- */ /* ----------------------------------------------------------------------------------------------------- */ -#define CASE_SPACE_TO_DEPTH_F32_1 { 2, 2, 8, 10 }, { 2, 8, 4, 5 }, space_to_depth::depth_mode::blocks_first, data_types::f32, format::bfyx, 2, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_F32_2 { 1, 2, 6, 6, 6 }, { 1, 54, 2, 2, 2 }, space_to_depth::depth_mode::depth_first, data_types::f32, format::bfzyx, 3, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_F16_1 { 1, 3, 6, 6 }, { 1, 12, 3, 3 }, space_to_depth::depth_mode::blocks_first, data_types::f16, format::bfyx, 2, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_F16_2 { 2, 1, 3, 3 }, { 2, 9, 1, 1 }, space_to_depth::depth_mode::blocks_first, data_types::f16, format::b_fs_yx_fsv16, 3, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_U8_1 { 2, 2, 8, 10 }, { 2, 8, 4, 5 }, space_to_depth::depth_mode::blocks_first, data_types::u8, format::bfyx, 2, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_U8_2 { 1, 2, 6, 6, 6 }, { 1, 54, 2, 2, 2 }, space_to_depth::depth_mode::depth_first, data_types::u8, format::bfzyx, 3, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_I8_1 { 1, 3, 6, 6 }, { 1, 12, 3, 3 }, space_to_depth::depth_mode::blocks_first, data_types::i8, format::bfyx, 2, data_types::f32, format::bfyx -#define CASE_SPACE_TO_DEPTH_I8_2 { 2, 1, 3, 3 }, { 2, 9, 1, 1 }, space_to_depth::depth_mode::blocks_first, data_types::i8, format::b_fs_yx_fsv16, 3, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_F32_1 { 2, 2, 8, 10 }, { 2, 8, 4, 5 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::f32, format::bfyx, 2, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_F32_2 { 1, 2, 6, 6, 6 }, { 1, 54, 2, 2, 2 }, SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, data_types::f32, format::bfzyx, 3, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_F16_1 { 1, 3, 6, 6 }, { 1, 12, 3, 3 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::f16, format::bfyx, 2, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_F16_2 { 2, 1, 3, 3 }, { 2, 9, 1, 1 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::f16, format::b_fs_yx_fsv16, 3, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_U8_1 { 2, 2, 8, 10 }, { 2, 8, 4, 5 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::u8, format::bfyx, 2, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_U8_2 { 1, 2, 6, 6, 6 }, { 1, 54, 2, 2, 2 }, SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, data_types::u8, format::bfzyx, 3, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_I8_1 { 1, 3, 6, 6 }, { 1, 12, 3, 3 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::i8, format::bfyx, 2, data_types::f32, format::bfyx +#define CASE_SPACE_TO_DEPTH_I8_2 { 2, 1, 3, 3 }, { 2, 9, 1, 1 }, SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, data_types::i8, format::b_fs_yx_fsv16, 3, data_types::f32, format::bfyx class space_to_depth_quantize_i8 : public SpaceToDepthFusingsTest {}; TEST_P(space_to_depth_quantize_i8, basic) { diff --git a/src/plugins/intel_gpu/tests/unit/shape_infer/space_to_depth_si_test.cpp b/src/plugins/intel_gpu/tests/unit/shape_infer/space_to_depth_si_test.cpp new file mode 100644 index 00000000000..1fad8eb632e --- /dev/null +++ b/src/plugins/intel_gpu/tests/unit/shape_infer/space_to_depth_si_test.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils.h" + +#include +#include +#include + +#include "space_to_depth_inst.h" + +#include "program_wrapper.h" + +#include +#include + +using namespace cldnn; +using namespace ::tests; + +namespace shape_infer_tests { + +struct space_to_depth_test_params { + layout input_layout; + size_t block_size; + layout expected_layout; +}; + +class space_to_depth_si_test : public testing::TestWithParam { }; + +TEST_P(space_to_depth_si_test, shape_infer) { + auto p = GetParam(); + + auto& engine = get_test_engine(); + + auto input_layout_prim = std::make_shared("input", p.input_layout); + auto space_to_depth_prim = std::make_shared("space_to_depth", input_info("input"), + SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, p.block_size); + + cldnn::program prog(engine); + auto& input_layout_node = prog.get_or_create(input_layout_prim); + auto& space_to_depth_node = prog.get_or_create(space_to_depth_prim); + program_wrapper::add_connection(prog, input_layout_node, space_to_depth_node); + auto res = space_to_depth_inst::calc_output_layouts(space_to_depth_node, *space_to_depth_node.get_kernel_impl_params()); + + ASSERT_EQ(res.size(), 1); + ASSERT_EQ(res[0], p.expected_layout); +} + +INSTANTIATE_TEST_SUITE_P(smoke, space_to_depth_si_test, + testing::ValuesIn(std::vector{ + { + layout{ov::PartialShape{4, 2, 4, 8}, data_types::f16, format::bfyx}, 4, layout{ov::PartialShape{4, 32, 1, 2}, data_types::f16, format::bfyx} + }, + { + layout{ov::PartialShape::dynamic(4), data_types::f32, format::bfyx}, 2, layout{ov::PartialShape::dynamic(4), data_types::f32, format::bfyx} + } + })); + +} // shape_infer_tests \ No newline at end of file diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/space_to_depth_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/space_to_depth_gpu_test.cpp index 5847642b660..df859e569bc 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/space_to_depth_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/space_to_depth_gpu_test.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/op/space_to_depth.hpp" #include "test_utils.h" #include @@ -33,7 +34,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -75,7 +76,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -123,7 +124,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -185,7 +186,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -233,7 +234,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -275,7 +276,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -323,7 +324,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -385,7 +386,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -435,7 +436,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -474,7 +475,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -522,7 +523,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -576,7 +577,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::blocks_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -623,7 +624,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -662,7 +663,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -710,7 +711,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -764,7 +765,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add( - space_to_depth("space_to_depth", input_info("Input0"), space_to_depth::depth_first, block_size) + space_to_depth("space_to_depth", input_info("Input0"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size) ); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -819,7 +820,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add(reorder("reorder", input_info("Input0"), format::b_fs_yx_fsv16, data_types::f32)); - topology.add(space_to_depth("space_to_depth", input_info("reorder"), space_to_depth::depth_first, block_size)); + topology.add(space_to_depth("space_to_depth", input_info("reorder"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size)); topology.add(reorder("reorder_out", input_info("space_to_depth"), format::bfyx, data_types::f32)); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test); @@ -874,7 +875,7 @@ public: topology topology; topology.add(input_layout("Input0", input1->get_layout())); topology.add(reorder("reorder", input_info("Input0"), format::b_fs_yx_fsv4, data_types::f32)); - topology.add(space_to_depth("space_to_depth", input_info("reorder"), space_to_depth::depth_first, block_size)); + topology.add(space_to_depth("space_to_depth", input_info("reorder"), SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, block_size)); topology.add(reorder("reorder_out", input_info("space_to_depth"), format::bfyx, data_types::f32)); cldnn::network::ptr network = get_network(engine, topology, get_test_default_config(engine), get_test_stream_ptr(), is_caching_test);