From 3a1f45e70e34f2f44f684b2e6ed161784b183139 Mon Sep 17 00:00:00 2001 From: Wilson Seok Date: Fri, 4 Aug 2023 02:37:41 +0900 Subject: [PATCH] [GPU] fix normalize dynamic shape support (#18956) * fix normalize dynamic shape support * remove redundant code --- src/plugins/intel_gpu/src/graph/normalize.cpp | 2 + .../dynamic/normalize_l2.cpp | 209 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/normalize_l2.cpp diff --git a/src/plugins/intel_gpu/src/graph/normalize.cpp b/src/plugins/intel_gpu/src/graph/normalize.cpp index 6a17bfdad29..8eb9893ffe6 100644 --- a/src/plugins/intel_gpu/src/graph/normalize.cpp +++ b/src/plugins/intel_gpu/src/graph/normalize.cpp @@ -49,6 +49,8 @@ std::string normalize_inst::to_string(normalize_node const& node) { } normalize_inst::typed_primitive_inst(network& network, normalize_node const& node) : parent(network, node) { + if (node.input().is_dynamic() || node.scale().is_dynamic()) + return; /// Scale f dimension should be 1 (if all channels have the same scale) or equal to input feature size (one scale per channel). auto scale_layout = node.scale().get_output_layout(); auto scale_size = scale_layout.get_tensor(); diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/normalize_l2.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/normalize_l2.cpp new file mode 100644 index 00000000000..2f16be4d118 --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/normalize_l2.cpp @@ -0,0 +1,209 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "ngraph_functions/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +using namespace InferenceEngine; +using namespace ov::test; + +namespace GPULayerTestsDefinitions { + +using NormalizeL2LayerGPUTestParams = std::tuple< + InputShape, // Input shapes + ElementType, // Input precision + std::vector, // Reduction axes + ngraph::op::EpsMode, // EpsMode + float>; // Epsilon + +class NormalizeL2LayerGPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + InputShape inputShapes; + ElementType netPrecision; + std::vector axes; + ngraph::op::EpsMode epsMode; + float eps; + std::tie(inputShapes, netPrecision, axes, epsMode, eps) = obj.param; + + std::ostringstream result; + result << "IS=" << ov::test::utils::partialShape2str({inputShapes.first}) << "_"; + result << "TS="; + for (const auto& shape : inputShapes.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "Precision=" << netPrecision << "_"; + result << "ReductionAxes=" << ov::test::utils::vec2str(axes) << "_"; + result << "EpsMode=" << epsMode << "_"; + result << "Epsilon=" << eps; + + return result.str(); + } +protected: + void SetUp() override { + targetDevice = ov::test::utils::DEVICE_GPU; + + InputShape inputShapes; + ElementType netPrecision; + std::vector axes; + ngraph::op::EpsMode epsMode; + float eps; + std::tie(inputShapes, netPrecision, axes, epsMode, eps) = this->GetParam(); + + init_input_shapes({inputShapes}); + + auto param = ngraph::builder::makeDynamicParams(netPrecision, inputDynamicShapes); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(param)); + auto normalize = ngraph::builder::makeNormalizeL2(paramOuts[0], axes, eps, epsMode); + + ngraph::ResultVector results{std::make_shared(normalize)}; + function = std::make_shared(results, param, "NormalizeL2"); + } +}; + +TEST_P(NormalizeL2LayerGPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + run(); +} + +namespace { + +const std::vector inputShapes_1D = { + { + // dynamic + {{1, 20}}, + // target + { + {1}, + {16}, + {4}, + {16} + } + } +}; + +const std::vector inputShapes_3D = { + { + // dynamic + {-1, -1, -1}, + // target + { + {2, 16, 6}, + {4, 16, 2}, + {2, 16, 6}, + {4, 16, 2} + } + }, + { + // dynamic + {{1, 5}, {1, 20}, {1, 7}}, + // target + { + {1, 1, 1}, + {2, 16, 6}, + {4, 16, 2}, + {2, 16, 6} + } + } +}; + +const std::vector inputShapes_4D = { + { + // dynamic + {-1, -1, -1, -1}, + // target + { + {2, 16, 10, 6}, + {4, 16, 2, 2}, + {2, 16, 10, 6}, + {4, 16, 2, 2} + } + }, + { + // dynamic + {{1, 5}, {1, 20}, {1, 10}, {1, 7}}, + // target + { + {1, 1, 1, 1}, + {2, 16, 10, 6}, + {4, 16, 2, 2}, + {2, 16, 10, 6} + } + } +}; + +const std::vector inputShapes_5D = { + { + // dynamic + {-1, -1, -1, -1, -1}, + // target + { + {2, 16, 5, 10, 6}, + {4, 16, 7, 2, 2}, + {2, 16, 5, 10, 6}, + {4, 16, 7, 2, 2} + } + }, + { + // dynamic + {{1, 5}, {1, 20}, {1, 7}, {1, 10}, {1, 7}}, + // target + { + {1, 1, 1, 1, 1}, + {2, 16, 5, 10, 6}, + {4, 16, 7, 2, 2}, + {2, 16, 5, 10, 6} + } + } +}; + +const std::vector epsMode = { + ngraph::op::EpsMode::ADD, ngraph::op::EpsMode::MAX +}; + +const std::vector epsilon = { + 0.000000001 +}; + +const std::vector reduction_axes_1234 = {1, 2, 3, 4}; +const std::vector reduction_axes_234 = {2, 3, 4}; +const std::vector reduction_axes_123 = {1, 2, 3}; +const std::vector reduction_axes_23 = {2, 3}; +const std::vector reduction_axes_12 = {1, 2}; +const std::vector reduction_axes_3 = {3}; +const std::vector reduction_axes_2 = {2}; + +std::vector nrtPrecision = {ElementType::f16, ElementType::f32}; + +const auto NormalizeL2_3D = ::testing::Combine( + ::testing::ValuesIn(inputShapes_3D), + ::testing::ValuesIn(nrtPrecision), + ::testing::ValuesIn({reduction_axes_12, reduction_axes_2}), + ::testing::ValuesIn(epsMode), + ::testing::ValuesIn(epsilon)); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_3D, NormalizeL2LayerGPUTest, NormalizeL2_3D, NormalizeL2LayerGPUTest::getTestCaseName); + +const auto NormalizeL2_4D = ::testing::Combine( + ::testing::ValuesIn(inputShapes_4D), + ::testing::ValuesIn(nrtPrecision), + ::testing::ValuesIn({reduction_axes_2, reduction_axes_3, reduction_axes_12, reduction_axes_23, reduction_axes_123}), + ::testing::ValuesIn(epsMode), + ::testing::ValuesIn(epsilon)); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_4D, NormalizeL2LayerGPUTest, NormalizeL2_4D, NormalizeL2LayerGPUTest::getTestCaseName); + +const auto NormalizeL2_5D = ::testing::Combine( + ::testing::ValuesIn(inputShapes_5D), + ::testing::ValuesIn(nrtPrecision), + ::testing::ValuesIn({reduction_axes_3, reduction_axes_23, reduction_axes_123, reduction_axes_1234}), + ::testing::ValuesIn(epsMode), + ::testing::ValuesIn(epsilon)); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_5D, NormalizeL2LayerGPUTest, NormalizeL2_5D, NormalizeL2LayerGPUTest::getTestCaseName); + +} // namespace +} // namespace GPULayerTestsDefinitions