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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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) fast_gelu=%s\n", a.dims, a.w, a.h, 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(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_1()
  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_2()
  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. }