From: Elizaveta Lobanova Date: Thu, 12 Nov 2020 14:07:38 +0000 (+0300) Subject: [GNA] Added tests for negative memory layer offset and split - trivial permute -... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a10f71feebadd810287524aeaded2da14a2aee48;p=platform%2Fupstream%2Fdldt.git [GNA] Added tests for negative memory layer offset and split - trivial permute - concat scenario (#2989) --- diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp new file mode 100644 index 0000000..5659c22 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/negative_memory_layer_offset.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +#include +#include "subgraph_tests/negative_memory_layer_offset.hpp" +#include "common_test_utils/test_constants.hpp" +#include "gna/gna_config.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + std::vector netPrecisions = { InferenceEngine::Precision::FP32, + }; + + std::map config = { + {"GNA_COMPACT_MODE", "NO"} + }; + + std::vector inputSizes = { + 384, + 128, + 64, + 32 + }; + + std::vector hiddenSizes = { + 384, + 128, + 64, + 32, + 100 + }; + + INSTANTIATE_TEST_CASE_P(smoke_negative_memory_layer_offset, NegativeMemoryOffsetTest, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(inputSizes), + ::testing::ValuesIn(hiddenSizes), + ::testing::Values(config)), + NegativeMemoryOffsetTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp new file mode 100644 index 0000000..686c72c --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/split_trivial_permute_concat.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +#include +#include "subgraph_tests/split_trivial_permute_concat.hpp" +#include "common_test_utils/test_constants.hpp" +#include "gna/gna_config.hpp" + +using namespace LayerTestsDefinitions; + +namespace { + std::vector netPrecisions = { InferenceEngine::Precision::FP32, + }; + + std::map config = { + {"GNA_COMPACT_MODE", "NO"} + }; + + std::vector> inputSizes = { + { 4, 2, 64, 6 }, + { 4, 16, 4, 128}, + { 2, 10, 16, 64}, + { 2, 32, 64, 2}, + }; + + std::vector split_axes = { 1 }; // only channels split is currently supported by gna for 4d inputs + std::vector concat_axes = { 1 }; // only channels concat is currently supported by gna for 4d inputs + + INSTANTIATE_TEST_CASE_P(smoke_split_trivial_permute_concat, SplitTrivialPermuteConcatTest, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(inputSizes), + ::testing::ValuesIn(split_axes), // split axis + ::testing::ValuesIn(concat_axes), // concat axis + ::testing::Values(config)), + SplitTrivialPermuteConcatTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/negative_memory_layer_offset.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/negative_memory_layer_offset.hpp new file mode 100644 index 0000000..0756a37 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/negative_memory_layer_offset.hpp @@ -0,0 +1,36 @@ +// 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/utils/ngraph_helpers.hpp" +#include "ngraph_functions/builders.hpp" + +namespace LayerTestsDefinitions { + +typedef std::tuple< + InferenceEngine::Precision, //Network precision + std::string, //Device name + size_t, //Input size + size_t, //Hidden size + std::map //Configuration +> NegativeMemoryLayerOffsetTuple; + +class NegativeMemoryOffsetTest + : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +private: + void switchToNgraphFriendlyModel(); + std::vector memory_init; +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; + void Run() override; +}; +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/split_trivial_permute_concat.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/split_trivial_permute_concat.hpp new file mode 100644 index 0000000..8b8a553 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/split_trivial_permute_concat.hpp @@ -0,0 +1,33 @@ +// 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/utils/ngraph_helpers.hpp" +#include "ngraph_functions/builders.hpp" + +namespace LayerTestsDefinitions { + +typedef std::tuple< + InferenceEngine::Precision, //Network precision + std::string, //Device name + std::vector, //Input sizes + size_t, //Split axis + size_t, //Concat axis + std::map //Configuration +> SplitTrivialPermuteConcatTuple; + +class SplitTrivialPermuteConcatTest + : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); +protected: + void SetUp() override; +}; +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/negative_memory_layer_offset.cpp b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/negative_memory_layer_offset.cpp new file mode 100644 index 0000000..781e92f --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/negative_memory_layer_offset.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include +#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 "subgraph_tests/negative_memory_layer_offset.hpp" + +namespace LayerTestsDefinitions { + std::string NegativeMemoryOffsetTest::getTestCaseName(const testing::TestParamInfo& obj) { + InferenceEngine::Precision netPrecision; + std::string targetName; + size_t inputSize; + size_t hiddenSize; + std::tie(netPrecision, targetName, inputSize, hiddenSize, std::ignore) = obj.param; + std::ostringstream results; + + results << "netPRC=" << netPrecision.name() << "_"; + results << "IS=" << inputSize << "_"; + results << "HS=" << hiddenSize << "_"; + results << "targetDevice=" << targetName; + return results.str(); + } + + void NegativeMemoryOffsetTest::SetUp() { + InferenceEngine::Precision netPrecision; + size_t inputSize; + size_t hiddenSize; + std::map config; + std::tie(netPrecision, targetDevice, inputSize, hiddenSize, config) = this->GetParam(); + configuration.insert(config.begin(), config.end()); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + const int seed = 0; + std::mt19937 gen(static_cast(seed)); + std::uniform_real_distribution dist(-0.2f, 0.2f); + for (int i = 0; i < hiddenSize; ++i) + memory_init.emplace_back(static_cast(dist(gen))); + + auto input = ngraph::builder::makeParams(ngPrc, { {1, inputSize} }); + + auto mem_c = std::make_shared(ngPrc, ngraph::Shape{ 1, hiddenSize }, memory_init); + auto mem_r = std::make_shared(mem_c, "memory"); + + // Use memory layer as the second input of 'concat' to get negative offset + auto concat = std::make_shared(ngraph::OutputVector{ input[0], mem_r }, 1); + auto split = ngraph::builder::makeVariadicSplit(concat, { hiddenSize, inputSize }, 1); + auto mem_w = std::make_shared(split->output(0), "memory"); + auto sigm = std::make_shared(split->output(1)); + + mem_w->add_control_dependency(mem_r); + sigm->add_control_dependency(mem_w); + + function = std::make_shared(sigm, input, "negative_memory_layer_offset_memory"); + } + + void NegativeMemoryOffsetTest::switchToNgraphFriendlyModel() { + InferenceEngine::Precision netPrecision; + size_t inputSize; + size_t hiddenSize; + std::tie(netPrecision, targetDevice, inputSize, hiddenSize, std::ignore) = this->GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, { {1, inputSize} }); + + auto mem_c = std::make_shared(ngPrc, ngraph::Shape{ 1, hiddenSize }, memory_init); + auto concat = std::make_shared(ngraph::OutputVector{ input[0], mem_c }, 1); + auto split = ngraph::builder::makeVariadicSplit(concat, { hiddenSize, inputSize }, 1); + auto sigm = std::make_shared(split->output(1)); + + function = std::make_shared(sigm, input, "negative_memory_layer_offset_nonmemory"); + } + + void NegativeMemoryOffsetTest::Run() { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + LoadNetwork(); + auto states = executableNetwork.QueryState(); + for (auto& state : states) { + auto name = state.GetName(); + if (name == "memory") { + auto blob = FuncTestUtils::createAndFillBlobWithFloatArray(state.GetLastState()->getTensorDesc(), + memory_init.data(), memory_init.size()); + state.SetState(blob); + } else { + GTEST_FAIL() << "unknown memory state"; + } + } + Infer(); + switchToNgraphFriendlyModel(); + Validate(); + } + + TEST_P(NegativeMemoryOffsetTest, CompareWithRefs) { + Run(); + }; +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/split_trivial_permute_concat.cpp b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/split_trivial_permute_concat.cpp new file mode 100644 index 0000000..c04e2a5 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/split_trivial_permute_concat.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include +#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 "subgraph_tests/split_trivial_permute_concat.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" + +namespace LayerTestsDefinitions { + std::string SplitTrivialPermuteConcatTest::getTestCaseName(const testing::TestParamInfo& obj) { + InferenceEngine::Precision netPrecision; + std::string targetName; + std::vector inputShape; + size_t splitAxis; + size_t concatAxis; + std::tie(netPrecision, targetName, inputShape, splitAxis, concatAxis, std::ignore) = obj.param; + std::ostringstream results; + + results << "netPRC=" << netPrecision.name() << "_"; + results << "IS="; + for (size_t size : inputShape) + results << size << "_"; + results << "SA=" << splitAxis << "_"; + results << "CA=" << concatAxis << "_"; + results << "targetDevice=" << targetName; + return results.str(); + } + + void SplitTrivialPermuteConcatTest::SetUp() { + InferenceEngine::Precision netPrecision; + std::vector inputShape; + size_t splitAxis; + size_t concatAxis; + std::map config; + std::tie(netPrecision, targetDevice, inputShape, splitAxis, concatAxis, config) = this->GetParam(); + configuration.insert(config.begin(), config.end()); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, { inputShape }); + auto split = ngraph::builder::makeSplit(input[0], ngPrc, 2, splitAxis); + + auto permute_in_params = std::make_shared(ngraph::element::i64, + ngraph::Shape{ 4 }, + ngraph::Shape{ {0, 3, 2, 1} }); + auto permute_0 = std::make_shared(split->output(0), permute_in_params); + auto permute_1 = std::make_shared(split->output(1), permute_in_params); + + auto concat = std::make_shared(ngraph::OutputVector{ split->output(0), split->output(1) }, concatAxis); + auto act = ngraph::builder::makeActivation(concat, ngPrc, ngraph::helpers::ActivationTypes::Relu); + function = std::make_shared(act, input, "split_trivial_permute_concat"); + } + + TEST_P(SplitTrivialPermuteConcatTest, CompareWithRefs) { + Run(); + }; +} // namespace LayerTestsDefinitions