1 // Copyright (c) Facebook, Inc. and its affiliates.
2 // All rights reserved.
3 //
4 // Copyright 2019 Google LLC
5 //
6 // This source code is licensed under the BSD-style license found in the
7 // LICENSE file in the root directory of this source tree.
8 
9 #include <gtest/gtest.h>
10 
11 #include "leaky-relu-operator-tester.h"
12 
13 
TEST(LEAKY_RELU_NC_QU8,unit_batch)14 TEST(LEAKY_RELU_NC_QU8, unit_batch) {
15   for (size_t channels = 1; channels < 100; channels++) {
16     LeakyReLUOperatorTester()
17       .batch_size(1)
18       .channels(channels)
19       .iterations(3)
20       .TestQU8();
21   }
22 }
23 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_qmin)24 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_qmin) {
25   for (size_t channels = 1; channels < 100; channels += 15) {
26     LeakyReLUOperatorTester()
27       .batch_size(1)
28       .channels(channels)
29       .qmin(128)
30       .iterations(3)
31       .TestQU8();
32   }
33 }
34 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_qmax)35 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_qmax) {
36   for (size_t channels = 1; channels < 100; channels += 15) {
37     LeakyReLUOperatorTester()
38       .batch_size(1)
39       .channels(channels)
40       .qmax(128)
41       .iterations(3)
42       .TestQU8();
43   }
44 }
45 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_negative_slope)46 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_negative_slope) {
47   for (size_t channels = 1; channels < 100; channels += 15) {
48     for (float negative_slope = 1.0e-4f; negative_slope < 1.0f; negative_slope *= 3.14159265f) {
49       LeakyReLUOperatorTester()
50         .batch_size(1)
51         .channels(channels)
52         .negative_slope(negative_slope)
53         .iterations(1)
54         .TestQU8();
55     }
56   }
57 }
58 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_input_scale)59 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_input_scale) {
60   for (size_t channels = 1; channels < 100; channels += 15) {
61     for (float input_scale = 1.0e-2f; input_scale < 1.0e+2f; input_scale *= 3.14159265f) {
62       LeakyReLUOperatorTester()
63         .batch_size(1)
64         .channels(channels)
65         .input_scale(input_scale)
66         .iterations(1)
67         .TestQU8();
68     }
69   }
70 }
71 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_input_zero_point)72 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_input_zero_point) {
73   for (size_t channels = 1; channels < 100; channels += 15) {
74     for (int32_t input_zero_point = 0; input_zero_point <= 255; input_zero_point += 51) {
75       LeakyReLUOperatorTester()
76         .batch_size(1)
77         .channels(channels)
78         .input_zero_point(uint8_t(input_zero_point))
79         .iterations(1)
80         .TestQU8();
81     }
82   }
83 }
84 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_output_scale)85 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_output_scale) {
86   for (size_t channels = 1; channels < 100; channels += 15) {
87     for (float output_scale = 1.0e-2f; output_scale < 1.0e+2f; output_scale *= 3.14159265f) {
88       LeakyReLUOperatorTester()
89         .batch_size(1)
90         .channels(channels)
91         .output_scale(output_scale)
92         .iterations(1)
93         .TestQU8();
94     }
95   }
96 }
97 
TEST(LEAKY_RELU_NC_QU8,unit_batch_with_output_zero_point)98 TEST(LEAKY_RELU_NC_QU8, unit_batch_with_output_zero_point) {
99   for (size_t channels = 1; channels < 100; channels += 15) {
100     for (int32_t output_zero_point = 0; output_zero_point <= 255; output_zero_point += 51) {
101       LeakyReLUOperatorTester()
102         .batch_size(1)
103         .channels(channels)
104         .output_zero_point(uint8_t(output_zero_point))
105         .iterations(1)
106         .TestQU8();
107     }
108   }
109 }
110 
TEST(LEAKY_RELU_NC_QU8,small_batch)111 TEST(LEAKY_RELU_NC_QU8, small_batch) {
112   for (size_t channels = 1; channels < 100; channels++) {
113     LeakyReLUOperatorTester()
114       .batch_size(3)
115       .channels(channels)
116       .iterations(3)
117       .TestQU8();
118   }
119 }
120 
TEST(LEAKY_RELU_NC_QU8,small_batch_with_input_stride)121 TEST(LEAKY_RELU_NC_QU8, small_batch_with_input_stride) {
122   for (size_t channels = 1; channels < 100; channels += 15) {
123     LeakyReLUOperatorTester()
124       .batch_size(3)
125       .channels(channels)
126       .input_stride(129)
127       .iterations(3)
128       .TestQU8();
129   }
130 }
131 
TEST(LEAKY_RELU_NC_QU8,small_batch_with_output_stride)132 TEST(LEAKY_RELU_NC_QU8, small_batch_with_output_stride) {
133   for (size_t channels = 1; channels < 100; channels += 15) {
134     LeakyReLUOperatorTester()
135       .batch_size(3)
136       .channels(channels)
137       .output_stride(117)
138       .iterations(3)
139       .TestQU8();
140   }
141 }
142 
TEST(LEAKY_RELU_NC_QU8,small_batch_with_input_and_output_stride)143 TEST(LEAKY_RELU_NC_QU8, small_batch_with_input_and_output_stride) {
144   for (size_t channels = 1; channels < 100; channels += 15) {
145     LeakyReLUOperatorTester()
146       .batch_size(3)
147       .channels(channels)
148       .input_stride(129)
149       .output_stride(117)
150       .iterations(3)
151       .TestQU8();
152   }
153 }
154 
155 
TEST(LEAKY_RELU_NC_F32,unit_batch)156 TEST(LEAKY_RELU_NC_F32, unit_batch) {
157   for (size_t channels = 1; channels < 100; channels++) {
158     LeakyReLUOperatorTester()
159       .batch_size(1)
160       .channels(channels)
161       .iterations(3)
162       .TestF32();
163   }
164 }
165 
TEST(LEAKY_RELU_NC_F32,small_batch)166 TEST(LEAKY_RELU_NC_F32, small_batch) {
167   for (size_t channels = 1; channels < 100; channels++) {
168     LeakyReLUOperatorTester()
169       .batch_size(3)
170       .channels(channels)
171       .iterations(3)
172       .TestF32();
173   }
174 }
175 
TEST(LEAKY_RELU_NC_F32,small_batch_with_input_stride)176 TEST(LEAKY_RELU_NC_F32, small_batch_with_input_stride) {
177   for (size_t channels = 1; channels < 100; channels += 15) {
178     LeakyReLUOperatorTester()
179       .batch_size(3)
180       .channels(channels)
181       .input_stride(129)
182       .iterations(3)
183       .TestF32();
184   }
185 }
186 
TEST(LEAKY_RELU_NC_F32,small_batch_with_output_stride)187 TEST(LEAKY_RELU_NC_F32, small_batch_with_output_stride) {
188   for (size_t channels = 1; channels < 100; channels += 15) {
189     LeakyReLUOperatorTester()
190       .batch_size(3)
191       .channels(channels)
192       .output_stride(117)
193       .iterations(3)
194       .TestF32();
195   }
196 }
197 
TEST(LEAKY_RELU_NC_F32,small_batch_with_input_and_output_stride)198 TEST(LEAKY_RELU_NC_F32, small_batch_with_input_and_output_stride) {
199   for (size_t channels = 1; channels < 100; channels += 15) {
200     LeakyReLUOperatorTester()
201       .batch_size(3)
202       .channels(channels)
203       .input_stride(129)
204       .output_stride(117)
205       .iterations(3)
206       .TestF32();
207   }
208 }
209 
TEST(LEAKY_RELU_NC_F32,small_batch_with_negative_slope)210 TEST(LEAKY_RELU_NC_F32, small_batch_with_negative_slope) {
211   for (size_t batch_size = 1; batch_size <= 3; batch_size += 2) {
212     for (size_t channels = 1; channels < 100; channels += 15) {
213       for (float negative_slope = 1.0e-4f; negative_slope < 1.0f; negative_slope *= 3.14159265f) {
214         LeakyReLUOperatorTester()
215           .batch_size(3)
216           .channels(channels)
217           .negative_slope(negative_slope)
218           .iterations(1)
219           .TestF32();
220       }
221     }
222   }
223 }
224