Skip to content

Commit 5866f71

Browse files
[GNA] Added test for backward compatibility (openvinotoolkit#4315)
1 parent 01e4606 commit 5866f71

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

inference-engine/src/gna_plugin/gna_model_serial.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ GNAPluginNS::HeaderLatest::ModelHeader GNAModelSerial::ReadHeader(std::istream &
113113
break;
114114
case 2:
115115
case 3:
116+
{
117+
Header2dot3::ModelHeader tempHeader2dot3;
118+
readBits(tempHeader2dot3, is);
119+
header = HeaderLatest::ModelHeader(tempHeader2dot3);
120+
break;
121+
}
116122
case 4:
117123
{
118124
Header2dot4::ModelHeader tempHeader2dot4;

inference-engine/src/gna_plugin/serial/headers/2dot5/gna_model_header.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct ModelHeader {
8585
nRotateColumns = old.nRotateColumns;
8686
nInputs = old.nInputs;
8787
nOutputs = old.nOutputs;
88+
version.minor = old.version.minor;
8889
}
8990
ModelHeader(GNAPluginNS::Header2dot4::ModelHeader const &old) {
9091
gnaMemSize = old.gnaMemSize;
@@ -99,6 +100,16 @@ struct ModelHeader {
99100
doRotateOutput = old.doRotateOutput;
100101
version.minor = old.version.minor;
101102
}
103+
ModelHeader(GNAPluginNS::Header2dot3::ModelHeader const &old) {
104+
gnaMemSize = old.gnaMemSize;
105+
layersCount = old.layersCount;
106+
nGroup = old.nGroup;
107+
nRotateRows = old.nRotateRows;
108+
nRotateColumns = old.nRotateColumns;
109+
nInputs = old.nInputs;
110+
nOutputs = old.nOutputs;
111+
version.minor = old.version.minor;
112+
}
102113
};
103114
#pragma pack(pop)
104115

inference-engine/tests_deprecated/functional/gna/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ file(GLOB TEST_SRC
1111
${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/ie_class/*.cpp
1212
${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/input_tests/*.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/lstm/*.cpp
14-
${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/single_layer_tests/*.cpp)
14+
${CMAKE_CURRENT_SOURCE_DIR}/shared_tests_instance/single_layer_tests/*.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/backward_compatibility/*.cpp)
1516

1617
list(APPEND DEPENDENCIES
1718
HeteroPlugin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright (C) 2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <functional_test_utils/precision_utils.hpp>
6+
#include <ie_core.hpp>
7+
#include <ngraph_functions/builders.hpp>
8+
#include <test_model_repo.hpp>
9+
#include <single_layer_common.hpp>
10+
#include "gtest/gtest.h"
11+
12+
//TODO : need move to new test infrastructure @IrinaEfode
13+
using namespace InferenceEngine;
14+
15+
typedef std::tuple<
16+
InferenceEngine::Precision, // Network Precision
17+
std::string, // Target Device
18+
std::string, // Name Export Model
19+
std::map<std::string, std::string>, // Export Configuration
20+
std::map<std::string, std::string> // Import Configuration
21+
> exportImportNetworkParams;
22+
23+
class BackwardCompatibilityTests : public testing::WithParamInterface<exportImportNetworkParams>,
24+
public testing::Test{
25+
public:
26+
static std::string getTestCaseName(testing::TestParamInfo<exportImportNetworkParams> obj) {
27+
InferenceEngine::Precision netPrecision;
28+
std::string targetDevice;
29+
std::map<std::string, std::string> exportConfiguration;
30+
std::map<std::string, std::string> importConfiguration;
31+
std::string nameExportModel;
32+
std::tie(netPrecision, targetDevice, nameExportModel, exportConfiguration, importConfiguration) = obj.param;
33+
34+
std::ostringstream result;
35+
result << "netPRC=" << netPrecision.name() << "_";
36+
result << "targetDevice=" << targetDevice << "_";
37+
result << "nameExportModel=" << nameExportModel << "_";
38+
for (auto const& configItem : exportConfiguration) {
39+
result << "_exportConfigItem=" << configItem.first << "_" << configItem.second;
40+
}
41+
for (auto const& configItem : importConfiguration) {
42+
result << "_importConfigItem=" << configItem.first << "_" << configItem.second;
43+
}
44+
return result.str();
45+
}
46+
47+
void Run() {
48+
InferenceEngine::Precision netPrecision;
49+
std::string targetDevice;
50+
std::map<std::string, std::string> exportConfiguration;
51+
std::map<std::string, std::string> importConfiguration;
52+
std::string nameExportModel;
53+
std::tie(netPrecision, targetDevice, nameExportModel, exportConfiguration, importConfiguration) = this->GetParam();
54+
GenerateFunction();
55+
Core ie;
56+
CNNNetwork network = CNNNetwork(function);
57+
ExecutableNetwork executableNetwork = ie.LoadNetwork(network, "GNA", exportConfiguration);
58+
InferRequest inferRequest = executableNetwork.CreateInferRequest();
59+
inferRequest.Infer();
60+
auto refOutputs = std::vector<InferenceEngine::Blob::Ptr>{};
61+
for (const auto& output : executableNetwork.GetOutputsInfo()) {
62+
const auto& name = output.first;
63+
refOutputs.push_back(inferRequest.GetBlob(name));
64+
}
65+
66+
auto models = TestDataHelpers::get_data_path() + "/gna/" + nameExportModel;
67+
auto ImportNetwork = ie.ImportNetwork(models, "GNA", importConfiguration);
68+
InferRequest inferRequestImport = ImportNetwork.CreateInferRequest();
69+
auto input_names = executableNetwork.GetInputsInfo();
70+
for (const auto& input_name : input_names) {
71+
auto i_blob = inferRequest.GetBlob(input_name.first);
72+
for (const auto& infer_name : ImportNetwork.GetInputsInfo()) {
73+
inferRequestImport.SetBlob(infer_name.first, i_blob);
74+
}
75+
}
76+
inferRequestImport.Infer();
77+
for (const auto& output : ImportNetwork.GetOutputsInfo()) {
78+
const auto& name = output.first;
79+
refOutputs.push_back(inferRequestImport.GetBlob(name));
80+
}
81+
CompareCommonExact(refOutputs[1], refOutputs[0]);
82+
}
83+
84+
protected:
85+
void SetUp() override {
86+
}
87+
private:
88+
std::shared_ptr<ngraph::Function> function;
89+
void GenerateFunction() {
90+
auto param = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::f32, ngraph::Shape{1, 336});
91+
auto const_eltwise = std::make_shared<ngraph::opset1::Constant>(ngraph::element::f32, ngraph::Shape{1, 336},
92+
std::vector<float>{-1});
93+
auto relu = std::make_shared<ngraph::opset1::Multiply>(param, const_eltwise);
94+
ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(relu) };
95+
function = std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{param}, "ExportBackwordCompatibility");
96+
}
97+
};
98+
99+
TEST_P(BackwardCompatibilityTests, smoke_BackwardCompatibility){
100+
Run();
101+
}
102+
103+
const std::vector<InferenceEngine::Precision> netPrecisions = {
104+
InferenceEngine::Precision::FP32,
105+
InferenceEngine::Precision::FP16
106+
};
107+
108+
const std::vector<std::map<std::string, std::string>> exportConfigs = {
109+
{
110+
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
111+
{"GNA_SCALE_FACTOR_0", "327.67"}
112+
}
113+
};
114+
115+
const std::vector<std::map<std::string, std::string>> importConfigs = {
116+
{
117+
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
118+
{"GNA_SCALE_FACTOR_0", "327.67"}
119+
},
120+
};
121+
122+
const std::vector<std::string> nameExportModel = {"export2dot1.blob", "export2dot2.blob", "export2dot3.blob", "export2dot4.blob"};
123+
124+
INSTANTIATE_TEST_CASE_P(smoke_OldVersion, BackwardCompatibilityTests,
125+
::testing::Combine(
126+
::testing::ValuesIn(netPrecisions),
127+
::testing::Values("GNA"),
128+
::testing::ValuesIn(nameExportModel),
129+
::testing::ValuesIn(exportConfigs),
130+
::testing::ValuesIn(importConfigs)),
131+
BackwardCompatibilityTests::getTestCaseName);

0 commit comments

Comments
 (0)