From 2cf7065f6e15db863012fbc833ba7ad089214385 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Thu, 2 Sep 2021 17:48:07 +0300 Subject: [PATCH] [GNA] Fixed import of model with several inputs (#7277) --- .../src/gna_plugin/gna_plugin.cpp | 2 +- .../import_export_multi_inputs.cpp | 118 ++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index 2f257ba4fb0bc1..fb9f406446e055 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -1612,7 +1612,7 @@ InferenceEngine::IExecutableNetworkInternal::Ptr GNAPlugin::ImportNetwork(std::i // If scale factors are defined in configuration we still need to use them instead of imported values, // for example to change the scale factors for the old models. if (!config.inputScaleFactors.empty()) { - IE_ASSERT(config.inputScaleFactors.size() == inputsDesc->inputScaleFactors.size()); + IE_ASSERT(config.inputScaleFactors.size() <= inputsDesc->inputScaleFactors.size()); for (size_t i = 0; i < config.inputScaleFactors.size(); ++i) { if (config.inputScaleFactors[i] != GNAPluginNS::kScaleFactorDefault) { gnalog() << "[Import Network] Using input scale factor defined in configuration for input " << i << std::endl; diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp new file mode 100644 index 00000000000000..511c56e5784568 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp @@ -0,0 +1,118 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include +#include + +#include "ngraph_functions/builders.hpp" +#include "base/import_export_base/import_export_base.hpp" + +namespace LayerTestsDefinitions { + +class ImportMultiInput : public FuncTestUtils::ImportNetworkTestBase { +protected: + void SetUp() override { + InferenceEngine::Precision netPrecision; + std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); + + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto input = ngraph::builder::makeParams(ngPrc, {{1, 10}, {1, 10}}); + auto mul1 = ngraph::builder::makeEltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); + auto result = std::make_shared(mul1); + + function = std::make_shared(ngraph::ResultVector{result}, input, "multiple_input"); + } +}; + +class ImportMultiInputChanged : public ImportMultiInput {}; +class ImportMultiInputUnchanged : public ImportMultiInput {}; + +TEST_P(ImportMultiInputUnchanged, CompareWithRefImpl) { + TestRun(false); +}; + +TEST_P(ImportMultiInputChanged, CompareWithRefImpl) { + TestRun(true); +}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32 +}; + +const std::vector> exportConfigs = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"}, + {"GNA_SCALE_FACTOR_1", "327.67"} + } +}; + +const std::vector> importConfigsChanged = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "32767"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_1", "32767"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "32767"}, + {"GNA_SCALE_FACTOR_1", "32767"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "1"}, + {"GNA_SCALE_FACTOR_1", "32767"} + } +}; + +const std::vector> importConfigsUnchanged = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "1"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"}, + {"GNA_SCALE_FACTOR_1", "327.67"} + }, + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_1", "327.67"} + }, +}; + +INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(exportConfigs), + ::testing::ValuesIn(importConfigsUnchanged), + ::testing::Values("")), + ImportMultiInputUnchanged::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkGNA, ImportMultiInputChanged, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(exportConfigs), + ::testing::ValuesIn(importConfigsChanged), + ::testing::Values("")), + ImportMultiInputChanged::getTestCaseName); + +} // namespace LayerTestsDefinitions +