From 6fdd983750ec79bd5787456b01b1ccad59cbac10 Mon Sep 17 00:00:00 2001 From: Andrey Noskov Date: Fri, 11 Mar 2022 15:05:14 +0300 Subject: [PATCH] [GNA] Added multi crop test (#10459) --- .../subgraph_tests/multi_crops_to_concat.cpp | 53 ++++++++++++++ .../subgraph_tests/multi_crops_to_concat.hpp | 13 ++++ .../subgraph/multi_crops_to_concat.hpp | 35 ++++++++++ .../src/subgraph/multi_crops_to_concat.cpp | 69 +++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 src/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp create mode 100644 src/tests/functional/plugin/shared/include/subgraph_tests/multi_crops_to_concat.hpp create mode 100644 src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multi_crops_to_concat.hpp create mode 100644 src/tests/functional/shared_test_classes/src/subgraph/multi_crops_to_concat.cpp diff --git a/src/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp b/src/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp new file mode 100644 index 00000000000..28922712f7f --- /dev/null +++ b/src/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/multi_crops_to_concat.cpp @@ -0,0 +1,53 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "common_test_utils/test_constants.hpp" + +namespace SubgraphTestsDefinitions { +namespace { +const std::vector> input_shapes = { + {1, 48}, + {1, 64} +}; + +const std::vector>> offsets = { + { + {0, 16}, + {33, 48} + }, + { + {17, 32}, + {33, 48} + }, + { + {5, 14}, + {17, 26} + }, + { + {1, 8}, + {9, 16}, + {17, 24} + } +}; + +const std::vector> additional_config = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_FP32"} + } +}; +} // namespace + +INSTANTIATE_TEST_SUITE_P(smoke_multi_crop_to_concat, MultiCropsToConcatTest, + ::testing::Combine( + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(input_shapes), + ::testing::ValuesIn(offsets), + ::testing::ValuesIn(additional_config)), + MultiCropsToConcatTest::getTestCaseName); +} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/multi_crops_to_concat.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/multi_crops_to_concat.hpp new file mode 100644 index 00000000000..70abb43f52b --- /dev/null +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/multi_crops_to_concat.hpp @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/subgraph/multi_crops_to_concat.hpp" + +namespace SubgraphTestsDefinitions { + +TEST_P(MultiCropsToConcatTest, CompareWithRefs) { + Run(); +}; + +} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multi_crops_to_concat.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multi_crops_to_concat.hpp new file mode 100644 index 00000000000..98728f7f7a0 --- /dev/null +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/multi_crops_to_concat.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" +#include "ngraph_functions/builders.hpp" + +namespace SubgraphTestsDefinitions { + +typedef std::tuple< + InferenceEngine::Precision, // Network Precision + std::string, // Target Device + std::vector, // Input Shapes + std::vector>, // Offset pairs (begin, end) + std::map // Configuration +> MultiCropsToConcatParams; + + +class MultiCropsToConcatTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; +}; +} // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/subgraph/multi_crops_to_concat.cpp b/src/tests/functional/shared_test_classes/src/subgraph/multi_crops_to_concat.cpp new file mode 100644 index 00000000000..489a8917cbc --- /dev/null +++ b/src/tests/functional/shared_test_classes/src/subgraph/multi_crops_to_concat.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "shared_test_classes/subgraph/multi_crops_to_concat.hpp" +#include "ngraph_functions/builders.hpp" + +namespace SubgraphTestsDefinitions { + +std::string MultiCropsToConcatTest::getTestCaseName(const testing::TestParamInfo& obj) { + InferenceEngine::Precision netPrecision; + std::string targetDevice; + std::map configuration; + std::vector inputShape; + std::vector> offsets; + std::tie(netPrecision, targetDevice, inputShape, offsets, configuration) = obj.param; + + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + result << "offset="; + for (auto offset : offsets) { + result << "(" << offset.first << "," << offset.second << ")"; + } + for (auto const& configItem : configuration) { + result << "_configItem=" << configItem.first << "_" << configItem.second; + } + return result.str(); +} + +void MultiCropsToConcatTest::SetUp() { + InferenceEngine::Precision netPrecision; + std::map tempConfig; + std::vector inputShape; + std::vector> offsets; + std::tie(netPrecision, targetDevice, inputShape, offsets, tempConfig) = this->GetParam(); + configuration.insert(tempConfig.begin(), tempConfig.end()); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, { inputShape }); + + auto crop1 = ngraph::builder::makeStridedSlice(params[0], std::vector{0, offsets[0].first}, std::vector{1, offsets[0].second}, + std::vector{1, 1}, ngPrc, std::vector{1, 0}, + std::vector{1, 0}, std::vector{0, 0}, + std::vector{0, 0}, std::vector{0, 0}); + + auto crop2 = ngraph::builder::makeStridedSlice(params[0], std::vector{0, offsets[1].first}, std::vector{1, offsets[1].second}, + std::vector{1, 1}, ngPrc, std::vector{1, 0}, + std::vector{1, 0}, std::vector{0, 0}, + std::vector{0, 0}, std::vector{0, 0}); + + auto concat1 = std::make_shared(ngraph::OutputVector{crop1, crop2}, 1); + std::shared_ptr result; + + // Case with 3 crops + if (offsets.size() == 3) { + auto crop3 = ngraph::builder::makeStridedSlice(params[0], std::vector{0, offsets[2].first}, std::vector{1, offsets[2].second}, + std::vector{1, 1}, ngPrc, std::vector{1, 0}, + std::vector{1, 0}, std::vector{0, 0}, + std::vector{0, 0}, std::vector{0, 0}); + auto concat2 = std::make_shared(ngraph::OutputVector{crop1, crop2}, 1); + result = std::make_shared(concat2); + } else { + result = std::make_shared(concat1); + } + function = std::make_shared(result, params, "InputSplitConcatTest"); +} +} // namespace SubgraphTestsDefinitions