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

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