From 6b5d513bcdab3adcd09dd2b24d973ada196c01a8 Mon Sep 17 00:00:00 2001 From: mryzhov Date: Wed, 23 Jun 2021 11:16:08 +0300 Subject: [PATCH] Revert "[gna] Fixed export/import precision" This reverts commit d381a2e216e3ee2d88b2532b122f6b0dd42d0960. --- .../src/gna_plugin/gna_model_serial.cpp | 5 +- .../src/gna_plugin/gna_plugin.cpp | 7 +- .../src/gna_plugin/gna_plugin.hpp | 1 - .../import_export_act_conv_act.cpp | 107 ++++++++++++++++-- .../import_reshape_permute_conv.cpp | 5 - .../skip_tests_config.cpp | 2 + .../import_export_base/import_export_base.hpp | 1 - .../import_export_base/import_export_base.cpp | 5 +- .../import_export_tests/import_nonzero.cpp | 3 +- .../import_reshape_permute_conv.cpp | 3 +- .../src/base/layer_test_utils.cpp | 9 -- 11 files changed, 109 insertions(+), 39 deletions(-) diff --git a/inference-engine/src/gna_plugin/gna_model_serial.cpp b/inference-engine/src/gna_plugin/gna_model_serial.cpp index 761f3cf6003fbc..e32ded8a9e37ed 100644 --- a/inference-engine/src/gna_plugin/gna_model_serial.cpp +++ b/inference-engine/src/gna_plugin/gna_model_serial.cpp @@ -831,7 +831,7 @@ std::vector GNAModelSerial::serializeOutputs(cons } uint32_t elementsCount = static_cast(InferenceEngine::details::product(outputDims.begin(), outputDims.end())); InferenceEngine::Layout outputLayout = output.second->getLayout(); - uint8_t outputPrecision = output.second->getPrecision().getPrecVal(); + InferenceEngine::Precision::ePrecision outputPrecision = InferenceEngine::Precision::FP32; HeaderLatest::RuntimeEndPoint endPoint(outputsDesc[outputIndex].scale_factor, outputsDesc[outputIndex].ptrs[0], outputsDesc[outputIndex].num_bytes_per_element, @@ -866,7 +866,7 @@ std::vector GNAModelSerial::serializeInputs(const uint32_t elementsCount = static_cast(InferenceEngine::details::product(inputDims.begin(), inputDims.end())); intel_dnn_orientation_t orientation = inputDesc->getOrientation(inputName); InferenceEngine::Layout inputLayout = input.second->getLayout(); - uint8_t inputPrecision = input.second->getPrecision().getPrecVal(); + InferenceEngine::Precision::ePrecision inputPrecision = InferenceEngine::Precision::FP32; HeaderLatest::RuntimeEndPoint endPoint(scaleFactor, descriptor_ptr[0], element_size, @@ -886,6 +886,7 @@ void GNAModelSerial::ImportInputs(std::istream &is, std::shared_ptr inputsDesc, InferenceEngine::InputsDataMap& dataMap) { dataMap.clear(); + for (uint32_t inputIndex = 0; inputIndex < modelHeader.nInputs; inputIndex++) { const std::string& name = (modelHeader.version.major == 2 && modelHeader.version.minor >= 3) ? inputNames.at(inputIndex) : std::string("input" + std::to_string(inputIndex)); diff --git a/inference-engine/src/gna_plugin/gna_plugin.cpp b/inference-engine/src/gna_plugin/gna_plugin.cpp index fa6e0cc4b3b500..cb227304649638 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.cpp +++ b/inference-engine/src/gna_plugin/gna_plugin.cpp @@ -714,7 +714,7 @@ void GNAPlugin::LoadNetwork(CNNNetwork & _network) { convertedNetwork = InferenceEngine::details::convertFunctionToICNNNetwork(graph, clonedNetwork); } IE_SUPPRESS_DEPRECATED_START - network = convertedNetwork ? InferenceEngine::CNNNetwork{convertedNetwork} : _network; + InferenceEngine::CNNNetwork network = convertedNetwork ? InferenceEngine::CNNNetwork{convertedNetwork} : _network; IE_SUPPRESS_DEPRECATED_END NetPass::ConvertPrecision(network, Precision::I64, Precision::I32); @@ -1632,6 +1632,7 @@ void GNAPlugin::Export(std::ostream &outStream) { THROW_GNA_EXCEPTION << " exporting network with multiple inputs not supported"; } #endif + // TODO: nnet group parameter looks only used in application - so can we move this line into load network. IE_ASSERT(!inputsDataMap.empty()); auto inputDims = inputsDataMap.begin()->second->getTensorDesc().getDims(); @@ -1648,8 +1649,8 @@ void GNAPlugin::Export(std::ostream &outStream) { auto serial = GNAModelSerial(modelToSerial, inputsDesc, outputsDesc, - network.getInputsInfo(), - network.getOutputsInfo()) + inputsDataMap, + outputsDataMap) .SetInputRotation(transpose_inputs_info) .SetOutputRotation(transpose_outputs_info); diff --git a/inference-engine/src/gna_plugin/gna_plugin.hpp b/inference-engine/src/gna_plugin/gna_plugin.hpp index 1f4dd8d52fa8ad..1b37439eead68e 100644 --- a/inference-engine/src/gna_plugin/gna_plugin.hpp +++ b/inference-engine/src/gna_plugin/gna_plugin.hpp @@ -83,7 +83,6 @@ class GNAPlugin : public InferenceEngine::IInferencePlugin { */ uint32_t rwSegmentSize = 0; - InferenceEngine::CNNNetwork network; InferenceEngine::InputsDataMap inputsDataMap; InferenceEngine::OutputsDataMap outputsDataMap; std::vector memoryStates; diff --git a/inference-engine/tests/functional/plugin/gna/Import_export_tests/import_export_act_conv_act.cpp b/inference-engine/tests/functional/plugin/gna/Import_export_tests/import_export_act_conv_act.cpp index bea3103e7a590b..e5abadfb1cc67f 100644 --- a/inference-engine/tests/functional/plugin/gna/Import_export_tests/import_export_act_conv_act.cpp +++ b/inference-engine/tests/functional/plugin/gna/Import_export_tests/import_export_act_conv_act.cpp @@ -11,21 +11,113 @@ #include #include -#include "base/import_export_base/import_export_base.hpp" + +#include "shared_test_classes/base/layer_test_utils.hpp" #include "functional_test_utils/blob_utils.hpp" #include "ngraph_functions/utils/ngraph_helpers.hpp" #include "ngraph_functions/builders.hpp" +typedef std::tuple< + std::vector, // Input shape + InferenceEngine::Precision, // Network Precision + std::string, // Target Device + std::map, // Export Configuration + std::map // Import Configuration +> exportImportNetworkParams; + namespace LayerTestsDefinitions { -class ImportActConvActTest : public FuncTestUtils::ImportNetworkTestBase { +class ImportActConvActTest : public testing::WithParamInterface, + public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::vector inputShape; + InferenceEngine::Precision netPrecision; + std::string targetDevice; + std::map exportConfiguration; + std::map importConfiguration; + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration) = obj.param; + + std::ostringstream result; + result << "netPRC=" << netPrecision.name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + for (auto const &configItem : exportConfiguration) { + result << "_exportConfigItem=" << configItem.first << "_" << configItem.second; + } + for (auto const &configItem : importConfiguration) { + result << "_importConfigItem=" << configItem.first << "_" << configItem.second; + } + result << CommonTestUtils::vec2str(inputShape); + return result.str(); + } + + void Run() override { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + configuration.insert(exportConfiguration.begin(), exportConfiguration.end()); + LoadNetwork(); + GenerateInputs(); + Infer(); + + executableNetwork.Export("exported_model.blob"); + for (auto const &configItem : importConfiguration) { + configuration[configItem.first] = configItem.second; + } + std::fstream inputStream("exported_model.blob", std::ios_base::in | std::ios_base::binary); + if (inputStream.fail()) { + FAIL() << "Cannot open file to import model: exported_model.blob"; + } + + auto importedNetwork = core->ImportNetwork(inputStream, targetDevice, configuration); + + // Generate inputs + std::vector inputs; + auto inputsInfo = importedNetwork.GetInputsInfo(); + auto functionParams = function->get_parameters(); + for (int i = 0; i < functionParams.size(); ++i) { + const auto& param = functionParams[i]; + const auto infoIt = inputsInfo.find(param->get_friendly_name()); + GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); + + const auto& info = infoIt->second; + auto blob = GenerateInput(*info); + inputs.push_back(blob); + } + + // Infer imported network + InferenceEngine::InferRequest importInfer = importedNetwork.CreateInferRequest(); + inputsInfo = importedNetwork.GetInputsInfo(); + functionParams = function->get_parameters(); + for (int i = 0; i < functionParams.size(); ++i) { + const auto& param = functionParams[i]; + const auto infoIt = inputsInfo.find(param->get_friendly_name()); + GTEST_ASSERT_NE(infoIt, inputsInfo.cend()); + + const auto& info = infoIt->second; + auto blob = inputs[i]; + importInfer.SetBlob(info->name(), blob); + } + importInfer.Infer(); + + // Validate + auto expectedOutputs = CalculateRefs(); + auto actualOutputs = std::vector{}; + for (const auto &output : importedNetwork.GetOutputsInfo()) { + const auto &name = output.first; + actualOutputs.push_back(importInfer.GetBlob(name)); + } + IE_ASSERT(actualOutputs.size() == expectedOutputs.size()) + << "nGraph interpreter has " << expectedOutputs.size() << " outputs, while IE " << actualOutputs.size(); + Compare(expectedOutputs, actualOutputs); + } + protected: void SetUp() override { std::vector inputShape; InferenceEngine::Precision netPrecision; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); - + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); auto relu1 = std::make_shared(params[0]); @@ -73,18 +165,13 @@ const std::vector> importConfigs = { } }; -const std::vector appHeaders = { - "" -}; - INSTANTIATE_TEST_CASE_P(smoke_ImportActConvAct, ImportActConvActTest, ::testing::Combine( ::testing::ValuesIn(inputShape), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), - ::testing::ValuesIn(importConfigs), - ::testing::ValuesIn(appHeaders)), + ::testing::ValuesIn(importConfigs)), ImportActConvActTest::getTestCaseName); } // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp index ff71f73ff937a6..442cb116f5d387 100644 --- a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp @@ -46,10 +46,6 @@ TEST_P(ImportReshapePermuteConvGNA, CompareWithRefImpl) { Run(); }; -const std::vector> inputShape = { - {} -}; - const std::vector netPrecisions = { InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16 @@ -80,7 +76,6 @@ const std::vector appHeaders = { INSTANTIATE_TEST_CASE_P(smoke_ImportNetworkCase, ImportReshapePermuteConvGNA, ::testing::Combine( - ::testing::ValuesIn(inputShape), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp index d3d8188db7fa1f..a59ad83eaed76e 100644 --- a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/skip_tests_config.cpp @@ -58,6 +58,8 @@ std::vector disabledTestPatterns() { R"(.*ConvolutionLayerTest.CompareWithRefs.*D=\(3.1\).*)", R"(.*ConstantResultSubgraphTest.*IS=\(2\.3\.4\.5\).*)", R"(.*ConstantResultSubgraphTest.*inPrc=(U8|I8|I32|U64|I64|BOOL).*)", + // TODO: Issue 51528 + R"(.*CachingSupport.*_(u8|i16)_.*)", // TODO: Issue 51525 R"(.*CachingSupport.*KSOFunction.*)", // TODO: Issue 57363 (Param -> Result subgraphs) diff --git a/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp b/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp index 86d49a2bcb809e..d8f30c23f2df1f 100644 --- a/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp @@ -9,7 +9,6 @@ #include typedef std::tuple< - std::vector, // Input shape InferenceEngine::Precision, // Network Precision std::string, // Target Device std::map, // Export Configuration diff --git a/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp b/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp index 4e9921aed8fee3..c30945dc914d83 100644 --- a/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp @@ -9,13 +9,12 @@ namespace FuncTestUtils { std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShape; InferenceEngine::Precision netPrecision; std::string targetDevice; std::map exportConfiguration; std::map importConfiguration; std::string appHeader; - std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; + std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; std::ostringstream result; result << "netPRC=" << netPrecision.name() << "_"; @@ -27,8 +26,6 @@ std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfoget_parameters(); for (int i = 0; i < functionParams.size(); ++i) {