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_eltwise.cpp 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2020 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. #include "layer/eltwise.h"
  16. static void print_float_array(const ncnn::Mat& a)
  17. {
  18. fprintf(stderr, "[");
  19. for (int i=0; i<a.w; i++)
  20. {
  21. fprintf(stderr, " %f", a[i]);
  22. }
  23. fprintf(stderr, " ]");
  24. }
  25. static int test_eltwise(const std::vector<ncnn::Mat>& a, int op_type, const ncnn::Mat& coeffs)
  26. {
  27. ncnn::ParamDict pd;
  28. pd.set(0, op_type);
  29. pd.set(1, coeffs);
  30. std::vector<ncnn::Mat> weights(0);
  31. ncnn::Option opt;
  32. opt.num_threads = 1;
  33. opt.use_vulkan_compute = true;
  34. opt.use_fp16_packed = false;
  35. opt.use_fp16_storage = false;
  36. opt.use_fp16_arithmetic = false;
  37. opt.use_int8_storage = false;
  38. opt.use_int8_arithmetic = false;
  39. int ret = test_layer<ncnn::Eltwise>("Eltwise", pd, weights, opt, a);
  40. if (ret != 0)
  41. {
  42. fprintf(stderr, "test_eltwise failed a[0].dims=%d a[0]=(%d %d %d) op_type=%d", a[0].dims, a[0].w, a[0].h, a[0].c, op_type);
  43. fprintf(stderr, " coeffs="); print_float_array(coeffs);
  44. fprintf(stderr, "\n");
  45. }
  46. return ret;
  47. }
  48. static int test_eltwise_0()
  49. {
  50. std::vector<ncnn::Mat> a(2);
  51. a[0] = RandomMat(16, 12, 8);
  52. a[1] = RandomMat(16, 12, 8);
  53. return 0
  54. || test_eltwise(a, 0, ncnn::Mat())
  55. || test_eltwise(a, 1, ncnn::Mat())
  56. || test_eltwise(a, 2, ncnn::Mat())
  57. || test_eltwise(a, 0, RandomMat(2))
  58. || test_eltwise(a, 1, RandomMat(2))
  59. || test_eltwise(a, 2, RandomMat(2))
  60. ;
  61. }
  62. static int test_eltwise_1()
  63. {
  64. std::vector<ncnn::Mat> a(4);
  65. a[0] = RandomMat(7, 3, 5);
  66. a[1] = RandomMat(7, 3, 5);
  67. a[2] = RandomMat(7, 3, 5);
  68. a[3] = RandomMat(7, 3, 5);
  69. return 0
  70. || test_eltwise(a, 0, ncnn::Mat())
  71. || test_eltwise(a, 1, ncnn::Mat())
  72. || test_eltwise(a, 2, ncnn::Mat())
  73. || test_eltwise(a, 0, RandomMat(4))
  74. || test_eltwise(a, 1, RandomMat(4))
  75. || test_eltwise(a, 2, RandomMat(4))
  76. ;
  77. }
  78. int main()
  79. {
  80. SRAND(7767517);
  81. return 0
  82. || test_eltwise_0()
  83. || test_eltwise_1()
  84. ;
  85. }