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_gru.cpp 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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_gru(int size, int T, int outch, int direction)
  16. {
  17. ncnn::Mat a = RandomMat(size, T);
  18. int num_directions = direction == 2 ? 2 : 1;
  19. ncnn::ParamDict pd;
  20. pd.set(0, outch);
  21. pd.set(1, outch * size * 3 * num_directions);
  22. pd.set(2, direction);
  23. std::vector<ncnn::Mat> weights(3);
  24. weights[0] = RandomMat(outch * size * 3 * num_directions);
  25. weights[1] = RandomMat(outch * 4 * num_directions);
  26. weights[2] = RandomMat(outch * outch * 3 * num_directions);
  27. int ret = test_layer("GRU", pd, weights, a);
  28. if (ret != 0)
  29. {
  30. fprintf(stderr, "test_gru failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  31. }
  32. return ret;
  33. }
  34. static int test_gru_with_hidden(int size, int T, int outch, int direction)
  35. {
  36. ncnn::Mat a = RandomMat(size, T);
  37. int num_directions = direction == 2 ? 2 : 1;
  38. ncnn::ParamDict pd;
  39. pd.set(0, outch);
  40. pd.set(1, outch * size * 3 * num_directions);
  41. pd.set(2, direction);
  42. std::vector<ncnn::Mat> weights(3);
  43. weights[0] = RandomMat(outch * size * 3 * num_directions);
  44. weights[1] = RandomMat(outch * 4 * num_directions);
  45. weights[2] = RandomMat(outch * outch * 3 * num_directions);
  46. // initial hidden state
  47. ncnn::Mat hidden = RandomMat(outch, num_directions);
  48. std::vector<ncnn::Mat> as(2);
  49. as[0] = a;
  50. as[1] = hidden;
  51. int ret = test_layer("GRU", pd, weights, as, 2);
  52. if (ret != 0)
  53. {
  54. fprintf(stderr, "test_gru_with_hidden failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  55. }
  56. return ret;
  57. }
  58. static int test_gru_with_hidden_input(int size, int T, int outch, int direction)
  59. {
  60. ncnn::Mat a = RandomMat(size, T);
  61. int num_directions = direction == 2 ? 2 : 1;
  62. ncnn::ParamDict pd;
  63. pd.set(0, outch);
  64. pd.set(1, outch * size * 3 * num_directions);
  65. pd.set(2, direction);
  66. std::vector<ncnn::Mat> weights(3);
  67. weights[0] = RandomMat(outch * size * 3 * num_directions);
  68. weights[1] = RandomMat(outch * 4 * num_directions);
  69. weights[2] = RandomMat(outch * outch * 3 * num_directions);
  70. // initial hidden state
  71. ncnn::Mat hidden = RandomMat(outch, num_directions);
  72. std::vector<ncnn::Mat> as(2);
  73. as[0] = a;
  74. as[1] = hidden;
  75. int ret = test_layer("GRU", pd, weights, as, 1);
  76. if (ret != 0)
  77. {
  78. fprintf(stderr, "test_gru_with_hidden_input failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  79. }
  80. return ret;
  81. }
  82. static int test_gru_with_hidden_output(int size, int T, int outch, int direction)
  83. {
  84. ncnn::Mat a = RandomMat(size, T);
  85. int num_directions = direction == 2 ? 2 : 1;
  86. ncnn::ParamDict pd;
  87. pd.set(0, outch);
  88. pd.set(1, outch * size * 3 * num_directions);
  89. pd.set(2, direction);
  90. std::vector<ncnn::Mat> weights(3);
  91. weights[0] = RandomMat(outch * size * 3 * num_directions);
  92. weights[1] = RandomMat(outch * 4 * num_directions);
  93. weights[2] = RandomMat(outch * outch * 3 * num_directions);
  94. std::vector<ncnn::Mat> as(1);
  95. as[0] = a;
  96. int ret = test_layer("GRU", pd, weights, as, 2);
  97. if (ret != 0)
  98. {
  99. fprintf(stderr, "test_gru_with_hidden_output failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  100. }
  101. return ret;
  102. }
  103. static int test_gru_0()
  104. {
  105. return 0
  106. || test_gru(4, 1, 2, 2)
  107. || test_gru(8, 2, 2, 2)
  108. || test_gru(16, 8, 7, 2)
  109. || test_gru(17, 8, 8, 2)
  110. || test_gru(19, 15, 8, 2)
  111. || test_gru(5, 16, 16, 2)
  112. || test_gru(3, 16, 8, 2)
  113. || test_gru(8, 16, 16, 2)
  114. || test_gru(31, 3, 31, 2)
  115. || test_gru(2, 5, 17, 2);
  116. }
  117. static int test_gru_1()
  118. {
  119. return 0
  120. || test_gru_with_hidden(4, 4, 1, 2)
  121. || test_gru_with_hidden(8, 2, 2, 2)
  122. || test_gru_with_hidden(16, 8, 7, 2)
  123. || test_gru_with_hidden(17, 8, 8, 2)
  124. || test_gru_with_hidden(19, 15, 8, 2)
  125. || test_gru_with_hidden(5, 16, 16, 2)
  126. || test_gru_with_hidden(3, 16, 8, 2)
  127. || test_gru_with_hidden(2, 5, 79, 2)
  128. || test_gru_with_hidden(4, 4, 1, 1)
  129. || test_gru_with_hidden(8, 2, 2, 1)
  130. || test_gru_with_hidden(16, 8, 7, 1)
  131. || test_gru_with_hidden(17, 8, 8, 1)
  132. || test_gru_with_hidden(19, 15, 8, 1)
  133. || test_gru_with_hidden(5, 16, 16, 1)
  134. || test_gru_with_hidden(3, 16, 8, 1)
  135. || test_gru_with_hidden(2, 5, 79, 1)
  136. || test_gru_with_hidden(4, 2, 1, 0)
  137. || test_gru_with_hidden(8, 2, 2, 0)
  138. || test_gru_with_hidden(16, 8, 7, 0)
  139. || test_gru_with_hidden(17, 8, 8, 0)
  140. || test_gru_with_hidden(19, 15, 8, 0)
  141. || test_gru_with_hidden(5, 16, 16, 0)
  142. || test_gru_with_hidden(3, 16, 8, 0)
  143. || test_gru_with_hidden(2, 5, 17, 0)
  144. || test_gru_with_hidden_input(4, 4, 1, 2)
  145. || test_gru_with_hidden_input(8, 2, 2, 2)
  146. || test_gru_with_hidden_input(16, 8, 7, 2)
  147. || test_gru_with_hidden_input(17, 8, 8, 2)
  148. || test_gru_with_hidden_input(19, 15, 8, 2)
  149. || test_gru_with_hidden_input(5, 16, 16, 2)
  150. || test_gru_with_hidden_input(3, 16, 8, 2)
  151. || test_gru_with_hidden_input(2, 5, 79, 2)
  152. || test_gru_with_hidden_input(4, 4, 1, 1)
  153. || test_gru_with_hidden_input(8, 2, 2, 1)
  154. || test_gru_with_hidden_input(16, 8, 7, 1)
  155. || test_gru_with_hidden_input(17, 8, 8, 1)
  156. || test_gru_with_hidden_input(19, 15, 8, 1)
  157. || test_gru_with_hidden_input(5, 16, 16, 1)
  158. || test_gru_with_hidden_input(3, 16, 8, 1)
  159. || test_gru_with_hidden_input(2, 5, 79, 1)
  160. || test_gru_with_hidden_input(4, 2, 1, 0)
  161. || test_gru_with_hidden_input(8, 2, 2, 0)
  162. || test_gru_with_hidden_input(16, 8, 7, 0)
  163. || test_gru_with_hidden_input(17, 8, 8, 0)
  164. || test_gru_with_hidden_input(19, 15, 8, 0)
  165. || test_gru_with_hidden_input(5, 16, 16, 0)
  166. || test_gru_with_hidden_input(3, 16, 8, 0)
  167. || test_gru_with_hidden_input(2, 5, 17, 0)
  168. || test_gru_with_hidden_output(4, 4, 1, 2)
  169. || test_gru_with_hidden_output(8, 2, 2, 2)
  170. || test_gru_with_hidden_output(16, 8, 7, 2)
  171. || test_gru_with_hidden_output(17, 8, 8, 2)
  172. || test_gru_with_hidden_output(19, 15, 8, 2)
  173. || test_gru_with_hidden_output(5, 16, 16, 2)
  174. || test_gru_with_hidden_output(3, 16, 8, 2)
  175. || test_gru_with_hidden_output(2, 5, 79, 2)
  176. || test_gru_with_hidden_output(4, 4, 1, 1)
  177. || test_gru_with_hidden_output(8, 2, 2, 1)
  178. || test_gru_with_hidden_output(16, 8, 7, 1)
  179. || test_gru_with_hidden_output(17, 8, 8, 1)
  180. || test_gru_with_hidden_output(19, 15, 8, 1)
  181. || test_gru_with_hidden_output(5, 16, 16, 1)
  182. || test_gru_with_hidden_output(3, 16, 8, 1)
  183. || test_gru_with_hidden_output(2, 5, 79, 1)
  184. || test_gru_with_hidden_output(4, 2, 1, 0)
  185. || test_gru_with_hidden_output(8, 2, 2, 0)
  186. || test_gru_with_hidden_output(16, 8, 7, 0)
  187. || test_gru_with_hidden_output(17, 8, 8, 0)
  188. || test_gru_with_hidden_output(19, 15, 8, 0)
  189. || test_gru_with_hidden_output(5, 16, 16, 0)
  190. || test_gru_with_hidden_output(3, 16, 8, 0)
  191. || test_gru_with_hidden_output(2, 5, 17, 0);
  192. }
  193. static int test_gru_2()
  194. {
  195. return 0
  196. || test_gru(4, 1, 1, 0)
  197. || test_gru(8, 2, 2, 0)
  198. || test_gru(16, 8, 7, 0)
  199. || test_gru(17, 8, 8, 0)
  200. || test_gru(19, 15, 8, 0)
  201. || test_gru(5, 16, 16, 0)
  202. || test_gru(3, 16, 8, 0)
  203. || test_gru(8, 16, 16, 0)
  204. || test_gru(2, 5, 17, 0);
  205. }
  206. static int test_gru_3()
  207. {
  208. return 0
  209. || test_gru(4, 1, 1, 1)
  210. || test_gru(8, 2, 2, 1)
  211. || test_gru(16, 8, 7, 1)
  212. || test_gru(17, 8, 8, 1)
  213. || test_gru(19, 15, 8, 1)
  214. || test_gru(5, 16, 16, 1)
  215. || test_gru(3, 16, 8, 1)
  216. || test_gru(8, 16, 16, 1)
  217. || test_gru(2, 5, 17, 1);
  218. }
  219. #if NCNN_INT8
  220. static void RandomizeA(ncnn::Mat& m, float absmax)
  221. {
  222. absmax = ncnn::float16_to_float32(ncnn::float32_to_float16(absmax));
  223. absmax = ncnn::bfloat16_to_float32(ncnn::float32_to_bfloat16(absmax));
  224. const int h = m.h;
  225. float* p = m;
  226. for (int i = 0; i < h; i++)
  227. {
  228. float* p = m.row(i);
  229. for (int j = 0; j < m.w; j++)
  230. {
  231. p[j] = RandomFloat(-absmax, absmax);
  232. // drop 0.45 ~ 0.55
  233. float v = p[j] * (127.f / absmax);
  234. float vv = fabs(v - (int)v);
  235. float hp = ncnn::float16_to_float32(ncnn::float32_to_float16(p[j]));
  236. float hv = hp * (127.f / absmax);
  237. float hvv = fabs(hv - (int)hv);
  238. float bp = ncnn::bfloat16_to_float32(ncnn::float32_to_bfloat16(p[j]));
  239. float bv = bp * (127.f / absmax);
  240. float bvv = fabs(bv - (int)bv);
  241. while ((vv > 0.45f && vv < 0.55f) || (hvv > 0.45f && hvv < 0.55f) || (bvv > 0.45f && bvv < 0.55f))
  242. {
  243. p[j] = RandomFloat(-absmax, absmax);
  244. v = p[j] * (127.f / absmax);
  245. vv = fabs(v - (int)v);
  246. hp = ncnn::float16_to_float32(ncnn::float32_to_float16(p[j]));
  247. hv = hp * (127.f / absmax);
  248. hvv = fabs(hv - (int)hv);
  249. bp = ncnn::bfloat16_to_float32(ncnn::float32_to_bfloat16(p[j]));
  250. bv = bp * (127.f / absmax);
  251. bvv = fabs(bv - (int)bv);
  252. }
  253. }
  254. }
  255. // set random a and b
  256. m.row(RandomInt(0, h - 1))[RandomInt(0, m.w - 1)] = -absmax;
  257. m.row(RandomInt(0, h - 1))[RandomInt(0, m.w - 1)] = absmax;
  258. }
  259. static int test_gru_int8(int size, int T, int outch, int direction)
  260. {
  261. int num_directions = direction == 2 ? 2 : 1;
  262. ncnn::ParamDict pd;
  263. pd.set(0, outch);
  264. pd.set(1, outch * size * 3 * num_directions);
  265. pd.set(2, direction);
  266. pd.set(8, 2); // int8_scale_term
  267. std::vector<ncnn::Mat> weights(5);
  268. weights[0] = RandomS8Mat(outch * size * 3 * num_directions);
  269. weights[1] = RandomMat(outch * 4 * num_directions);
  270. weights[2] = RandomS8Mat(outch * outch * 3 * num_directions);
  271. weights[3] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  272. weights[4] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  273. ncnn::Mat a(size, T);
  274. RandomizeA(a, 10.f);
  275. int ret = test_layer("GRU", pd, weights, a);
  276. if (ret != 0)
  277. {
  278. fprintf(stderr, "test_gru_int8 failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  279. }
  280. return ret;
  281. }
  282. static int test_gru_int8_with_hidden(int size, int T, int outch, int direction)
  283. {
  284. int num_directions = direction == 2 ? 2 : 1;
  285. ncnn::ParamDict pd;
  286. pd.set(0, outch);
  287. pd.set(1, outch * size * 3 * num_directions);
  288. pd.set(2, direction);
  289. pd.set(8, 2); // int8_scale_term
  290. std::vector<ncnn::Mat> weights(5);
  291. weights[0] = RandomS8Mat(outch * size * 3 * num_directions);
  292. weights[1] = RandomMat(outch * 4 * num_directions);
  293. weights[2] = RandomS8Mat(outch * outch * 3 * num_directions);
  294. weights[3] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  295. weights[4] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  296. ncnn::Mat a(size, T);
  297. RandomizeA(a, 10.f);
  298. // initial hidden state
  299. ncnn::Mat hidden(outch, num_directions);
  300. RandomizeA(hidden, 10.f);
  301. std::vector<ncnn::Mat> as(2);
  302. as[0] = a;
  303. as[1] = hidden;
  304. int ret = test_layer("GRU", pd, weights, as, 2);
  305. if (ret != 0)
  306. {
  307. fprintf(stderr, "test_gru_int8_with_hidden failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  308. }
  309. return ret;
  310. }
  311. static int test_gru_int8_with_hidden_input(int size, int T, int outch, int direction)
  312. {
  313. int num_directions = direction == 2 ? 2 : 1;
  314. ncnn::ParamDict pd;
  315. pd.set(0, outch);
  316. pd.set(1, outch * size * 3 * num_directions);
  317. pd.set(2, direction);
  318. pd.set(8, 2); // int8_scale_term
  319. std::vector<ncnn::Mat> weights(5);
  320. weights[0] = RandomS8Mat(outch * size * 3 * num_directions);
  321. weights[1] = RandomMat(outch * 4 * num_directions);
  322. weights[2] = RandomS8Mat(outch * outch * 3 * num_directions);
  323. weights[3] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  324. weights[4] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  325. ncnn::Mat a(size, T);
  326. RandomizeA(a, 10.f);
  327. // initial hidden state
  328. ncnn::Mat hidden(outch, num_directions);
  329. RandomizeA(hidden, 10.f);
  330. std::vector<ncnn::Mat> as(2);
  331. as[0] = a;
  332. as[1] = hidden;
  333. int ret = test_layer("GRU", pd, weights, as, 1);
  334. if (ret != 0)
  335. {
  336. fprintf(stderr, "test_gru_int8_with_hidden_input failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  337. }
  338. return ret;
  339. }
  340. static int test_gru_int8_with_hidden_output(int size, int T, int outch, int direction)
  341. {
  342. int num_directions = direction == 2 ? 2 : 1;
  343. ncnn::ParamDict pd;
  344. pd.set(0, outch);
  345. pd.set(1, outch * size * 3 * num_directions);
  346. pd.set(2, direction);
  347. pd.set(8, 2); // int8_scale_term
  348. std::vector<ncnn::Mat> weights(5);
  349. weights[0] = RandomS8Mat(outch * size * 3 * num_directions);
  350. weights[1] = RandomMat(outch * 4 * num_directions);
  351. weights[2] = RandomS8Mat(outch * outch * 3 * num_directions);
  352. weights[3] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  353. weights[4] = RandomMat(outch * 3 * num_directions, 100.f, 200.f);
  354. ncnn::Mat a(size, T);
  355. RandomizeA(a, 10.f);
  356. std::vector<ncnn::Mat> as(1);
  357. as[0] = a;
  358. int ret = test_layer("GRU", pd, weights, as, 2);
  359. if (ret != 0)
  360. {
  361. fprintf(stderr, "test_gru_int8_with_hidden_output failed size=%d T=%d outch=%d direction=%d\n", size, T, outch, direction);
  362. }
  363. return ret;
  364. }
  365. static int test_gru_4()
  366. {
  367. return 0
  368. || test_gru_int8(4, 1, 2, 2)
  369. || test_gru_int8(8, 2, 2, 2)
  370. || test_gru_int8(16, 8, 7, 2)
  371. || test_gru_int8(17, 8, 8, 2)
  372. || test_gru_int8(19, 15, 8, 2)
  373. || test_gru_int8(5, 16, 16, 2)
  374. || test_gru_int8(3, 16, 8, 2)
  375. || test_gru_int8(8, 16, 16, 2)
  376. || test_gru_int8(31, 3, 31, 2)
  377. || test_gru_int8(2, 5, 17, 2);
  378. }
  379. static int test_gru_5()
  380. {
  381. return 0
  382. || test_gru_int8_with_hidden(4, 4, 1, 2)
  383. || test_gru_int8_with_hidden(8, 2, 2, 2)
  384. || test_gru_int8_with_hidden(16, 8, 7, 2)
  385. || test_gru_int8_with_hidden(17, 8, 8, 2)
  386. || test_gru_int8_with_hidden(19, 15, 8, 2)
  387. || test_gru_int8_with_hidden(5, 16, 16, 2)
  388. || test_gru_int8_with_hidden(3, 16, 8, 2)
  389. || test_gru_int8_with_hidden(2, 5, 79, 2)
  390. || test_gru_int8_with_hidden(4, 4, 1, 1)
  391. || test_gru_int8_with_hidden(8, 2, 2, 1)
  392. || test_gru_int8_with_hidden(16, 8, 7, 1)
  393. || test_gru_int8_with_hidden(17, 8, 8, 1)
  394. || test_gru_int8_with_hidden(19, 15, 8, 1)
  395. || test_gru_int8_with_hidden(5, 16, 16, 1)
  396. || test_gru_int8_with_hidden(3, 16, 8, 1)
  397. || test_gru_int8_with_hidden(2, 5, 79, 1)
  398. || test_gru_int8_with_hidden(4, 2, 1, 0)
  399. || test_gru_int8_with_hidden(8, 2, 2, 0)
  400. || test_gru_int8_with_hidden(16, 8, 7, 0)
  401. || test_gru_int8_with_hidden(17, 8, 8, 0)
  402. || test_gru_int8_with_hidden(19, 15, 8, 0)
  403. || test_gru_int8_with_hidden(5, 16, 16, 0)
  404. || test_gru_int8_with_hidden(3, 16, 8, 0)
  405. || test_gru_int8_with_hidden(2, 5, 17, 0)
  406. || test_gru_int8_with_hidden_input(4, 4, 1, 2)
  407. || test_gru_int8_with_hidden_input(8, 2, 2, 2)
  408. || test_gru_int8_with_hidden_input(16, 8, 7, 2)
  409. || test_gru_int8_with_hidden_input(17, 8, 8, 2)
  410. || test_gru_int8_with_hidden_input(19, 15, 8, 2)
  411. || test_gru_int8_with_hidden_input(5, 16, 16, 2)
  412. || test_gru_int8_with_hidden_input(3, 16, 8, 2)
  413. || test_gru_int8_with_hidden_input(2, 5, 79, 2)
  414. || test_gru_int8_with_hidden_input(4, 4, 1, 1)
  415. || test_gru_int8_with_hidden_input(8, 2, 2, 1)
  416. || test_gru_int8_with_hidden_input(16, 8, 7, 1)
  417. || test_gru_int8_with_hidden_input(17, 8, 8, 1)
  418. || test_gru_int8_with_hidden_input(19, 15, 8, 1)
  419. || test_gru_int8_with_hidden_input(5, 16, 16, 1)
  420. || test_gru_int8_with_hidden_input(3, 16, 8, 1)
  421. || test_gru_int8_with_hidden_input(2, 5, 79, 1)
  422. || test_gru_int8_with_hidden_input(4, 2, 1, 0)
  423. || test_gru_int8_with_hidden_input(8, 2, 2, 0)
  424. || test_gru_int8_with_hidden_input(16, 8, 7, 0)
  425. || test_gru_int8_with_hidden_input(17, 8, 8, 0)
  426. || test_gru_int8_with_hidden_input(19, 15, 8, 0)
  427. || test_gru_int8_with_hidden_input(5, 16, 16, 0)
  428. || test_gru_int8_with_hidden_input(3, 16, 8, 0)
  429. || test_gru_int8_with_hidden_input(2, 5, 17, 0)
  430. || test_gru_int8_with_hidden_output(4, 4, 1, 2)
  431. || test_gru_int8_with_hidden_output(8, 2, 2, 2)
  432. || test_gru_int8_with_hidden_output(16, 8, 7, 2)
  433. || test_gru_int8_with_hidden_output(17, 8, 8, 2)
  434. || test_gru_int8_with_hidden_output(19, 15, 8, 2)
  435. || test_gru_int8_with_hidden_output(5, 16, 16, 2)
  436. || test_gru_int8_with_hidden_output(3, 16, 8, 2)
  437. || test_gru_int8_with_hidden_output(2, 5, 79, 2)
  438. || test_gru_int8_with_hidden_output(4, 4, 1, 1)
  439. || test_gru_int8_with_hidden_output(8, 2, 2, 1)
  440. || test_gru_int8_with_hidden_output(16, 8, 7, 1)
  441. || test_gru_int8_with_hidden_output(17, 8, 8, 1)
  442. || test_gru_int8_with_hidden_output(19, 15, 8, 1)
  443. || test_gru_int8_with_hidden_output(5, 16, 16, 1)
  444. || test_gru_int8_with_hidden_output(3, 16, 8, 1)
  445. || test_gru_int8_with_hidden_output(2, 5, 79, 1)
  446. || test_gru_int8_with_hidden_output(4, 2, 1, 0)
  447. || test_gru_int8_with_hidden_output(8, 2, 2, 0)
  448. || test_gru_int8_with_hidden_output(16, 8, 7, 0)
  449. || test_gru_int8_with_hidden_output(17, 8, 8, 0)
  450. || test_gru_int8_with_hidden_output(19, 15, 8, 0)
  451. || test_gru_int8_with_hidden_output(5, 16, 16, 0)
  452. || test_gru_int8_with_hidden_output(3, 16, 8, 0)
  453. || test_gru_int8_with_hidden_output(2, 5, 17, 0);
  454. }
  455. static int test_gru_6()
  456. {
  457. return 0
  458. || test_gru_int8(4, 1, 1, 0)
  459. || test_gru_int8(8, 2, 2, 0)
  460. || test_gru_int8(16, 8, 7, 0)
  461. || test_gru_int8(17, 8, 8, 0)
  462. || test_gru_int8(19, 15, 8, 0)
  463. || test_gru_int8(5, 16, 16, 0)
  464. || test_gru_int8(3, 16, 8, 0)
  465. || test_gru_int8(8, 16, 16, 0)
  466. || test_gru_int8(2, 5, 17, 0);
  467. }
  468. static int test_gru_7()
  469. {
  470. return 0
  471. || test_gru_int8(4, 1, 1, 1)
  472. || test_gru_int8(8, 2, 2, 1)
  473. || test_gru_int8(16, 8, 7, 1)
  474. || test_gru_int8(17, 8, 8, 1)
  475. || test_gru_int8(19, 15, 8, 1)
  476. || test_gru_int8(5, 16, 16, 1)
  477. || test_gru_int8(3, 16, 8, 1)
  478. || test_gru_int8(8, 16, 16, 1)
  479. || test_gru_int8(2, 5, 17, 1);
  480. }
  481. #endif
  482. int main()
  483. {
  484. SRAND(7767517);
  485. #if NCNN_INT8
  486. return 0
  487. || test_gru_0()
  488. || test_gru_1()
  489. || test_gru_2()
  490. || test_gru_3()
  491. || test_gru_4()
  492. || test_gru_5()
  493. || test_gru_6()
  494. || test_gru_7();
  495. #else
  496. return 0
  497. || test_gru_0()
  498. || test_gru_1()
  499. || test_gru_2()
  500. || test_gru_3();
  501. #endif
  502. }