Elffuss BraidHub

kikocis/ncnn public

master · 20.7 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "testutil.h"
16
17static int test_rnn(const ncnn::Mat& a, int outch, int direction)
18{
19 int input_size = a.w;
20 int num_directions = direction == 2 ? 2 : 1;
21
22 ncnn::ParamDict pd;
23 pd.set(0, outch);
24 pd.set(1, outch * input_size * num_directions);
25 pd.set(2, direction);
26
27 std::vector<ncnn::Mat> weights(3);
28 weights[0] = RandomMat(outch * input_size * num_directions);
29 weights[1] = RandomMat(outch * num_directions);
30 weights[2] = RandomMat(outch * outch * num_directions);
31
32 int ret = test_layer("RNN", pd, weights, a);
33 if (ret != 0)
34 {
35 fprintf(stderr, "test_rnn failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
36 }
37
38 return ret;
39}
40
41int test_rnn_with_hidden(const ncnn::Mat& a, int outch, int direction)
42{
43 int input_size = a.w;
44 int num_directions = direction == 2 ? 2 : 1;
45
46 ncnn::ParamDict pd;
47 pd.set(0, outch);
48 pd.set(1, outch * input_size * num_directions);
49 pd.set(2, direction);
50
51 std::vector<ncnn::Mat> weights(3);
52 weights[0] = RandomMat(outch * input_size * num_directions);
53 weights[1] = RandomMat(outch * num_directions);
54 weights[2] = RandomMat(outch * outch * num_directions);
55
56 // initial hidden state
57 ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
58
59 std::vector<ncnn::Mat> as(2);
60 as[0] = a;
61 as[1] = hidden;
62
63 int ret = test_layer("RNN", pd, weights, as, 2);
64 if (ret != 0)
65 {
66 fprintf(stderr, "test_rnn_with_hidden failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
67 }
68
69 return ret;
70}
71
72int test_rnn_with_hidden_input(const ncnn::Mat& a, int outch, int direction)
73{
74 int input_size = a.w;
75 int num_directions = direction == 2 ? 2 : 1;
76
77 ncnn::ParamDict pd;
78 pd.set(0, outch);
79 pd.set(1, outch * input_size * num_directions);
80 pd.set(2, direction);
81
82 std::vector<ncnn::Mat> weights(3);
83 weights[0] = RandomMat(outch * input_size * num_directions);
84 weights[1] = RandomMat(outch * num_directions);
85 weights[2] = RandomMat(outch * outch * num_directions);
86
87 // initial hidden state
88 ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
89
90 std::vector<ncnn::Mat> as(2);
91 as[0] = a;
92 as[1] = hidden;
93
94 int ret = test_layer("RNN", pd, weights, as, 1);
95 if (ret != 0)
96 {
97 fprintf(stderr, "test_rnn_with_hidden_input failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
98 }
99
100 return ret;
101}
102
103int test_rnn_with_hidden_output(const ncnn::Mat& a, int outch, int direction)
104{
105 int input_size = a.w;
106 int num_directions = direction == 2 ? 2 : 1;
107
108 ncnn::ParamDict pd;
109 pd.set(0, outch);
110 pd.set(1, outch * input_size * num_directions);
111 pd.set(2, direction);
112
113 std::vector<ncnn::Mat> weights(3);
114 weights[0] = RandomMat(outch * input_size * num_directions);
115 weights[1] = RandomMat(outch * num_directions);
116 weights[2] = RandomMat(outch * outch * num_directions);
117
118 std::vector<ncnn::Mat> as(1);
119 as[0] = a;
120
121 int ret = test_layer("RNN", pd, weights, as, 2);
122 if (ret != 0)
123 {
124 fprintf(stderr, "test_rnn_with_hidden_output failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
125 }
126
127 return ret;
128}
129
130static int test_rnn_0()
131{
132 return 0
133 || test_rnn(RandomMat(4, 1), 2, 2)
134 || test_rnn(RandomMat(8, 2), 2, 2)
135 || test_rnn(RandomMat(16, 8), 7, 2)
136 || test_rnn(RandomMat(17, 8), 8, 2)
137 || test_rnn(RandomMat(19, 15), 8, 2)
138 || test_rnn(RandomMat(5, 16), 16, 2)
139 || test_rnn(RandomMat(3, 16), 8, 2)
140 || test_rnn(RandomMat(8, 16), 16, 2)
141 || test_rnn(RandomMat(31, 3), 31, 2)
142 || test_rnn(RandomMat(2, 5), 17, 2);
143}
144
145static int test_rnn_1()
146{
147 return 0
148 || test_rnn_with_hidden(RandomMat(4, 4), 1, 2)
149 || test_rnn_with_hidden(RandomMat(8, 2), 2, 2)
150 || test_rnn_with_hidden(RandomMat(16, 8), 7, 2)
151 || test_rnn_with_hidden(RandomMat(17, 8), 8, 2)
152 || test_rnn_with_hidden(RandomMat(19, 15), 8, 2)
153 || test_rnn_with_hidden(RandomMat(5, 16), 16, 2)
154 || test_rnn_with_hidden(RandomMat(3, 16), 8, 2)
155 || test_rnn_with_hidden(RandomMat(2, 5), 79, 2)
156 || test_rnn_with_hidden(RandomMat(4, 4), 1, 1)
157 || test_rnn_with_hidden(RandomMat(8, 2), 2, 1)
158 || test_rnn_with_hidden(RandomMat(16, 8), 7, 1)
159 || test_rnn_with_hidden(RandomMat(17, 8), 8, 1)
160 || test_rnn_with_hidden(RandomMat(19, 15), 8, 1)
161 || test_rnn_with_hidden(RandomMat(5, 16), 16, 1)
162 || test_rnn_with_hidden(RandomMat(3, 16), 8, 1)
163 || test_rnn_with_hidden(RandomMat(2, 5), 79, 1)
164 || test_rnn_with_hidden(RandomMat(4, 2), 1, 0)
165 || test_rnn_with_hidden(RandomMat(8, 2), 2, 0)
166 || test_rnn_with_hidden(RandomMat(16, 8), 7, 0)
167 || test_rnn_with_hidden(RandomMat(17, 8), 8, 0)
168 || test_rnn_with_hidden(RandomMat(19, 15), 8, 0)
169 || test_rnn_with_hidden(RandomMat(5, 16), 16, 0)
170 || test_rnn_with_hidden(RandomMat(3, 16), 8, 0)
171 || test_rnn_with_hidden(RandomMat(2, 5), 17, 0)
172
173 || test_rnn_with_hidden_input(RandomMat(4, 4), 1, 2)
174 || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 2)
175 || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 2)
176 || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 2)
177 || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 2)
178 || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 2)
179 || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 2)
180 || test_rnn_with_hidden_input(RandomMat(2, 5), 79, 2)
181 || test_rnn_with_hidden_input(RandomMat(4, 4), 1, 1)
182 || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 1)
183 || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 1)
184 || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 1)
185 || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 1)
186 || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 1)
187 || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 1)
188 || test_rnn_with_hidden_input(RandomMat(2, 5), 79, 1)
189 || test_rnn_with_hidden_input(RandomMat(4, 2), 1, 0)
190 || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 0)
191 || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 0)
192 || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 0)
193 || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 0)
194 || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 0)
195 || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 0)
196 || test_rnn_with_hidden_input(RandomMat(2, 5), 17, 0)
197
198 || test_rnn_with_hidden_output(RandomMat(4, 4), 1, 2)
199 || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 2)
200 || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 2)
201 || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 2)
202 || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 2)
203 || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 2)
204 || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 2)
205 || test_rnn_with_hidden_output(RandomMat(2, 5), 79, 2)
206 || test_rnn_with_hidden_output(RandomMat(4, 4), 1, 1)
207 || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 1)
208 || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 1)
209 || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 1)
210 || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 1)
211 || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 1)
212 || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 1)
213 || test_rnn_with_hidden_output(RandomMat(2, 5), 79, 1)
214 || test_rnn_with_hidden_output(RandomMat(4, 2), 1, 0)
215 || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 0)
216 || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 0)
217 || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 0)
218 || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 0)
219 || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 0)
220 || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 0)
221 || test_rnn_with_hidden_output(RandomMat(2, 5), 17, 0);
222}
223
224static int test_rnn_2()
225{
226 return 0
227 || test_rnn(RandomMat(4, 1), 1, 0)
228 || test_rnn(RandomMat(8, 2), 2, 0)
229 || test_rnn(RandomMat(16, 8), 7, 0)
230 || test_rnn(RandomMat(17, 8), 8, 0)
231 || test_rnn(RandomMat(19, 15), 8, 0)
232 || test_rnn(RandomMat(5, 16), 16, 0)
233 || test_rnn(RandomMat(3, 16), 8, 0)
234 || test_rnn(RandomMat(8, 16), 16, 0)
235 || test_rnn(RandomMat(2, 5), 17, 0);
236}
237
238static int test_rnn_3()
239{
240 return 0
241 || test_rnn(RandomMat(4, 1), 1, 1)
242 || test_rnn(RandomMat(8, 2), 2, 1)
243 || test_rnn(RandomMat(16, 8), 7, 1)
244 || test_rnn(RandomMat(17, 8), 8, 1)
245 || test_rnn(RandomMat(19, 15), 8, 1)
246 || test_rnn(RandomMat(5, 16), 16, 1)
247 || test_rnn(RandomMat(3, 16), 8, 1)
248 || test_rnn(RandomMat(8, 16), 16, 1)
249 || test_rnn(RandomMat(2, 5), 17, 1);
250}
251
252#if NCNN_INT8
253static int test_rnn_int8(const ncnn::Mat& a, int outch, int direction)
254{
255 int input_size = a.w;
256 int num_directions = direction == 2 ? 2 : 1;
257
258 ncnn::ParamDict pd;
259 pd.set(0, outch);
260 pd.set(1, outch * input_size * num_directions);
261 pd.set(2, direction);
262 pd.set(8, 2); // int8_scale_term
263
264 std::vector<ncnn::Mat> weights(5);
265 weights[0] = RandomS8Mat(outch * input_size * num_directions);
266 weights[1] = RandomMat(outch * num_directions);
267 weights[2] = RandomS8Mat(outch * outch * num_directions);
268 weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
269 weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
270
271 int ret = test_layer("RNN", pd, weights, a);
272 if (ret != 0)
273 {
274 fprintf(stderr, "test_rnn_int8 failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
275 }
276
277 return ret;
278}
279
280int test_rnn_int8_with_hidden(const ncnn::Mat& a, int outch, int direction)
281{
282 int input_size = a.w;
283 int num_directions = direction == 2 ? 2 : 1;
284
285 ncnn::ParamDict pd;
286 pd.set(0, outch);
287 pd.set(1, outch * input_size * num_directions);
288 pd.set(2, direction);
289 pd.set(8, 2); // int8_scale_term
290
291 std::vector<ncnn::Mat> weights(5);
292 weights[0] = RandomS8Mat(outch * input_size * num_directions);
293 weights[1] = RandomMat(outch * num_directions);
294 weights[2] = RandomS8Mat(outch * outch * num_directions);
295 weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
296 weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
297
298 // initial hidden state
299 ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
300
301 std::vector<ncnn::Mat> as(2);
302 as[0] = a;
303 as[1] = hidden;
304
305 int ret = test_layer("RNN", pd, weights, as, 2);
306 if (ret != 0)
307 {
308 fprintf(stderr, "test_rnn_int8_with_hidden failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
309 }
310
311 return ret;
312}
313
314int test_rnn_int8_with_hidden_input(const ncnn::Mat& a, int outch, int direction)
315{
316 int input_size = a.w;
317 int num_directions = direction == 2 ? 2 : 1;
318
319 ncnn::ParamDict pd;
320 pd.set(0, outch);
321 pd.set(1, outch * input_size * num_directions);
322 pd.set(2, direction);
323 pd.set(8, 2); // int8_scale_term
324
325 std::vector<ncnn::Mat> weights(5);
326 weights[0] = RandomS8Mat(outch * input_size * num_directions);
327 weights[1] = RandomMat(outch * num_directions);
328 weights[2] = RandomS8Mat(outch * outch * num_directions);
329 weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
330 weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
331
332 // initial hidden state
333 ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
334
335 std::vector<ncnn::Mat> as(2);
336 as[0] = a;
337 as[1] = hidden;
338
339 int ret = test_layer("RNN", pd, weights, as, 1);
340 if (ret != 0)
341 {
342 fprintf(stderr, "test_rnn_int8_with_hidden_input failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
343 }
344
345 return ret;
346}
347
348int test_rnn_int8_with_hidden_output(const ncnn::Mat& a, int outch, int direction)
349{
350 int input_size = a.w;
351 int num_directions = direction == 2 ? 2 : 1;
352
353 ncnn::ParamDict pd;
354 pd.set(0, outch);
355 pd.set(1, outch * input_size * num_directions);
356 pd.set(2, direction);
357 pd.set(8, 2); // int8_scale_term
358
359 std::vector<ncnn::Mat> weights(5);
360 weights[0] = RandomS8Mat(outch * input_size * num_directions);
361 weights[1] = RandomMat(outch * num_directions);
362 weights[2] = RandomS8Mat(outch * outch * num_directions);
363 weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
364 weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
365
366 std::vector<ncnn::Mat> as(1);
367 as[0] = a;
368
369 int ret = test_layer("RNN", pd, weights, as, 2);
370 if (ret != 0)
371 {
372 fprintf(stderr, "test_rnn_int8_with_hidden_output failed a.dims=%d a=(%d %d %d) outch=%d direction=%d\n", a.dims, a.w, a.h, a.c, outch, direction);
373 }
374
375 return ret;
376}
377
378static int test_rnn_4()
379{
380 return 0
381 || test_rnn_int8(RandomMat(4, 1), 2, 2)
382 || test_rnn_int8(RandomMat(8, 2), 2, 2)
383 || test_rnn_int8(RandomMat(16, 8), 7, 2)
384 || test_rnn_int8(RandomMat(17, 8), 8, 2)
385 || test_rnn_int8(RandomMat(19, 15), 8, 2)
386 || test_rnn_int8(RandomMat(5, 16), 16, 2)
387 || test_rnn_int8(RandomMat(3, 16), 8, 2)
388 || test_rnn_int8(RandomMat(8, 16), 16, 2)
389 || test_rnn_int8(RandomMat(31, 3), 31, 2)
390 || test_rnn_int8(RandomMat(2, 5), 17, 2);
391}
392
393static int test_rnn_5()
394{
395 return 0
396 || test_rnn_int8_with_hidden(RandomMat(4, 4), 1, 2)
397 || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 2)
398 || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 2)
399 || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 2)
400 || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 2)
401 || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 2)
402 || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 2)
403 || test_rnn_int8_with_hidden(RandomMat(2, 5), 79, 2)
404 || test_rnn_int8_with_hidden(RandomMat(4, 4), 1, 1)
405 || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 1)
406 || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 1)
407 || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 1)
408 || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 1)
409 || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 1)
410 || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 1)
411 || test_rnn_int8_with_hidden(RandomMat(2, 5), 79, 1)
412 || test_rnn_int8_with_hidden(RandomMat(4, 2), 1, 0)
413 || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 0)
414 || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 0)
415 || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 0)
416 || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 0)
417 || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 0)
418 || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 0)
419 || test_rnn_int8_with_hidden(RandomMat(2, 5), 17, 0)
420
421 || test_rnn_int8_with_hidden_input(RandomMat(4, 4), 1, 2)
422 || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 2)
423 || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 2)
424 || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 2)
425 || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 2)
426 || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 2)
427 || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 2)
428 || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 79, 2)
429 || test_rnn_int8_with_hidden_input(RandomMat(4, 4), 1, 1)
430 || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 1)
431 || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 1)
432 || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 1)
433 || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 1)
434 || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 1)
435 || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 1)
436 || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 79, 1)
437 || test_rnn_int8_with_hidden_input(RandomMat(4, 2), 1, 0)
438 || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 0)
439 || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 0)
440 || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 0)
441 || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 0)
442 || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 0)
443 || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 0)
444 || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 17, 0)
445
446 || test_rnn_int8_with_hidden_output(RandomMat(4, 4), 1, 2)
447 || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 2)
448 || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 2)
449 || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 2)
450 || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 2)
451 || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 2)
452 || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 2)
453 || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 79, 2)
454 || test_rnn_int8_with_hidden_output(RandomMat(4, 4), 1, 1)
455 || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 1)
456 || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 1)
457 || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 1)
458 || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 1)
459 || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 1)
460 || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 1)
461 || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 79, 1)
462 || test_rnn_int8_with_hidden_output(RandomMat(4, 2), 1, 0)
463 || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 0)
464 || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 0)
465 || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 0)
466 || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 0)
467 || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 0)
468 || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 0)
469 || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 17, 0);
470}
471
472static int test_rnn_6()
473{
474 return 0
475 || test_rnn_int8(RandomMat(4, 1), 1, 0)
476 || test_rnn_int8(RandomMat(8, 2), 2, 0)
477 || test_rnn_int8(RandomMat(16, 8), 7, 0)
478 || test_rnn_int8(RandomMat(17, 8), 8, 0)
479 || test_rnn_int8(RandomMat(19, 15), 8, 0)
480 || test_rnn_int8(RandomMat(5, 16), 16, 0)
481 || test_rnn_int8(RandomMat(3, 16), 8, 0)
482 || test_rnn_int8(RandomMat(8, 16), 16, 0)
483 || test_rnn_int8(RandomMat(2, 5), 17, 0);
484}
485
486static int test_rnn_7()
487{
488 return 0
489 || test_rnn_int8(RandomMat(4, 1), 1, 1)
490 || test_rnn_int8(RandomMat(8, 2), 2, 1)
491 || test_rnn_int8(RandomMat(16, 8), 7, 1)
492 || test_rnn_int8(RandomMat(17, 8), 8, 1)
493 || test_rnn_int8(RandomMat(19, 15), 8, 1)
494 || test_rnn_int8(RandomMat(5, 16), 16, 1)
495 || test_rnn_int8(RandomMat(3, 16), 8, 1)
496 || test_rnn_int8(RandomMat(8, 16), 16, 1)
497 || test_rnn_int8(RandomMat(2, 5), 17, 1);
498}
499#endif
500
501int main()
502{
503 SRAND(7767517);
504
505#if NCNN_INT8
506 return 0
507 || test_rnn_0()
508 || test_rnn_1()
509 || test_rnn_2()
510 || test_rnn_3()
511 || test_rnn_4()
512 || test_rnn_5()
513 || test_rnn_6()
514 || test_rnn_7();
515#else
516 return 0
517 || test_rnn_0()
518 || test_rnn_1()
519 || test_rnn_2()
520 || test_rnn_3();
521#endif
522}