From 11f1c138decd153f8235e57828b59d3a01b20d1a Mon Sep 17 00:00:00 2001 From: Kelvin Choi Date: Wed, 11 Jan 2023 04:25:14 +0900 Subject: [PATCH] [GPU] Add dynamic func tests for shapeof op (#14923) --- .../single_layer_tests/dynamic/shapeof.cpp | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 src/tests/functional/plugin/gpu/single_layer_tests/dynamic/shapeof.cpp diff --git a/src/tests/functional/plugin/gpu/single_layer_tests/dynamic/shapeof.cpp b/src/tests/functional/plugin/gpu/single_layer_tests/dynamic/shapeof.cpp new file mode 100644 index 00000000000..13990a89fe6 --- /dev/null +++ b/src/tests/functional/plugin/gpu/single_layer_tests/dynamic/shapeof.cpp @@ -0,0 +1,171 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/single_layer/shape_of.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "ie_precision.hpp" +#include "ngraph_functions/builders.hpp" +#include + +using namespace ngraph; +using namespace InferenceEngine; +using namespace ov::test; + +using ElementType = ov::element::Type_t; + +namespace GPULayerTestsDefinitions { +typedef std::tuple< + InputShape, + ElementType // Net precision +> ShapeOfLayerGPUTestParamsSet; + +class ShapeOfLayerGPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + InputShape inputShape; + ElementType netPrecision; + std::tie(inputShape, netPrecision) = obj.param; + + std::ostringstream result; + result << "ShapeOfTest_"; + result << std::to_string(obj.index) << "_"; + result << "netPrec=" << netPrecision << "_"; + result << "IS="; + result << CommonTestUtils::partialShape2str({inputShape.first}) << "_"; + result << "TS=("; + for (const auto& shape : inputShape.second) { + result << CommonTestUtils::vec2str(shape) << "_"; + } + result << ")"; + return result.str(); + } +protected: + void SetUp() override { + targetDevice = CommonTestUtils::DEVICE_GPU; + + auto netPrecision = ElementType::undefined; + InputShape inputShape; + std::tie(inputShape, netPrecision) = this->GetParam(); + + init_input_shapes({inputShape}); + + inType = ov::element::Type(netPrecision); + outType = ElementType::i32; + + auto functionParams = builder::makeDynamicParams(inType, inputDynamicShapes); + auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(functionParams)); + auto shapeOfOp = std::make_shared(paramOuts[0], element::i32); + + auto makeFunction = [](ParameterVector ¶ms, const std::shared_ptr &lastNode) { + ResultVector results; + + for (int i = 0; i < lastNode->get_output_size(); i++) + results.push_back(std::make_shared(lastNode->output(i))); + + return std::make_shared(results, params, "ShapeOfLayerGPUTest"); + }; + + function = makeFunction(functionParams, shapeOfOp); + } +}; + +TEST_P(ShapeOfLayerGPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + run(); +} + +namespace { + +const std::vector netPrecisions = { + ElementType::i32, +}; + +// We don't check static case, because of constant folding + +// ============================================================================== +// 3D +std::vector inShapesDynamic3d = { + { + {-1, -1, -1}, + { + { 8, 5, 4 }, + { 8, 5, 3 }, + { 8, 5, 2 } + } + }, + { + {-1, -1, -1}, + { + { 1, 2, 4 }, + { 1, 2, 3 }, + { 1, 2, 2 } + } + } +}; +INSTANTIATE_TEST_SUITE_P(smoke_ShapeOf_3d_compareWithRefs_dynamic, + ShapeOfLayerGPUTest, + ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic3d), + ::testing::ValuesIn(netPrecisions)), + ShapeOfLayerGPUTest::getTestCaseName); + +// ============================================================================== +// 4D +std::vector inShapesDynamic4d = { + { + {-1, -1, -1, -1}, + { + { 8, 5, 3, 4 }, + { 8, 5, 3, 3 }, + { 8, 5, 3, 2 } + } + }, + { + {-1, -1, -1, -1}, + { + { 1, 2, 3, 4 }, + { 1, 2, 3, 3 }, + { 1, 2, 3, 2 } + } + } +}; +INSTANTIATE_TEST_SUITE_P(smoke_ShapeOf_4d_compareWithRefs_dynamic, + ShapeOfLayerGPUTest, + ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic4d), + ::testing::ValuesIn(netPrecisions)), + ShapeOfLayerGPUTest::getTestCaseName); + +// ============================================================================== +// 5D +std::vector inShapesDynamic5d = { + { + { -1, -1, -1, -1, -1 }, + { + { 8, 5, 3, 2, 4 }, + { 8, 5, 3, 2, 3 }, + { 8, 5, 3, 2, 2 } + } + }, + { + {-1, -1, -1, -1, -1}, + { + { 1, 2, 3, 4, 4 }, + { 1, 2, 3, 4, 3 }, + { 1, 2, 3, 4, 2 } + } + } +}; +INSTANTIATE_TEST_SUITE_P(smoke_ShapeOf_5d_compareWithRefs_dynamic, + ShapeOfLayerGPUTest, + ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic5d), + ::testing::ValuesIn(netPrecisions)), + ShapeOfLayerGPUTest::getTestCaseName); + +} // namespace + +} // namespace GPULayerTestsDefinitions