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