Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / gna_pwl_test.cpp
1 /*
2  * INTEL CONFIDENTIAL
3  * Copyright (C) 2018-2019 Intel Corporation.
4  *
5  * The source code contained or described herein and all documents
6  * related to the source code ("Material") are owned by Intel Corporation
7  * or its suppliers or licensors. Title to the Material remains with
8  * Intel Corporation or its suppliers and licensors. The Material may
9  * contain trade secrets and proprietary and confidential information
10  * of Intel Corporation and its suppliers and licensors, and is protected
11  * by worldwide copyright and trade secret laws and treaty provisions.
12  * No part of the Material may be used, copied, reproduced, modified,
13  * published, uploaded, posted, transmitted, distributed, or disclosed
14  * in any way without Intel's prior express written permission.
15  *
16  * No license under any patent, copyright, trade secret or other
17  * intellectual property right is granted to or conferred upon you by
18  * disclosure or delivery of the Materials, either expressly, by implication,
19  * inducement, estoppel or otherwise. Any license under such intellectual
20  * property rights must be express and approved by Intel in writing.
21  *
22  * Include any supplier copyright notices as supplier requires Intel to use.
23  *
24  * Include supplier trademarks or logos as supplier requires Intel to use,
25  * preceded by an asterisk. An asterisked footnote can be added as follows:
26  * *Third Party trademarks are the property of their respective owners.
27  *
28  * Unless otherwise agreed by Intel in writing, you may not remove or alter
29  * this notice or any other notice embedded in Materials by Intel or Intel's
30  * suppliers or licensors in any way.
31  */
32
33
34 #include <vector>
35 #include <gtest/gtest.h>
36 #include "gna_matcher.hpp"
37
38 class PWLAproximationTest : public GNATest {
39  protected:
40     void SetUp() override  {
41     }
42 };
43 using namespace GNATestIRs;
44
45 // Recursive Algorithm
46 // Precision Threshold
47
48 TEST_F(PWLAproximationTest, forTanhOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
49     assert_that().onInferModel(TanhActivationModel())
50                                     .inNotCompactMode()
51                                 .propagate_forward()
52                                 .called_with()
53                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
54                                 .pwl_quantization_precision_threshold(0.0053);
55 }
56
57 TEST_F(PWLAproximationTest, forSigmoidOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
58     assert_that().onInferModel(SigmoidActivationModel())
59                                 .inNotCompactMode()
60                                 .propagate_forward()
61                                 .called_with()
62                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
63                                 .pwl_quantization_precision_threshold(0.0027);
64 }
65
66 TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
67     assert_that().onInferModel(ReLUActivationModel())
68                                 .inNotCompactMode()
69                                 .propagate_forward()
70                                 .called_with()
71                                 .pwl_quantization_activation(DnnActivationType::kActRelu)
72                                 .pwl_quantization_precision_threshold(0.0001);
73 }
74
75 TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithPrecisionThresholdIsSuccess) {
76     assert_that().onInferModel(LeakyReLUActivationModel())
77                                 .inNotCompactMode()
78                                 .propagate_forward()
79                                 .called_with()
80                                 .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
81                                 .pwl_quantization_precision_threshold(0.0003);
82 }
83
84 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
85     assert_that().onInferModel(IdentityActivationModel())
86                                 .inNotCompactMode()
87                                 .propagate_forward()
88                                 .called_with()
89                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
90                                 .pwl_quantization_precision_threshold(0.0003);
91 }
92
93 TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithPrecisionThresholdIsSuccess) {
94     assert_that().onInferModel(ClampActivationModel())
95                                 .inNotCompactMode()
96                                 .propagate_forward()
97                                 .called_with()
98                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
99                                 .pwl_quantization_precision_threshold(0.0001);
100 }
101
102 // Uniform Algorithm
103 // Precision Threshold
104
105 TEST_F(PWLAproximationTest, forTanhOnUniformAlgoWithPrecisionThresholdIsSuccess) {
106     assert_that().onInferModel(TanhActivationModel())
107                                 .inNotCompactMode()
108                                 .withUniformPWLAlgo()
109                                 .propagate_forward()
110                                 .called_with()
111                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
112                                 .pwl_quantization_precision_threshold(0.0009);
113 }
114
115 TEST_F(PWLAproximationTest, forSigmoidOnUniformAlgoWithPrecisionThresholdIsSuccess) {
116     assert_that().onInferModel(SigmoidActivationModel())
117                                 .inNotCompactMode()
118                                 .withUniformPWLAlgo()
119                                 .propagate_forward()
120                                 .called_with()
121                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
122                                 .pwl_quantization_precision_threshold(0.0004);
123 }
124
125 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithPrecisionThresholdIsSuccess) {
126     assert_that().onInferModel(IdentityActivationModel())
127                                 .inNotCompactMode()
128                                 .withUniformPWLAlgo()
129                                 .propagate_forward()
130                                 .called_with()
131                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
132                                 .pwl_quantization_precision_threshold(0.0003);
133 }
134
135 TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithPrecisionThresholdIsSuccess) {
136     assert_that().onInferModel(ClampActivationModel())
137                                 .inNotCompactMode()
138                                 .withUniformPWLAlgo()
139                                 .propagate_forward()
140                                 .called_with()
141                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
142                                 .pwl_quantization_precision_threshold(0.0001);
143 }
144
145 // Recursive Algorithm
146 // Segment Threshold
147
148 TEST_F(PWLAproximationTest, forSigmoidonRecursiveAlgoWithSegmentThresholdIsSuccess) {
149     assert_that().onInferModel(SigmoidActivationModel())
150                                 .inNotCompactMode()
151                                 .propagate_forward()
152                                 .called_with()
153                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
154                                 .pwl_quantization_segments_threshold(12);
155 }
156
157 TEST_F(PWLAproximationTest, forTanhonRecursiveAlgoWithSegmentThresholdIsSuccess) {
158     assert_that().onInferModel(TanhActivationModel())
159                                 .inNotCompactMode()
160                                 .propagate_forward()
161                                 .called_with()
162                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
163                                 .pwl_quantization_segments_threshold(12);
164 }
165
166 TEST_F(PWLAproximationTest, forReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
167     assert_that().onInferModel(ReLUActivationModel())
168                                 .inNotCompactMode()
169                                 .propagate_forward()
170                                 .called_with()
171                                 .pwl_quantization_activation(DnnActivationType::kActRelu)
172                                 .pwl_quantization_segments_threshold(2);
173 }
174
175 TEST_F(PWLAproximationTest, forLeakyReLUonRecursiveAlgoWithSegmentThresholdIsSuccess) {
176     assert_that().onInferModel(LeakyReLUActivationModel())
177                                 .inNotCompactMode()
178                                 .propagate_forward()
179                                 .called_with()
180                                 .pwl_quantization_activation(DnnActivationType::kActLeakyRelu)
181                                 .pwl_quantization_segments_threshold(2);
182 }
183
184 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
185     assert_that().onInferModel(IdentityActivationModel())
186                                 .inNotCompactMode()
187                                 .propagate_forward()
188                                 .called_with()
189                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
190                                 .pwl_quantization_segments_threshold(3);
191 }
192
193 TEST_F(PWLAproximationTest, forClampOnRecursiveAlgoWithSegmentThresholdIsSuccess) {
194     assert_that().onInferModel(ClampActivationModel())
195                                 .inNotCompactMode()
196                                 .propagate_forward()
197                                 .called_with()
198                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
199                                 .pwl_quantization_segments_threshold(3);
200 }
201
202 // Uniform Algorithm
203 // Segment Threshold
204
205 TEST_F(PWLAproximationTest, forSigmoidonUniformAlgoWithSegmentThresholdIsSuccess) {
206     assert_that().onInferModel(SigmoidActivationModel())
207                                 .inNotCompactMode()
208                                 .withUniformPWLAlgo()
209                                 .propagate_forward()
210                                 .called_with()
211                                 .pwl_quantization_activation(DnnActivationType::kActSigmoid)
212                                 .pwl_quantization_segments_threshold(65);
213 }
214
215 TEST_F(PWLAproximationTest, forTanhonUniformAlgoWithSegmentThresholdIsSuccess) {
216     assert_that().onInferModel(TanhActivationModel())
217                                 .inNotCompactMode()
218                                 .withUniformPWLAlgo()
219                                 .propagate_forward()
220                                 .called_with()
221                                 .pwl_quantization_activation(DnnActivationType::kActTanh)
222                                 .pwl_quantization_segments_threshold(65);
223 }
224
225 TEST_F(PWLAproximationTest, DISABLED_forIdentityOnUniformAlgoWithSegmentThresholdIsSuccess) {
226     assert_that().onInferModel(IdentityActivationModel())
227                                 .inNotCompactMode()
228                                 .withUniformPWLAlgo()
229                                 .propagate_forward()
230                                 .called_with()
231                                 .pwl_quantization_activation(DnnActivationType::kActIdentity)
232                                 .pwl_quantization_segments_threshold(3);
233 }
234
235 TEST_F(PWLAproximationTest, forClampOnUniformAlgoWithSegmentThresholdIsSuccess) {
236     assert_that().onInferModel(ClampActivationModel())
237                                 .inNotCompactMode()
238                                 .withUniformPWLAlgo()
239                                 .propagate_forward()
240                                 .called_with()
241                                 .pwl_quantization_activation(DnnActivationType::kActKaldiLstmClipping)
242                                 .pwl_quantization_segments_threshold(3);
243 }