From 6839ef769924b9e85af3a0e00b3d125345c26013 Mon Sep 17 00:00:00 2001 From: Liubov Batanina Date: Mon, 21 Sep 2020 11:37:22 +0300 Subject: [PATCH] Add TopK tests (#2165) --- .../single_layer_tests/topk.cpp | 52 ++++++++++++++++++ .../skip_tests_config.cpp | 5 +- .../include/single_layer_tests/topk.hpp | 33 ++++++++++++ .../shared/src/single_layer_tests/topk.cpp | 54 +++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp new file mode 100644 index 00000000000..b73c929eb4f --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/topk.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "single_layer_tests/topk.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::vector axes = { + 0, + 1, + 2, +}; + +const std::vector k = { + 1, + 5, + 10, +}; + +const std::vector modes = { + ngraph::opset4::TopK::Mode::MIN, + ngraph::opset4::TopK::Mode::MAX +}; + +const std::vector sortTypes = { + ngraph::opset4::TopK::SortType::NONE, + ngraph::opset4::TopK::SortType::SORT_INDICES, + ngraph::opset4::TopK::SortType::SORT_VALUES, +}; + + +INSTANTIATE_TEST_CASE_P(TopK, TopKLayerTest, + ::testing::Combine( + ::testing::ValuesIn(k), + ::testing::ValuesIn(axes), + ::testing::ValuesIn(modes), + ::testing::ValuesIn(sortTypes), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(std::vector({10, 10, 10})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + TopKLayerTest::getTestCaseName); +} // namespace 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 faf4916dfc0..e8302db4389 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 @@ -50,6 +50,9 @@ std::vector disabledTestPatterns() { // TODO: Issue: 32032 R"(.*ActivationParamLayerTest.*)", // TODO: Issue: 37862 - R"(.*ReverseSequenceLayerTest.*netPRC=(I8|U8).*)" + R"(.*ReverseSequenceLayerTest.*netPRC=(I8|U8).*)", + // TODO: Issue: 38841 + R"(.*TopKLayerTest.*k=10.*mode=min.*sort=index.*)", + R"(.*TopKLayerTest.*k=5.*sort=(none|index).*)" }; } diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp new file mode 100644 index 00000000000..94e4be583b6 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/topk.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "functional_test_utils/layer_test_utils.hpp" +#include "ngraph_functions/builders.hpp" + +namespace LayerTestsDefinitions { +typedef std::tuple< + int64_t, // keepK + int64_t, // axis + ngraph::opset4::TopK::Mode, // mode + ngraph::opset4::TopK::SortType, // sort + InferenceEngine::Precision, // Net precision + InferenceEngine::SizeVector, // inputShape + std::string // Target device name +> TopKParams; + +class TopKLayerTest : public testing::WithParamInterface, + virtual 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/topk.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp new file mode 100644 index 00000000000..49f1638d913 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/topk.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/topk.hpp" + +namespace LayerTestsDefinitions { + std::string TopKLayerTest::getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + InferenceEngine::SizeVector inputShape; + std::string targetDevice; + int64_t keepK, axis; + ngraph::opset4::TopK::Mode mode; + ngraph::opset4::TopK::SortType sort; + std::tie(keepK, axis, mode, sort, netPrecision, inputShape, targetDevice) = obj.param; + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; + result << "k=" << keepK << "_"; + result << "axis=" << axis << "_"; + result << "mode=" << mode << "_"; + result << "sort=" << sort << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "targetDevice=" << targetDevice; + return result.str(); +} + +void TopKLayerTest::SetUp() { + InferenceEngine::SizeVector inputShape; + InferenceEngine::Precision netPrecision; + int64_t keepK, axis; + ngraph::opset4::TopK::Mode mode; + ngraph::opset4::TopK::SortType sort; + std::tie(keepK, axis, mode, sort, netPrecision, inputShape, targetDevice) = this->GetParam(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + auto paramIn = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(params)); + + auto k = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{}, &keepK); + auto topk = std::dynamic_pointer_cast( + std::make_shared(paramIn[0], k, axis, mode, sort)); + + ngraph::ResultVector results; + for (int i = 0; i < topk->get_output_size(); i++) { + results.push_back(std::make_shared(topk->output(i))); + } + function = std::make_shared(results, params, "TopK"); +} + +TEST_P(TopKLayerTest, CompareWithRefsDynamicBath) { + Run(); +} +} // namespace LayerTestsDefinitions \ No newline at end of file