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 3.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_gelu(const ncnn::Mat& a, bool fast_gelu)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, fast_gelu ? 1 : 0);
  19. std::vector<ncnn::Mat> weights(0);
  20. int ret = test_layer("GELU", pd, weights, a);
  21. if (ret != 0)
  22. {
  23. 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");
  24. }
  25. return ret;
  26. }
  27. static int test_gelu_0()
  28. {
  29. return 0
  30. || test_gelu(RandomMat(6, 7, 9, 32), false)
  31. || test_gelu(RandomMat(6, 7, 9, 32), true)
  32. || test_gelu(RandomMat(5, 6, 7, 24), false)
  33. || test_gelu(RandomMat(5, 6, 7, 24), true)
  34. || test_gelu(RandomMat(7, 8, 9, 12), false)
  35. || test_gelu(RandomMat(7, 8, 9, 12), true)
  36. || test_gelu(RandomMat(3, 4, 5, 13), false)
  37. || test_gelu(RandomMat(3, 4, 5, 13), true);
  38. }
  39. static int test_gelu_1()
  40. {
  41. return 0
  42. || test_gelu(RandomMat(9, 7, 32), false)
  43. || test_gelu(RandomMat(9, 7, 32), true)
  44. || test_gelu(RandomMat(5, 7, 24), false)
  45. || test_gelu(RandomMat(5, 7, 24), true)
  46. || test_gelu(RandomMat(7, 9, 12), false)
  47. || test_gelu(RandomMat(7, 9, 12), true)
  48. || test_gelu(RandomMat(3, 5, 13), false)
  49. || test_gelu(RandomMat(3, 5, 13), true);
  50. }
  51. static int test_gelu_2()
  52. {
  53. return 0
  54. || test_gelu(RandomMat(13, 32), false)
  55. || test_gelu(RandomMat(13, 32), true)
  56. || test_gelu(RandomMat(15, 24), false)
  57. || test_gelu(RandomMat(15, 24), true)
  58. || test_gelu(RandomMat(17, 12), false)
  59. || test_gelu(RandomMat(17, 12), true)
  60. || test_gelu(RandomMat(19, 15), false)
  61. || test_gelu(RandomMat(19, 15), true);
  62. }
  63. static int test_gelu_3()
  64. {
  65. return 0
  66. || test_gelu(RandomMat(128), false)
  67. || test_gelu(RandomMat(128), true)
  68. || test_gelu(RandomMat(124), false)
  69. || test_gelu(RandomMat(124), true)
  70. || test_gelu(RandomMat(127), false)
  71. || test_gelu(RandomMat(127), true)
  72. || test_gelu(RandomMat(120), false)
  73. || test_gelu(RandomMat(120), true);
  74. }
  75. int main()
  76. {
  77. SRAND(7767517);
  78. return 0
  79. || test_gelu_0()
  80. || test_gelu_1()
  81. || test_gelu_2()
  82. || test_gelu_3();
  83. }