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_gelu.cpp 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2021 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_gelu(const ncnn::Mat& a, bool fast_gelu)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, fast_gelu ? 1 : 0);
  8. std::vector<ncnn::Mat> weights(0);
  9. int ret = test_layer("GELU", pd, weights, a);
  10. if (ret != 0)
  11. {
  12. fprintf(stderr, "test_gelu failed a.dims=%d a=(%d %d %d %d) fast_gelu=%s\n", a.dims, a.w, a.h, a.d, a.c, fast_gelu ? "true" : "false");
  13. }
  14. return ret;
  15. }
  16. static int test_gelu_0()
  17. {
  18. return 0
  19. || test_gelu(RandomMat(6, 7, 9, 32), false)
  20. || test_gelu(RandomMat(6, 7, 9, 32), true)
  21. || test_gelu(RandomMat(5, 6, 7, 24), false)
  22. || test_gelu(RandomMat(5, 6, 7, 24), true)
  23. || test_gelu(RandomMat(7, 8, 9, 12), false)
  24. || test_gelu(RandomMat(7, 8, 9, 12), true)
  25. || test_gelu(RandomMat(3, 4, 5, 13), false)
  26. || test_gelu(RandomMat(3, 4, 5, 13), true);
  27. }
  28. static int test_gelu_1()
  29. {
  30. return 0
  31. || test_gelu(RandomMat(9, 7, 32), false)
  32. || test_gelu(RandomMat(9, 7, 32), true)
  33. || test_gelu(RandomMat(5, 7, 24), false)
  34. || test_gelu(RandomMat(5, 7, 24), true)
  35. || test_gelu(RandomMat(7, 9, 12), false)
  36. || test_gelu(RandomMat(7, 9, 12), true)
  37. || test_gelu(RandomMat(3, 5, 13), false)
  38. || test_gelu(RandomMat(3, 5, 13), true);
  39. }
  40. static int test_gelu_2()
  41. {
  42. return 0
  43. || test_gelu(RandomMat(13, 32), false)
  44. || test_gelu(RandomMat(13, 32), true)
  45. || test_gelu(RandomMat(15, 24), false)
  46. || test_gelu(RandomMat(15, 24), true)
  47. || test_gelu(RandomMat(17, 12), false)
  48. || test_gelu(RandomMat(17, 12), true)
  49. || test_gelu(RandomMat(19, 15), false)
  50. || test_gelu(RandomMat(19, 15), true);
  51. }
  52. static int test_gelu_3()
  53. {
  54. return 0
  55. || test_gelu(RandomMat(128), false)
  56. || test_gelu(RandomMat(128), true)
  57. || test_gelu(RandomMat(124), false)
  58. || test_gelu(RandomMat(124), true)
  59. || test_gelu(RandomMat(127), false)
  60. || test_gelu(RandomMat(127), true)
  61. || test_gelu(RandomMat(120), false)
  62. || test_gelu(RandomMat(120), true);
  63. }
  64. int main()
  65. {
  66. SRAND(7767517);
  67. return 0
  68. || test_gelu_0()
  69. || test_gelu_1()
  70. || test_gelu_2()
  71. || test_gelu_3();
  72. }