Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / fp32_non_quantized_tests.cpp
1 //
2 // Copyright 2016-2018 Intel Corporation.
3 //
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
11 //
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
15 //
16
17
18 #include <vector>
19 #include <gtest/gtest.h>
20 #include <inference_engine/layer_transform.hpp>
21 #include "gna_plugin/quantization/model_quantizer.hpp"
22 #include "gna_plugin/quantization/layer_quantizer.hpp"
23 #include "gna_matcher.hpp"
24
25 using namespace InferenceEngine;
26 using namespace GNAPluginNS;
27 using namespace GNATestIRs;
28
29 class FP32NonQuantizedTest : public GNATest {
30  protected:
31
32     void SetUp() override  {
33     }
34 };
35
36 TEST_F(FP32NonQuantizedTest, SplitFollowedByFCAndEltwiseOnCPU) {
37     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
38                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
39     std::vector<float> expected_result = {12.0, 12.0, 12.0, 12.0, 12.0,
40                                           12.0, 12.0, 12.0, 12.0, 12.0};
41     assert_that().onInferModel(FCWithPaddingAfterSplitModel())
42         .inNotCompactMode().gna().propagate_forward().onCPU()
43         .called_with_input_and_expected_output(input_data, expected_result);
44 }
45
46 TEST_F(FP32NonQuantizedTest, SliceFollowedByFCAndEltwiseOnCPU) {
47     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
48                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
49     std::vector<float> expected_result = {14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0};
50     assert_that().onInferModel(FCWithPaddingAfterSliceModel())
51         .inNotCompactMode().gna().propagate_forward().onCPU()
52         .called_with_input_and_expected_output(input_data, expected_result);
53 }
54
55 TEST_F(FP32NonQuantizedTest, SliceFollowedByAlignedFCAndEltwiseOnCPU) {
56     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
57                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
58     std::vector<float> expected_result = {18.0, 18.0, 18.0, 18.0};
59     assert_that().onInferModel(SliceModelWithAlignedOutputs())
60         .inNotCompactMode().gna().propagate_forward().onCPU()
61         .called_with_input_and_expected_output(input_data, expected_result);
62 }
63
64 TEST_F(FP32NonQuantizedTest, DISABLED_SliceFollowedBy2FCsAnd2EltwisesOnCPU) {
65     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
66                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
67     std::vector<float> expected_result = {27.0, 27.0, 27.0, 27.0, 27.0, 27.0, 27.0, 27.0};
68     assert_that().onInferModel(twoFCWithPaddingAfterSliceModel())
69         .inNotCompactMode().gna().propagate_forward().onCPU()
70         .called_with_input_and_expected_output(input_data, expected_result);
71 }
72
73 TEST_F(FP32NonQuantizedTest, SplitAfterFCFollowedByFCAndEltwiseOnCPU) {
74     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
75                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
76     std::vector<float> expected_result = {232.0, 232.0, 232.0, 232.0, 232.0,
77                                           232.0, 232.0, 232.0, 232.0, 232.0};
78     assert_that().onInferModel(FCBeforeSplitModel())
79         .inNotCompactMode().gna().propagate_forward().onCPU()
80         .called_with_input_and_expected_output(input_data, expected_result);
81 }
82
83
84 TEST_F(FP32NonQuantizedTest, ConcatPropagateForwardWithSuccessOnCPU) {
85     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
86                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
87     std::vector<float> expected_result = {121.0, 121.0, 121.0, 121.0, 121.0,
88                                           121.0, 121.0, 121.0, 121.0, 121.0,
89                                           121.0, 121.0, 121.0, 121.0, 121.0,
90                                           121.0, 121.0, 121.0, 121.0, 121.0};
91
92     assert_that().onInferModel(concatModel())
93         .inNotCompactMode().gna().propagate_forward().onCPU()
94         .called_with_input_and_expected_output(input_data, expected_result);
95 }
96
97 TEST_F(FP32NonQuantizedTest, DoubleConcatPropageteForwardWithSuccessOnCPU) {
98     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
99                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
100                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
101                                      1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
102     std::vector<float> expected_result = {141.0, 141.0, 141.0, 141.0, 141.0,
103                                           141.0, 141.0, 141.0, 141.0, 141.0,
104                                           141.0, 141.0, 141.0, 141.0, 141.0,
105                                           141.0, 141.0, 141.0, 141.0, 141.0,
106                                           141.0, 141.0, 141.0, 141.0, 141.0,
107                                           141.0, 141.0, 141.0, 141.0, 141.0,
108                                           141.0, 141.0, 141.0, 141.0, 141.0,
109                                           141.0, 141.0, 141.0, 141.0, 141.0};
110
111     assert_that().onInferModel(doubleConcatModel())
112         .inNotCompactMode().gna().propagate_forward().onCPU()
113         .called_with_input_and_expected_output(input_data, expected_result);
114 }
115
116 TEST_F(FP32NonQuantizedTest, multiple_inputs_correct_results) {
117     std::vector<float> input_data  = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
118     std::vector<float> input2_data = {2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0};
119     std::vector<float> result      = {30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0, 30.0};
120
121     assert_that().onInferModel(two_inputs_to_affine())
122         .inNotCompactMode().gna().propagate_forward().onCPU()
123         .called_with().input("input_1", input_data).And().input("input_2", input2_data).result().equal_to(result);
124 }
125
126
127 TEST_F(FP32NonQuantizedTest, CropWithoutOffsetPropagateForwardWithSuccessOnCPU) {
128     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
129                                      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
130     std::vector<float> expected_result = {11.0, 11.0, 11.0, 11.0, 11.0,
131                                           11.0, 11.0, 11.0, 11.0, 11.0};
132
133     assert_that().onInferModel(cropWithoutOffsetModel())
134         .inNotCompactMode().gna().propagate_forward().onCPU()
135         .called_with_input_and_expected_output(input_data, expected_result);
136 }
137
138 TEST_F(FP32NonQuantizedTest, CropWithAlignedOffsetPropagateForwardWithSuccessOnCPU) {
139     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
140                                      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
141     std::vector<float> expected_result = {3.0, 3.0, 3.0, 3.0, 3.0,
142                                           3.0, 3.0, 3.0, 3.0, 3.0};
143
144     assert_that().onInferModel(cropWithAlignedOffsetModel())
145         .inNotCompactMode().gna().propagate_forward().onCPU()
146         .called_with_input_and_expected_output(input_data, expected_result);
147 }
148
149 TEST_F(FP32NonQuantizedTest, CropWithOffsetPropagateForwardWithSuccessOnCPU) {
150     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
151                                      0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0};
152     std::vector<float> expected_result = {7.0, 7.0, 7.0, 7.0, 7.0,
153                                           7.0, 7.0, 7.0, 7.0, 7.0};
154
155     assert_that().onInferModel(cropWithOffsetModel())
156         .inNotCompactMode().gna().propagate_forward().onCPU()
157         .called_with_input_and_expected_output(input_data, expected_result);
158 }
159
160 TEST_F(FP32NonQuantizedTest, CropWithMaxOffsetPropagateForwardWithSuccessOnCPU) {
161     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
162                                      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
163     std::vector<float> expected_result = {1.0, 1.0, 1.0, 1.0, 1.0,
164                                           1.0, 1.0, 1.0, 1.0, 1.0};
165
166     assert_that().onInferModel(cropWithMaxOffsetModel())
167         .inNotCompactMode().gna().propagate_forward().onCPU()
168         .called_with_input_and_expected_output(input_data, expected_result);
169 }
170
171 TEST_F(FP32NonQuantizedTest, CropWithOffsetAfterFCPropagateForwardWithSuccessOnCPU) {
172     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
173                                      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
174     std::vector<float> expected_result = {111.0, 111.0, 111.0, 111.0, 111.0,
175                                           111.0, 111.0, 111.0, 111.0, 111.0};
176
177     assert_that().onInferModel(cropWithOffsetExtendedModel())
178         .inNotCompactMode().gna().propagate_forward().onCPU()
179         .called_with_input_and_expected_output(input_data, expected_result);
180 }
181
182 TEST_F(FP32NonQuantizedTest, CopySimpleCasePropagateForwardWithSuccessOnCPU) {
183     std::vector<float> input_data = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
184                                      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
185     std::vector<float> expected_result = {12.0, 12.0, 12.0, 12.0, 12.0,
186                                           12.0, 12.0, 12.0, 12.0, 12.0,
187                                           11.0, 11.0, 11.0, 11.0, 11.0,
188                                           11.0, 11.0, 11.0, 11.0, 11.0,};
189
190     assert_that().onInferModel(copyModel())
191         .inNotCompactMode().gna().propagate_forward().onCPU()
192         .called_with_input_and_expected_output(input_data, expected_result);
193 }
194
195
196 TEST_F(FP32NonQuantizedTest, ScaleShiftWithBroadcastSupported) {
197     std::vector<float> input_data (40, 1.0);
198
199     std::vector<float> expected_result = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
200                                           2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
201                                           2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
202                                           2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
203                                           2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0};
204
205     assert_that().onInferModel(ScaleShift3DModel()).withWeigthsPattern({1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f})
206         .inNotCompactMode().gna().propagate_forward().onCPU()
207         .called_with_input_and_expected_output(input_data, expected_result);
208 }