You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_rnn.cpp 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. #include "testutil.h"
  15. static int test_rnn(const ncnn::Mat& a, int outch, int direction)
  16. {
  17. int input_size = a.w;
  18. int num_directions = direction == 2 ? 2 : 1;
  19. ncnn::ParamDict pd;
  20. pd.set(0, outch);
  21. pd.set(1, outch * input_size * num_directions);
  22. pd.set(2, direction);
  23. std::vector<ncnn::Mat> weights(3);
  24. weights[0] = RandomMat(outch * input_size * num_directions);
  25. weights[1] = RandomMat(outch * num_directions);
  26. weights[2] = RandomMat(outch * outch * num_directions);
  27. int ret = test_layer("RNN", pd, weights, a);
  28. if (ret != 0)
  29. {
  30. 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);
  31. }
  32. return ret;
  33. }
  34. int test_rnn_with_hidden(const ncnn::Mat& a, int outch, int direction)
  35. {
  36. int input_size = a.w;
  37. int num_directions = direction == 2 ? 2 : 1;
  38. ncnn::ParamDict pd;
  39. pd.set(0, outch);
  40. pd.set(1, outch * input_size * num_directions);
  41. pd.set(2, direction);
  42. std::vector<ncnn::Mat> weights(3);
  43. weights[0] = RandomMat(outch * input_size * num_directions);
  44. weights[1] = RandomMat(outch * num_directions);
  45. weights[2] = RandomMat(outch * outch * num_directions);
  46. // initial hidden state
  47. ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
  48. std::vector<ncnn::Mat> as(2);
  49. as[0] = a;
  50. as[1] = hidden;
  51. int ret = test_layer("RNN", pd, weights, as, 2);
  52. if (ret != 0)
  53. {
  54. 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);
  55. }
  56. return ret;
  57. }
  58. int test_rnn_with_hidden_input(const ncnn::Mat& a, int outch, int direction)
  59. {
  60. int input_size = a.w;
  61. int num_directions = direction == 2 ? 2 : 1;
  62. ncnn::ParamDict pd;
  63. pd.set(0, outch);
  64. pd.set(1, outch * input_size * num_directions);
  65. pd.set(2, direction);
  66. std::vector<ncnn::Mat> weights(3);
  67. weights[0] = RandomMat(outch * input_size * num_directions);
  68. weights[1] = RandomMat(outch * num_directions);
  69. weights[2] = RandomMat(outch * outch * num_directions);
  70. // initial hidden state
  71. ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
  72. std::vector<ncnn::Mat> as(2);
  73. as[0] = a;
  74. as[1] = hidden;
  75. int ret = test_layer("RNN", pd, weights, as, 1);
  76. if (ret != 0)
  77. {
  78. 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);
  79. }
  80. return ret;
  81. }
  82. int test_rnn_with_hidden_output(const ncnn::Mat& a, int outch, int direction)
  83. {
  84. int input_size = a.w;
  85. int num_directions = direction == 2 ? 2 : 1;
  86. ncnn::ParamDict pd;
  87. pd.set(0, outch);
  88. pd.set(1, outch * input_size * num_directions);
  89. pd.set(2, direction);
  90. std::vector<ncnn::Mat> weights(3);
  91. weights[0] = RandomMat(outch * input_size * num_directions);
  92. weights[1] = RandomMat(outch * num_directions);
  93. weights[2] = RandomMat(outch * outch * num_directions);
  94. std::vector<ncnn::Mat> as(1);
  95. as[0] = a;
  96. int ret = test_layer("RNN", pd, weights, as, 2);
  97. if (ret != 0)
  98. {
  99. 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);
  100. }
  101. return ret;
  102. }
  103. static int test_rnn_0()
  104. {
  105. return 0
  106. || test_rnn(RandomMat(4, 1), 2, 2)
  107. || test_rnn(RandomMat(8, 2), 2, 2)
  108. || test_rnn(RandomMat(16, 8), 7, 2)
  109. || test_rnn(RandomMat(17, 8), 8, 2)
  110. || test_rnn(RandomMat(19, 15), 8, 2)
  111. || test_rnn(RandomMat(5, 16), 16, 2)
  112. || test_rnn(RandomMat(3, 16), 8, 2)
  113. || test_rnn(RandomMat(8, 16), 16, 2)
  114. || test_rnn(RandomMat(31, 3), 31, 2)
  115. || test_rnn(RandomMat(2, 5), 17, 2);
  116. }
  117. static int test_rnn_1()
  118. {
  119. return 0
  120. || test_rnn_with_hidden(RandomMat(4, 4), 1, 2)
  121. || test_rnn_with_hidden(RandomMat(8, 2), 2, 2)
  122. || test_rnn_with_hidden(RandomMat(16, 8), 7, 2)
  123. || test_rnn_with_hidden(RandomMat(17, 8), 8, 2)
  124. || test_rnn_with_hidden(RandomMat(19, 15), 8, 2)
  125. || test_rnn_with_hidden(RandomMat(5, 16), 16, 2)
  126. || test_rnn_with_hidden(RandomMat(3, 16), 8, 2)
  127. || test_rnn_with_hidden(RandomMat(2, 5), 79, 2)
  128. || test_rnn_with_hidden(RandomMat(4, 4), 1, 1)
  129. || test_rnn_with_hidden(RandomMat(8, 2), 2, 1)
  130. || test_rnn_with_hidden(RandomMat(16, 8), 7, 1)
  131. || test_rnn_with_hidden(RandomMat(17, 8), 8, 1)
  132. || test_rnn_with_hidden(RandomMat(19, 15), 8, 1)
  133. || test_rnn_with_hidden(RandomMat(5, 16), 16, 1)
  134. || test_rnn_with_hidden(RandomMat(3, 16), 8, 1)
  135. || test_rnn_with_hidden(RandomMat(2, 5), 79, 1)
  136. || test_rnn_with_hidden(RandomMat(4, 2), 1, 0)
  137. || test_rnn_with_hidden(RandomMat(8, 2), 2, 0)
  138. || test_rnn_with_hidden(RandomMat(16, 8), 7, 0)
  139. || test_rnn_with_hidden(RandomMat(17, 8), 8, 0)
  140. || test_rnn_with_hidden(RandomMat(19, 15), 8, 0)
  141. || test_rnn_with_hidden(RandomMat(5, 16), 16, 0)
  142. || test_rnn_with_hidden(RandomMat(3, 16), 8, 0)
  143. || test_rnn_with_hidden(RandomMat(2, 5), 17, 0)
  144. || test_rnn_with_hidden_input(RandomMat(4, 4), 1, 2)
  145. || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 2)
  146. || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 2)
  147. || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 2)
  148. || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 2)
  149. || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 2)
  150. || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 2)
  151. || test_rnn_with_hidden_input(RandomMat(2, 5), 79, 2)
  152. || test_rnn_with_hidden_input(RandomMat(4, 4), 1, 1)
  153. || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 1)
  154. || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 1)
  155. || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 1)
  156. || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 1)
  157. || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 1)
  158. || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 1)
  159. || test_rnn_with_hidden_input(RandomMat(2, 5), 79, 1)
  160. || test_rnn_with_hidden_input(RandomMat(4, 2), 1, 0)
  161. || test_rnn_with_hidden_input(RandomMat(8, 2), 2, 0)
  162. || test_rnn_with_hidden_input(RandomMat(16, 8), 7, 0)
  163. || test_rnn_with_hidden_input(RandomMat(17, 8), 8, 0)
  164. || test_rnn_with_hidden_input(RandomMat(19, 15), 8, 0)
  165. || test_rnn_with_hidden_input(RandomMat(5, 16), 16, 0)
  166. || test_rnn_with_hidden_input(RandomMat(3, 16), 8, 0)
  167. || test_rnn_with_hidden_input(RandomMat(2, 5), 17, 0)
  168. || test_rnn_with_hidden_output(RandomMat(4, 4), 1, 2)
  169. || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 2)
  170. || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 2)
  171. || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 2)
  172. || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 2)
  173. || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 2)
  174. || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 2)
  175. || test_rnn_with_hidden_output(RandomMat(2, 5), 79, 2)
  176. || test_rnn_with_hidden_output(RandomMat(4, 4), 1, 1)
  177. || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 1)
  178. || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 1)
  179. || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 1)
  180. || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 1)
  181. || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 1)
  182. || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 1)
  183. || test_rnn_with_hidden_output(RandomMat(2, 5), 79, 1)
  184. || test_rnn_with_hidden_output(RandomMat(4, 2), 1, 0)
  185. || test_rnn_with_hidden_output(RandomMat(8, 2), 2, 0)
  186. || test_rnn_with_hidden_output(RandomMat(16, 8), 7, 0)
  187. || test_rnn_with_hidden_output(RandomMat(17, 8), 8, 0)
  188. || test_rnn_with_hidden_output(RandomMat(19, 15), 8, 0)
  189. || test_rnn_with_hidden_output(RandomMat(5, 16), 16, 0)
  190. || test_rnn_with_hidden_output(RandomMat(3, 16), 8, 0)
  191. || test_rnn_with_hidden_output(RandomMat(2, 5), 17, 0);
  192. }
  193. static int test_rnn_2()
  194. {
  195. return 0
  196. || test_rnn(RandomMat(4, 1), 1, 0)
  197. || test_rnn(RandomMat(8, 2), 2, 0)
  198. || test_rnn(RandomMat(16, 8), 7, 0)
  199. || test_rnn(RandomMat(17, 8), 8, 0)
  200. || test_rnn(RandomMat(19, 15), 8, 0)
  201. || test_rnn(RandomMat(5, 16), 16, 0)
  202. || test_rnn(RandomMat(3, 16), 8, 0)
  203. || test_rnn(RandomMat(8, 16), 16, 0)
  204. || test_rnn(RandomMat(2, 5), 17, 0);
  205. }
  206. static int test_rnn_3()
  207. {
  208. return 0
  209. || test_rnn(RandomMat(4, 1), 1, 1)
  210. || test_rnn(RandomMat(8, 2), 2, 1)
  211. || test_rnn(RandomMat(16, 8), 7, 1)
  212. || test_rnn(RandomMat(17, 8), 8, 1)
  213. || test_rnn(RandomMat(19, 15), 8, 1)
  214. || test_rnn(RandomMat(5, 16), 16, 1)
  215. || test_rnn(RandomMat(3, 16), 8, 1)
  216. || test_rnn(RandomMat(8, 16), 16, 1)
  217. || test_rnn(RandomMat(2, 5), 17, 1);
  218. }
  219. #if NCNN_INT8
  220. static int test_rnn_int8(const ncnn::Mat& a, int outch, int direction)
  221. {
  222. int input_size = a.w;
  223. int num_directions = direction == 2 ? 2 : 1;
  224. ncnn::ParamDict pd;
  225. pd.set(0, outch);
  226. pd.set(1, outch * input_size * num_directions);
  227. pd.set(2, direction);
  228. pd.set(8, 2); // int8_scale_term
  229. std::vector<ncnn::Mat> weights(5);
  230. weights[0] = RandomS8Mat(outch * input_size * num_directions);
  231. weights[1] = RandomMat(outch * num_directions);
  232. weights[2] = RandomS8Mat(outch * outch * num_directions);
  233. weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
  234. weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
  235. int ret = test_layer("RNN", pd, weights, a);
  236. if (ret != 0)
  237. {
  238. 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);
  239. }
  240. return ret;
  241. }
  242. int test_rnn_int8_with_hidden(const ncnn::Mat& a, int outch, int direction)
  243. {
  244. int input_size = a.w;
  245. int num_directions = direction == 2 ? 2 : 1;
  246. ncnn::ParamDict pd;
  247. pd.set(0, outch);
  248. pd.set(1, outch * input_size * num_directions);
  249. pd.set(2, direction);
  250. pd.set(8, 2); // int8_scale_term
  251. std::vector<ncnn::Mat> weights(5);
  252. weights[0] = RandomS8Mat(outch * input_size * num_directions);
  253. weights[1] = RandomMat(outch * num_directions);
  254. weights[2] = RandomS8Mat(outch * outch * num_directions);
  255. weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
  256. weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
  257. // initial hidden state
  258. ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
  259. std::vector<ncnn::Mat> as(2);
  260. as[0] = a;
  261. as[1] = hidden;
  262. int ret = test_layer("RNN", pd, weights, as, 2);
  263. if (ret != 0)
  264. {
  265. 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);
  266. }
  267. return ret;
  268. }
  269. int test_rnn_int8_with_hidden_input(const ncnn::Mat& a, int outch, int direction)
  270. {
  271. int input_size = a.w;
  272. int num_directions = direction == 2 ? 2 : 1;
  273. ncnn::ParamDict pd;
  274. pd.set(0, outch);
  275. pd.set(1, outch * input_size * num_directions);
  276. pd.set(2, direction);
  277. pd.set(8, 2); // int8_scale_term
  278. std::vector<ncnn::Mat> weights(5);
  279. weights[0] = RandomS8Mat(outch * input_size * num_directions);
  280. weights[1] = RandomMat(outch * num_directions);
  281. weights[2] = RandomS8Mat(outch * outch * num_directions);
  282. weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
  283. weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
  284. // initial hidden state
  285. ncnn::Mat hidden = RandomMat(outch, num_directions, -1.f, 1.f);
  286. std::vector<ncnn::Mat> as(2);
  287. as[0] = a;
  288. as[1] = hidden;
  289. int ret = test_layer("RNN", pd, weights, as, 1);
  290. if (ret != 0)
  291. {
  292. 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);
  293. }
  294. return ret;
  295. }
  296. int test_rnn_int8_with_hidden_output(const ncnn::Mat& a, int outch, int direction)
  297. {
  298. int input_size = a.w;
  299. int num_directions = direction == 2 ? 2 : 1;
  300. ncnn::ParamDict pd;
  301. pd.set(0, outch);
  302. pd.set(1, outch * input_size * num_directions);
  303. pd.set(2, direction);
  304. pd.set(8, 2); // int8_scale_term
  305. std::vector<ncnn::Mat> weights(5);
  306. weights[0] = RandomS8Mat(outch * input_size * num_directions);
  307. weights[1] = RandomMat(outch * num_directions);
  308. weights[2] = RandomS8Mat(outch * outch * num_directions);
  309. weights[3] = RandomMat(outch * num_directions, 100.f, 200.f);
  310. weights[4] = RandomMat(outch * num_directions, 100.f, 200.f);
  311. std::vector<ncnn::Mat> as(1);
  312. as[0] = a;
  313. int ret = test_layer("RNN", pd, weights, as, 2);
  314. if (ret != 0)
  315. {
  316. 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);
  317. }
  318. return ret;
  319. }
  320. static int test_rnn_4()
  321. {
  322. return 0
  323. || test_rnn_int8(RandomMat(4, 1), 2, 2)
  324. || test_rnn_int8(RandomMat(8, 2), 2, 2)
  325. || test_rnn_int8(RandomMat(16, 8), 7, 2)
  326. || test_rnn_int8(RandomMat(17, 8), 8, 2)
  327. || test_rnn_int8(RandomMat(19, 15), 8, 2)
  328. || test_rnn_int8(RandomMat(5, 16), 16, 2)
  329. || test_rnn_int8(RandomMat(3, 16), 8, 2)
  330. || test_rnn_int8(RandomMat(8, 16), 16, 2)
  331. || test_rnn_int8(RandomMat(31, 3), 31, 2)
  332. || test_rnn_int8(RandomMat(2, 5), 17, 2);
  333. }
  334. static int test_rnn_5()
  335. {
  336. return 0
  337. || test_rnn_int8_with_hidden(RandomMat(4, 4), 1, 2)
  338. || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 2)
  339. || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 2)
  340. || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 2)
  341. || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 2)
  342. || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 2)
  343. || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 2)
  344. || test_rnn_int8_with_hidden(RandomMat(2, 5), 79, 2)
  345. || test_rnn_int8_with_hidden(RandomMat(4, 4), 1, 1)
  346. || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 1)
  347. || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 1)
  348. || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 1)
  349. || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 1)
  350. || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 1)
  351. || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 1)
  352. || test_rnn_int8_with_hidden(RandomMat(2, 5), 79, 1)
  353. || test_rnn_int8_with_hidden(RandomMat(4, 2), 1, 0)
  354. || test_rnn_int8_with_hidden(RandomMat(8, 2), 2, 0)
  355. || test_rnn_int8_with_hidden(RandomMat(16, 8), 7, 0)
  356. || test_rnn_int8_with_hidden(RandomMat(17, 8), 8, 0)
  357. || test_rnn_int8_with_hidden(RandomMat(19, 15), 8, 0)
  358. || test_rnn_int8_with_hidden(RandomMat(5, 16), 16, 0)
  359. || test_rnn_int8_with_hidden(RandomMat(3, 16), 8, 0)
  360. || test_rnn_int8_with_hidden(RandomMat(2, 5), 17, 0)
  361. || test_rnn_int8_with_hidden_input(RandomMat(4, 4), 1, 2)
  362. || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 2)
  363. || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 2)
  364. || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 2)
  365. || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 2)
  366. || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 2)
  367. || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 2)
  368. || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 79, 2)
  369. || test_rnn_int8_with_hidden_input(RandomMat(4, 4), 1, 1)
  370. || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 1)
  371. || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 1)
  372. || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 1)
  373. || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 1)
  374. || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 1)
  375. || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 1)
  376. || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 79, 1)
  377. || test_rnn_int8_with_hidden_input(RandomMat(4, 2), 1, 0)
  378. || test_rnn_int8_with_hidden_input(RandomMat(8, 2), 2, 0)
  379. || test_rnn_int8_with_hidden_input(RandomMat(16, 8), 7, 0)
  380. || test_rnn_int8_with_hidden_input(RandomMat(17, 8), 8, 0)
  381. || test_rnn_int8_with_hidden_input(RandomMat(19, 15), 8, 0)
  382. || test_rnn_int8_with_hidden_input(RandomMat(5, 16), 16, 0)
  383. || test_rnn_int8_with_hidden_input(RandomMat(3, 16), 8, 0)
  384. || test_rnn_int8_with_hidden_input(RandomMat(2, 5), 17, 0)
  385. || test_rnn_int8_with_hidden_output(RandomMat(4, 4), 1, 2)
  386. || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 2)
  387. || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 2)
  388. || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 2)
  389. || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 2)
  390. || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 2)
  391. || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 2)
  392. || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 79, 2)
  393. || test_rnn_int8_with_hidden_output(RandomMat(4, 4), 1, 1)
  394. || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 1)
  395. || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 1)
  396. || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 1)
  397. || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 1)
  398. || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 1)
  399. || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 1)
  400. || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 79, 1)
  401. || test_rnn_int8_with_hidden_output(RandomMat(4, 2), 1, 0)
  402. || test_rnn_int8_with_hidden_output(RandomMat(8, 2), 2, 0)
  403. || test_rnn_int8_with_hidden_output(RandomMat(16, 8), 7, 0)
  404. || test_rnn_int8_with_hidden_output(RandomMat(17, 8), 8, 0)
  405. || test_rnn_int8_with_hidden_output(RandomMat(19, 15), 8, 0)
  406. || test_rnn_int8_with_hidden_output(RandomMat(5, 16), 16, 0)
  407. || test_rnn_int8_with_hidden_output(RandomMat(3, 16), 8, 0)
  408. || test_rnn_int8_with_hidden_output(RandomMat(2, 5), 17, 0);
  409. }
  410. static int test_rnn_6()
  411. {
  412. return 0
  413. || test_rnn_int8(RandomMat(4, 1), 1, 0)
  414. || test_rnn_int8(RandomMat(8, 2), 2, 0)
  415. || test_rnn_int8(RandomMat(16, 8), 7, 0)
  416. || test_rnn_int8(RandomMat(17, 8), 8, 0)
  417. || test_rnn_int8(RandomMat(19, 15), 8, 0)
  418. || test_rnn_int8(RandomMat(5, 16), 16, 0)
  419. || test_rnn_int8(RandomMat(3, 16), 8, 0)
  420. || test_rnn_int8(RandomMat(8, 16), 16, 0)
  421. || test_rnn_int8(RandomMat(2, 5), 17, 0);
  422. }
  423. static int test_rnn_7()
  424. {
  425. return 0
  426. || test_rnn_int8(RandomMat(4, 1), 1, 1)
  427. || test_rnn_int8(RandomMat(8, 2), 2, 1)
  428. || test_rnn_int8(RandomMat(16, 8), 7, 1)
  429. || test_rnn_int8(RandomMat(17, 8), 8, 1)
  430. || test_rnn_int8(RandomMat(19, 15), 8, 1)
  431. || test_rnn_int8(RandomMat(5, 16), 16, 1)
  432. || test_rnn_int8(RandomMat(3, 16), 8, 1)
  433. || test_rnn_int8(RandomMat(8, 16), 16, 1)
  434. || test_rnn_int8(RandomMat(2, 5), 17, 1);
  435. }
  436. #endif
  437. int main()
  438. {
  439. SRAND(7767517);
  440. #if NCNN_INT8
  441. return 0
  442. || test_rnn_0()
  443. || test_rnn_1()
  444. || test_rnn_2()
  445. || test_rnn_3()
  446. || test_rnn_4()
  447. || test_rnn_5()
  448. || test_rnn_6()
  449. || test_rnn_7();
  450. #else
  451. return 0
  452. || test_rnn_0()
  453. || test_rnn_1()
  454. || test_rnn_2()
  455. || test_rnn_3();
  456. #endif
  457. }