From 949e23d0e8a0c0fbec4b212b486c4306b454c91c Mon Sep 17 00:00:00 2001 From: Andrey Dmitriev Date: Thu, 1 Oct 2020 15:09:53 +0300 Subject: [PATCH] [GNA]specific execution order for delayer copy layer (#2117) [GNA]specific execution order for delayer copy layer + Test --- .../src/gna_plugin/backend/dnn_components.cpp | 1 - .../gna_plugin/optimizer/gna_pass_manager.cpp | 4 +- .../subgraph_tests/delayed_copy_layer.cpp | 24 ++++++ .../subgraph_tests/delayed_copy_layer.hpp | 33 ++++++++ .../src/subgraph_tests/delayed_copy_layer.cpp | 82 +++++++++++++++++++ 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/subgraph_tests/delayed_copy_layer.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/subgraph_tests/delayed_copy_layer.cpp diff --git a/inference-engine/src/gna_plugin/backend/dnn_components.cpp b/inference-engine/src/gna_plugin/backend/dnn_components.cpp index 2c7c799f52b..76df4d0ac38 100644 --- a/inference-engine/src/gna_plugin/backend/dnn_components.cpp +++ b/inference-engine/src/gna_plugin/backend/dnn_components.cpp @@ -52,7 +52,6 @@ intel_dnn_component_t * DnnComponents::findComponent(InferenceEngine::CNNLayerPt return nullptr; } - std::vector DnnComponents::getExecutionOrder() { std::vector result(components.size()); diff --git a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp index 7e33fc7b66a..867e5f38154 100644 --- a/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp +++ b/inference-engine/src/gna_plugin/optimizer/gna_pass_manager.cpp @@ -27,6 +27,7 @@ #include "gna_plugin_log.hpp" #include "frontend/quantized_layer_params.hpp" +#include #include "gna_graph_tools.hpp" #include "gna_pass_manager.hpp" #include "layers/gna_layer_info.hpp" @@ -703,7 +704,8 @@ void InsertCopyLayerPass::run() { }; if (LayerInfo(l).isMemory()) { - if (LayerInfo(prevIndirectLayer).isConcat() || LayerInfo(prevIndirectLayer).isCrop()) { bInsertDelayed = true;} + if (LayerInfo(prevIndirectLayer).isConcat() || LayerInfo(prevIndirectLayer).isCrop() + || LayerInfo(prevIndirectLayer).isSplit()) { bInsertDelayed = true;} // memory usualy preceded by either activation or split, or other layers in order to have 2b precision for (auto && inputto : getInputTo(prevLayers[i].first->outData[prevLayers[i].second])) { // if preceding layer is common for memory and concat diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp new file mode 100644 index 00000000000..59dfb27b79e --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/subgraph_tests/delayed_copy_layer.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +#include +#include "subgraph_tests/delayed_copy_layer.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 additional_config = { + {"GNA_COMPACT_MODE", "NO"} + }; + + INSTANTIATE_TEST_CASE_P(delayed_copy_layer, DelayedCopyTest, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::Values(additional_config)), + DelayedCopyTest::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/delayed_copy_layer.hpp b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/delayed_copy_layer.hpp new file mode 100644 index 00000000000..c6ac64a36f4 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/subgraph_tests/delayed_copy_layer.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::map //Configuration +> ConcatSplitReluTuple; + +class DelayedCopyTest + : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +private: + void switchToNgraphFriendlyModel(); +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/src/subgraph_tests/delayed_copy_layer.cpp b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/delayed_copy_layer.cpp new file mode 100644 index 00000000000..7180cacb4ac --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/subgraph_tests/delayed_copy_layer.cpp @@ -0,0 +1,82 @@ +// 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/delayed_copy_layer.hpp" + +namespace LayerTestsDefinitions { + std::string DelayedCopyTest::getTestCaseName(const testing::TestParamInfo &obj) { + InferenceEngine::Precision netPrecision; + std::string targetName; + std::map additional_config; + std::tie(netPrecision, targetName, additional_config) = obj.param; + std::ostringstream results; + + results << "netPRC=" << netPrecision.name() << "_"; + results << "targetDevice=" << targetName << "_"; + return results.str(); + } + + void DelayedCopyTest::SetUp() { + InferenceEngine::Precision netPrecision; + std::map additional_config; + std::tie(netPrecision, targetDevice, additional_config) = this->GetParam(); + configuration.insert(additional_config.begin(), additional_config.end()); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, {{1, 384}}); + + auto mem_c = std::make_shared(ngPrc, ngraph::Shape{1, 128}, std::vector{0}); + + auto mem_r = std::make_shared(mem_c, "id"); + + auto concat = std::make_shared(ngraph::OutputVector{mem_r, input[0]}, 1); + auto split = ngraph::builder::makeVariadicSplit(concat, {384, 128}, 1); + auto mem_w = std::make_shared(split->output(1), "id"); + + auto VariadicSplit = ngraph::builder::makeVariadicSplit(concat, {64, 448}, 1); + auto relu2 = std::make_shared(VariadicSplit->output(1)); + + mem_w->add_control_dependency(mem_r); + relu2->add_control_dependency(mem_w); + + function = std::make_shared(relu2, input, "delayed_copy_layer_memory"); + } + + void DelayedCopyTest::switchToNgraphFriendlyModel() { + InferenceEngine::Precision netPrecision; + std::map config; + std::map additional_config; + std::tie(netPrecision, targetDevice, additional_config) = this->GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, {{1, 384}}); + + auto mem_c = std::make_shared(ngPrc, ngraph::Shape{1, 128}, std::vector{0}); + auto concat = std::make_shared(ngraph::OutputVector{mem_c, input[0]}, 1); + auto split = ngraph::builder::makeVariadicSplit(concat, {384, 128}, 1); + + auto VariadicSplit = ngraph::builder::makeVariadicSplit(concat, {64, 448}, 1); + auto relu2 = std::make_shared(VariadicSplit->output(1)); + + function = std::make_shared(relu2, input, "delayed_copy_layer_nonmemory"); + } + + void DelayedCopyTest::Run() { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + LoadNetwork(); + Infer(); + switchToNgraphFriendlyModel(); + Validate(); + } + + TEST_P(DelayedCopyTest, CompareWithRefs) { + Run(); +}; +} // namespace LayerTestsDefinitions