Publishing 2019 R1.1 content and Myriad plugin sources (#162)
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / gna_pwl_test.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <vector>
6 #include <gtest/gtest.h>
7 #include "gna_matcher.hpp"
8
9 class PWLAproximationTest : public GNATest {
10  protected:
11     void SetUp() override  {
12     }
13 };
14 using namespace GNATestIRs;
15
16 // Recursive Algorithm
17 // Precision Threshold
18
19 TEST_F(PWLAproximationTest, forTanhOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
20     assert_that().onInferModel(TanhActivationModel())
21                                     .inNotCompactMode()
22                                 .propagate_forward()
23                                 .called_with()
24                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
25                                 .pwl_quantization_precision_threshold(0.0053);
26 }
27
28 TEST_F(PWLAproximationTest, forSigmoidOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
29     assert_that().onInferModel(SigmoidActivationModel())
30                                 .inNotCompactMode()
31                                 .propagate_forward()
32                                 .called_with()
33                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
34                                 .pwl_quantization_precision_threshold(0.0027);
35 }
36
37 TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
38     assert_that().onInferModel(ReLUActivationModel())
39                                 .inNotCompactMode()
40                                 .propagate_forward()
41                                 .called_with()
42                                 .pwl_quantization_activation(DnnActivationType::kActRelu)
43                                 .pwl_quantization_precision_threshold(0.0001);
44 }
45
46 TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
47     assert_that().onInferModel(LeakyReLUActivationModel())
48                                 .inNotCompactMode()
49                                 .propagate_forward()
50                                 .called_with()
51                                 .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
52                                 .pwl_quantization_precision_threshold(0.0003);
53 }
54
55 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
56     assert_that().onInferModel(IdentityActivationModel())
57                                 .inNotCompactMode()
58                                 .propagate_forward()
59                                 .called_with()
60                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
61                                 .pwl_quantization_precision_threshold(0.0003);
62 }
63
64 TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
65     assert_that().onInferModel(ClampActivationModel())
66                                 .inNotCompactMode()
67                                 .propagate_forward()
68                                 .called_with()
69                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
70                                 .pwl_quantization_precision_threshold(0.0001);
71 }
72
73 // Uniform Algorithm
74 // Precision Threshold
75
76 TEST_F(PWLAproximationTest, forTanhOnUniformAlgoWithPrecisionThresholdIsSuccess) {
77     assert_that().onInferModel(TanhActivationModel())
78                                 .inNotCompactMode()
79                                 .withUniformPWLAlgo()
80                                 .propagate_forward()
81                                 .called_with()
82                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
83                                 .pwl_quantization_precision_threshold(0.0009);
84 }
85
86 TEST_F(PWLAproximationTest, forSigmoidOnUniformAlgoWithPrecisionThresholdIsSuccess) {
87     assert_that().onInferModel(SigmoidActivationModel())
88                                 .inNotCompactMode()
89                                 .withUniformPWLAlgo()
90                                 .propagate_forward()
91                                 .called_with()
92                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
93                                 .pwl_quantization_precision_threshold(0.0004);
94 }
95
96 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithPrecisionThresholdIsSuccess) {
97     assert_that().onInferModel(IdentityActivationModel())
98                                 .inNotCompactMode()
99                                 .withUniformPWLAlgo()
100                                 .propagate_forward()
101                                 .called_with()
102                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
103                                 .pwl_quantization_precision_threshold(0.0003);
104 }
105
106 TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithPrecisionThresholdIsSuccess) {
107     assert_that().onInferModel(ClampActivationModel())
108                                 .inNotCompactMode()
109                                 .withUniformPWLAlgo()
110                                 .propagate_forward()
111                                 .called_with()
112                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
113                                 .pwl_quantization_precision_threshold(0.0001);
114 }
115
116 // Recursive Algorithm
117 // Segment Threshold
118
119 TEST_F(PWLAproximationTest, forSigmoidonRecursiveAlgoWithSegmentThresholdIsSuccess) {
120     assert_that().onInferModel(SigmoidActivationModel())
121                                 .inNotCompactMode()
122                                 .propagate_forward()
123                                 .called_with()
124                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
125                                 .pwl_quantization_segments_threshold(12);
126 }
127
128 TEST_F(PWLAproximationTest, forTanhonRecursiveAlgoWithSegmentThresholdIsSuccess) {
129     assert_that().onInferModel(TanhActivationModel())
130                                 .inNotCompactMode()
131                                 .propagate_forward()
132                                 .called_with()
133                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
134                                 .pwl_quantization_segments_threshold(12);
135 }
136
137 TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
138     assert_that().onInferModel(ReLUActivationModel())
139                                 .inNotCompactMode()
140                                 .propagate_forward()
141                                 .called_with()
142                                 .pwl_quantization_activation(DnnActivationType::kActRelu)
143                                 .pwl_quantization_segments_threshold(2);
144 }
145
146 TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
147     assert_that().onInferModel(LeakyReLUActivationModel())
148                                 .inNotCompactMode()
149                                 .propagate_forward()
150                                 .called_with()
151                                 .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
152                                 .pwl_quantization_segments_threshold(2);
153 }
154
155 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
156     assert_that().onInferModel(IdentityActivationModel())
157                                 .inNotCompactMode()
158                                 .propagate_forward()
159                                 .called_with()
160                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
161                                 .pwl_quantization_segments_threshold(3);
162 }
163
164 TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
165     assert_that().onInferModel(ClampActivationModel())
166                                 .inNotCompactMode()
167                                 .propagate_forward()
168                                 .called_with()
169                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
170                                 .pwl_quantization_segments_threshold(3);
171 }
172
173 // Uniform Algorithm
174 // Segment Threshold
175
176 TEST_F(PWLAproximationTest, forSigmoidonUniformAlgoWithSegmentThresholdIsSuccess) {
177     assert_that().onInferModel(SigmoidActivationModel())
178                                 .inNotCompactMode()
179                                 .withUniformPWLAlgo()
180                                 .propagate_forward()
181                                 .called_with()
182                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
183                                 .pwl_quantization_segments_threshold(65);
184 }
185
186 TEST_F(PWLAproximationTest, forTanhonUniformAlgoWithSegmentThresholdIsSuccess) {
187     assert_that().onInferModel(TanhActivationModel())
188                                 .inNotCompactMode()
189                                 .withUniformPWLAlgo()
190                                 .propagate_forward()
191                                 .called_with()
192                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
193                                 .pwl_quantization_segments_threshold(65);
194 }
195
196 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithSegmentThresholdIsSuccess) {
197     assert_that().onInferModel(IdentityActivationModel())
198                                 .inNotCompactMode()
199                                 .withUniformPWLAlgo()
200                                 .propagate_forward()
201                                 .called_with()
202                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
203                                 .pwl_quantization_segments_threshold(3);
204 }
205
206 TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithSegmentThresholdIsSuccess) {
207     assert_that().onInferModel(ClampActivationModel())
208                                 .inNotCompactMode()
209                                 .withUniformPWLAlgo()
210                                 .propagate_forward()
211                                 .called_with()
212                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
213                                 .pwl_quantization_segments_threshold(3);
214 }