From 5866f713d9a32e7ecc0ff775c16633231a363585 Mon Sep 17 00:00:00 2001 From: Andrey Dmitriev Date: Mon, 15 Feb 2021 14:46:56 +0300 Subject: [PATCH] [GNA] Added test for backward compatibility (#4315) --- .../src/gna_plugin/gna_model_serial.cpp | 6 + .../serial/headers/2dot5/gna_model_header.hpp | 11 ++ .../functional/gna/CMakeLists.txt | 3 +- .../backward_compatibility.cpp | 131 ++++++++++++++++++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 inference-engine/tests_deprecated/functional/gna/backward_compatibility/backward_compatibility.cpp diff --git a/inference-engine/src/gna_plugin/gna_model_serial.cpp b/inference-engine/src/gna_plugin/gna_model_serial.cpp index fee680cbbdc..bd373c1952f 100644 --- a/inference-engine/src/gna_plugin/gna_model_serial.cpp +++ b/inference-engine/src/gna_plugin/gna_model_serial.cpp @@ -113,6 +113,12 @@ GNAPluginNS::HeaderLatest::ModelHeader GNAModelSerial::ReadHeader(std::istream & break; case 2: case 3: + { + Header2dot3::ModelHeader tempHeader2dot3; + readBits(tempHeader2dot3, is); + header = HeaderLatest::ModelHeader(tempHeader2dot3); + break; + } case 4: { Header2dot4::ModelHeader tempHeader2dot4; diff --git a/inference-engine/src/gna_plugin/serial/headers/2dot5/gna_model_header.hpp b/inference-engine/src/gna_plugin/serial/headers/2dot5/gna_model_header.hpp index 5a5dfacc261..0fa4e4a007d 100644 --- a/inference-engine/src/gna_plugin/serial/headers/2dot5/gna_model_header.hpp +++ b/inference-engine/src/gna_plugin/serial/headers/2dot5/gna_model_header.hpp @@ -85,6 +85,7 @@ struct ModelHeader { nRotateColumns = old.nRotateColumns; nInputs = old.nInputs; nOutputs = old.nOutputs; + version.minor = old.version.minor; } ModelHeader(GNAPluginNS::Header2dot4::ModelHeader const &old) { gnaMemSize = old.gnaMemSize; @@ -99,6 +100,16 @@ struct ModelHeader { doRotateOutput = old.doRotateOutput; version.minor = old.version.minor; } + ModelHeader(GNAPluginNS::Header2dot3::ModelHeader const &old) { + gnaMemSize = old.gnaMemSize; + layersCount = old.layersCount; + nGroup = old.nGroup; + nRotateRows = old.nRotateRows; + nRotateColumns = old.nRotateColumns; + nInputs = old.nInputs; + nOutputs = old.nOutputs; + version.minor = old.version.minor; + } }; #pragma pack(pop) diff --git a/inference-engine/tests_deprecated/functional/gna/CMakeLists.txt b/inference-engine/tests_deprecated/functional/gna/CMakeLists.txt index 665637e85bb..4e05f853f44 100644 --- a/inference-engine/tests_deprecated/functional/gna/CMakeLists.txt +++ b/inference-engine/tests_deprecated/functional/gna/CMakeLists.txt @@ -11,7 +11,8 @@ file(GLOB TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/ie_class/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/input_tests/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/lstm/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/single_layer_tests/*.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/single_layer_tests/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/backward_compatibility/*.cpp) list(APPEND DEPENDENCIES HeteroPlugin diff --git a/inference-engine/tests_deprecated/functional/gna/backward_compatibility/backward_compatibility.cpp b/inference-engine/tests_deprecated/functional/gna/backward_compatibility/backward_compatibility.cpp new file mode 100644 index 00000000000..efe79eb35d1 --- /dev/null +++ b/inference-engine/tests_deprecated/functional/gna/backward_compatibility/backward_compatibility.cpp @@ -0,0 +1,131 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +//TODO : need move to new test infrastructure @IrinaEfode +using namespace InferenceEngine; + +typedef std::tuple< + InferenceEngine::Precision, // Network Precision + std::string, // Target Device + std::string, // Name Export Model + std::map, // Export Configuration + std::map // Import Configuration +> exportImportNetworkParams; + +class BackwardCompatibilityTests : public testing::WithParamInterface, + public testing::Test{ +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + std::string targetDevice; + std::map exportConfiguration; + std::map importConfiguration; + std::string nameExportModel; + std::tie(netPrecision, targetDevice, nameExportModel, exportConfiguration, importConfiguration) = obj.param; + + std::ostringstream result; + result << "netPRC=" << netPrecision.name() << "_"; + result << "targetDevice=" << targetDevice << "_"; + result << "nameExportModel=" << nameExportModel << "_"; + for (auto const& configItem : exportConfiguration) { + result << "_exportConfigItem=" << configItem.first << "_" << configItem.second; + } + for (auto const& configItem : importConfiguration) { + result << "_importConfigItem=" << configItem.first << "_" << configItem.second; + } + return result.str(); + } + + void Run() { + InferenceEngine::Precision netPrecision; + std::string targetDevice; + std::map exportConfiguration; + std::map importConfiguration; + std::string nameExportModel; + std::tie(netPrecision, targetDevice, nameExportModel, exportConfiguration, importConfiguration) = this->GetParam(); + GenerateFunction(); + Core ie; + CNNNetwork network = CNNNetwork(function); + ExecutableNetwork executableNetwork = ie.LoadNetwork(network, "GNA", exportConfiguration); + InferRequest inferRequest = executableNetwork.CreateInferRequest(); + inferRequest.Infer(); + auto refOutputs = std::vector{}; + for (const auto& output : executableNetwork.GetOutputsInfo()) { + const auto& name = output.first; + refOutputs.push_back(inferRequest.GetBlob(name)); + } + + auto models = TestDataHelpers::get_data_path() + "/gna/" + nameExportModel; + auto ImportNetwork = ie.ImportNetwork(models, "GNA", importConfiguration); + InferRequest inferRequestImport = ImportNetwork.CreateInferRequest(); + auto input_names = executableNetwork.GetInputsInfo(); + for (const auto& input_name : input_names) { + auto i_blob = inferRequest.GetBlob(input_name.first); + for (const auto& infer_name : ImportNetwork.GetInputsInfo()) { + inferRequestImport.SetBlob(infer_name.first, i_blob); + } + } + inferRequestImport.Infer(); + for (const auto& output : ImportNetwork.GetOutputsInfo()) { + const auto& name = output.first; + refOutputs.push_back(inferRequestImport.GetBlob(name)); + } + CompareCommonExact(refOutputs[1], refOutputs[0]); + } + +protected: + void SetUp() override { + } +private: + std::shared_ptr function; + void GenerateFunction() { + auto param = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 336}); + auto const_eltwise = std::make_shared(ngraph::element::f32, ngraph::Shape{1, 336}, + std::vector{-1}); + auto relu = std::make_shared(param, const_eltwise); + ngraph::ResultVector results{ std::make_shared(relu) }; + function = std::make_shared(results, ngraph::ParameterVector{param}, "ExportBackwordCompatibility"); + } +}; + +TEST_P(BackwardCompatibilityTests, smoke_BackwardCompatibility){ + Run(); +} + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::vector> exportConfigs = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"} + } +}; + +const std::vector> importConfigs = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"} + }, +}; + +const std::vector nameExportModel = {"export2dot1.blob", "export2dot2.blob", "export2dot3.blob", "export2dot4.blob"}; + +INSTANTIATE_TEST_CASE_P(smoke_OldVersion, BackwardCompatibilityTests, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values("GNA"), + ::testing::ValuesIn(nameExportModel), + ::testing::ValuesIn(exportConfigs), + ::testing::ValuesIn(importConfigs)), + BackwardCompatibilityTests::getTestCaseName); \ No newline at end of file