From 476dc0f00feab2799cad260447e3692255cb6709 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Tue, 7 Jul 2020 11:47:13 +0300 Subject: [PATCH] [IE TESTS] Add Convert, ConvertLike single layer tests. Refactoring `Range` (#1212) --- .../single_layer_tests/convert.cpp | 30 ++++++++++++++ .../single_layer_tests/convert_like.cpp | 31 ++++++++++++++ .../shared_tests_instances/skip_tests_config.cpp | 9 +++- .../subgraph_tests/range_add.cpp | 44 ++++++++++++++++++++ .../shared/include/single_layer_tests/convert.hpp | 33 +++++++++++++++ .../include/single_layer_tests/convert_like.hpp | 34 +++++++++++++++ .../shared/include/single_layer_tests/range.hpp | 2 + .../shared/include/subgraph_tests/range_add.hpp | 26 ++++++++++++ .../shared/src/single_layer_tests/convert.cpp | 46 +++++++++++++++++++++ .../shared/src/single_layer_tests/convert_like.cpp | 48 ++++++++++++++++++++++ .../plugin/shared/src/single_layer_tests/range.cpp | 30 +++++++++++--- .../plugin/shared/src/subgraph_tests/range_add.cpp | 45 ++++++++++++++++++++ .../functional_test_utils/layer_test_utils.hpp | 4 +- 13 files changed, 373 insertions(+), 9 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert_like.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/range_add.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert_like.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert_like.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/subgraph_tests/range_add.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert.cpp new file mode 100644 index 0000000..7ba3db9 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "single_layer_tests/convert.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector> inShape = {{1, 2, 3, 4}}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::U8, + InferenceEngine::Precision::I8, +}; + +INSTANTIATE_TEST_CASE_P(NoReshape, ConvertLayerTest, + ::testing::Combine( + ::testing::Values(inShape), + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ConvertLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert_like.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert_like.cpp new file mode 100644 index 0000000..f4b0e4a --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert_like.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "single_layer_tests/convert_like.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector> inShape = {{1, 2, 3, 4}}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16, + InferenceEngine::Precision::U8, + InferenceEngine::Precision::I8, +}; + +INSTANTIATE_TEST_CASE_P(NoReshape, ConvertLikeLayerTest, + ::testing::Combine( + ::testing::Values(inShape), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(inShape), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ConvertLikeLayerTest::getTestCaseName); + +} // namespace \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index 5d378d9..b9b4b40 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -31,13 +31,18 @@ std::vector disabledTestPatterns() { R"(.*Reduce.*type=Logical.*)", R"(.*Reduce.*axes=\(1\.-1\).*)", R"(.*Reduce.*axes=\(0\.3\)_type=Prod.*)", - // TODO: Issue 34055 + // TODO: Issue: 34518 R"(.*RangeLayerTest.*)", - // TODO: Issue 34092 + R"(.*(RangeAddSubgraphTest).*Start=1.2.*Stop=(5.2|-5.2).*Step=(0.1|-0.1).*netPRC=FP16.*)", + // TODO: Issue: 34083 #if (defined(_WIN32) || defined(_WIN64)) R"(.*(CoreThreadingTestsWithIterations).*(smoke_LoadNetworkAccuracy).*)", #endif // TODO: Issue: 34348 R"(.*IEClassGetAvailableDevices.*)", + // TODO: Issue: 25533 + R"(.*ConvertLikeLayerTest.*)", + //TODO: Issue: 34516 + R"(.*ConvertLayerTest.*)", }; } \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/range_add.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/range_add.cpp new file mode 100644 index 0000000..d51a2a8 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/range_add.cpp @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "subgraph_tests/range_add.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + +const std::vector positiveStart = { 1.0f, 1.2f }; +const std::vector positiveStop = { 5.0f, 5.2f }; +const std::vector positiveStep = { 1.0f, 0.1f }; + +const std::vector negativeStart = { 1.0f, 1.2f }; +const std::vector negativeStop = { -5.0f, -5.2f }; +const std::vector negativeStep = { -1.0f, -0.1f }; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +INSTANTIATE_TEST_CASE_P(BasicPositive, RangeAddSubgraphTest, + ::testing::Combine( + ::testing::ValuesIn(positiveStart), + ::testing::ValuesIn(positiveStop), + ::testing::ValuesIn(positiveStep), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + RangeAddSubgraphTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(BasicNegative, RangeAddSubgraphTest, + ::testing::Combine( + ::testing::ValuesIn(negativeStart), + ::testing::ValuesIn(negativeStop), + ::testing::ValuesIn(negativeStep), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + RangeAddSubgraphTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert.hpp new file mode 100644 index 0000000..960f6cd --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "functional_test_utils/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LayerTestsDefinitions { + +using ConvertParamsTuple = typename std::tuple< + std::vector>, // Input shapes + InferenceEngine::Precision, // Source precision + InferenceEngine::Precision, // Target precision + std::string>; // Device name + +class ConvertLayerTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; + +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert_like.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert_like.hpp new file mode 100644 index 0000000..9db66c9 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/convert_like.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "functional_test_utils/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LayerTestsDefinitions { + +using ConvertLikeParamsTuple = typename std::tuple< + std::vector>, // Input1 shapes + InferenceEngine::Precision, // Input1 precision + std::vector>, // Input2 shapes + InferenceEngine::Precision, // Input2 precision + std::string>; // Device name + +class ConvertLikeLayerTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo &obj); + +protected: + void SetUp() override; +}; + +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/range.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/range.hpp index 0beb2d9..e89140e 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/range.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/range.hpp @@ -23,8 +23,10 @@ typedef std::tuple< class RangeLayerTest : public testing::WithParamInterface, public LayerTestsUtils::LayerTestsCommon { + float start, stop, step; public: static std::string getTestCaseName(testing::TestParamInfo obj); + void Infer(); protected: void SetUp() override; diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp new file mode 100644 index 0000000..1137a02 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/range_add.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "functional_test_utils/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" + +#include "single_layer_tests/range.hpp" + +namespace LayerTestsDefinitions { + +class RangeAddSubgraphTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); +protected: + void SetUp() override; +}; +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert.cpp new file mode 100644 index 0000000..132ef96 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/precision_utils.hpp" +#include "functional_test_utils/skip_tests_config.hpp" + +#include "single_layer_tests/convert.hpp" + +namespace LayerTestsDefinitions { + +std::string ConvertLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + InferenceEngine::Precision inputPrecision, targetPrecision; + std::string targetName; + std::vector> inputShape; + std::tie(inputShape, inputPrecision, targetPrecision, targetName) = obj.param; + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; + result << "targetPRC=" << targetPrecision.name() << "_"; + result << "inputPRC=" << inputPrecision.name() << "_"; + result << "targetDevice=" << targetName; + return result.str(); +} + +void ConvertLayerTest::SetUp() { + InferenceEngine::Precision inputPrecision, targetPrecision; + std::vector> inputShape; + std::tie(inputShape, inputPrecision, targetPrecision, targetDevice) = GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); + auto targetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(targetPrecision); + auto params = ngraph::builder::makeParams(ngPrc, inputShape); + auto convert = std::make_shared(params.front(), targetPrc); + ngraph::ResultVector results{std::make_shared(convert)}; + function = std::make_shared(results, params, "Convert"); +} + +TEST_P(ConvertLayerTest, CompareWithRefs) { + Run(); +}; +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert_like.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert_like.cpp new file mode 100644 index 0000000..04d674b --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/convert_like.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/precision_utils.hpp" +#include "functional_test_utils/skip_tests_config.hpp" + +#include "single_layer_tests/convert_like.hpp" + +namespace LayerTestsDefinitions { + +std::string ConvertLikeLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { + InferenceEngine::Precision precision, targetPrecision; + std::vector> inputShape1, inputShape2; + std::string targetName; + std::tie(inputShape1, precision, inputShape2, targetPrecision, targetName) = obj.param; + std::ostringstream result; + result << "IS1=" << CommonTestUtils::vec2str(inputShape1) << "_"; + result << "IS2=" << CommonTestUtils::vec2str(inputShape2) << "_"; + result << "PRC1=" << precision.name() << "_"; + result << "PRC2=" << targetPrecision.name() << "_"; + result << "targetDevice=" << targetName; + return result.str(); +} + +void ConvertLikeLayerTest::SetUp() { + InferenceEngine::Precision inputPrecision, targetPrecision; + std::vector> inputShape1, inputShape2; + std::tie(inputShape1, inputPrecision, inputShape2, targetPrecision, targetDevice) = GetParam(); + auto ngPrc1 = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputPrecision); + auto targetPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(targetPrecision); + auto params = ngraph::builder::makeParams(ngPrc1, inputShape1); + params.push_back(ngraph::builder::makeParams(targetPrc, inputShape2).front()); + auto convertLike = std::make_shared(params.front(), params.back()); + ngraph::ResultVector results{std::make_shared(convertLike)}; + function = std::make_shared(results, params, "ConvertLike"); +} + +TEST_P(ConvertLikeLayerTest, CompareWithRefs) { + Run(); +}; +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/range.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/range.cpp index 061cb1d..544c96b 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/range.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/range.cpp @@ -11,12 +11,12 @@ #include "ie_precision.hpp" -#include "common_test_utils/common_utils.hpp" #include "functional_test_utils/layer_test_utils.hpp" #include "single_layer_tests/range.hpp" namespace LayerTestsDefinitions { + std::string RangeLayerTest::getTestCaseName(testing::TestParamInfo obj) { InferenceEngine::Precision netPrecision; float start, stop, step; @@ -33,17 +33,37 @@ std::string RangeLayerTest::getTestCaseName(testing::TestParamInfo return result.str(); } +void RangeLayerTest::Infer() { + inferRequest = executableNetwork.CreateInferRequest(); + inputs.clear(); + + auto blobStart = inferRequest.GetBlob("start"); + blobStart = FuncTestUtils::createAndFillBlobWithFloatArray(blobStart->getTensorDesc(), &start, 1); + + auto blobStop = inferRequest.GetBlob("stop"); + blobStop = FuncTestUtils::createAndFillBlobWithFloatArray(blobStop->getTensorDesc(), &stop, 1); + + auto blobStep = inferRequest.GetBlob("step"); + blobStep = FuncTestUtils::createAndFillBlobWithFloatArray(blobStep->getTensorDesc(), &step, 1); + + inferRequest.Infer(); +} + void RangeLayerTest::SetUp() { InferenceEngine::Precision netPrecision; - float start, stop, step; std::tie(start, stop, step, netPrecision, targetDevice) = GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - std::vector inShape; - auto params = ngraph::builder::makeParams(ngPrc, {inShape}); + auto start_constant = std::make_shared(ngPrc, ngraph::Shape{}, start); auto stop_constant = std::make_shared(ngPrc, ngraph::Shape{}, stop); auto step_constant = std::make_shared(ngPrc, ngraph::Shape{}, step); - auto range = std::make_shared(start_constant, stop_constant, step_constant); + + auto params = ngraph::builder::makeParams(ngPrc, {std::vector(), std::vector(), std::vector()}); + params[0]->set_friendly_name("start"); + params[1]->set_friendly_name("stop"); + params[2]->set_friendly_name("step"); + + auto range = std::make_shared(params[0], params[1], params[2]); const ngraph::ResultVector results{std::make_shared(range)}; function = std::make_shared(results, params, "Range"); } diff --git a/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/range_add.cpp b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/range_add.cpp new file mode 100644 index 0000000..19506e4 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/range_add.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "subgraph_tests/range_add.hpp" + +namespace LayerTestsDefinitions { + +std::string RangeAddSubgraphTest::getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + float start, stop, step; + std::string targetDevice; + std::tie(start, stop, step, netPrecision, targetDevice) = obj.param; + + std::ostringstream result; + const char separator = '_'; + result << "Start=" << start << separator; + result << "Stop=" << stop << separator; + result << "Step=" << step << separator; + result << "netPRC=" << netPrecision.name() << separator; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void RangeAddSubgraphTest::SetUp() { + InferenceEngine::Precision netPrecision; + float start, stop, step; + std::tie(start, stop, step, netPrecision, targetDevice) = GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + auto startConstant = std::make_shared(ngPrc, ngraph::Shape{}, start); + auto stopConstant = std::make_shared(ngPrc, ngraph::Shape{}, stop); + auto stepConstant = std::make_shared(ngPrc, ngraph::Shape{}, step); + auto range = std::make_shared(startConstant, stopConstant, stepConstant); + + auto params = ngraph::builder::makeParams(ngPrc, {range->get_shape()}); + auto eltwise = ngraph::builder::makeEltwise(params.front(), range, ngraph::helpers::EltwiseTypes::ADD); + const ngraph::ResultVector results{std::make_shared(eltwise)}; + function = std::make_shared(results, params, "RangeEltwise"); +} + +TEST_P(RangeAddSubgraphTest, CompareWithRefs) { + Run(); +} +} // namespace LayerTestsDefinitions \ No newline at end of file diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp index 564ba18..7b06129 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_test_utils.hpp @@ -107,13 +107,13 @@ protected: virtual std::vector> CalculateRefs(); + InferenceEngine::InferRequest inferRequest; + private: void ConfigureNetwork() const; std::vector GetOutputs(); - std::shared_ptr core; - InferenceEngine::InferRequest inferRequest; RefMode refMode = RefMode::INTERPRETER; }; -- 2.7.4