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.

resize.cpp 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * \file dnn/test/arm_common/resize.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #include "test/common/resize.h"
  13. #include "test/arm_common/fixture.h"
  14. #include "test/common/checker.h"
  15. namespace megdnn {
  16. namespace test {
  17. using namespace resize;
  18. static void set_nchw_args(IMode imode, std::vector<TestArg>& args) {
  19. param::Resize param;
  20. param.format = param::Resize::Format::NCHW;
  21. param.imode = imode;
  22. rep(n, 4ul) rep(c, 4ul) rep(ih, 4ul) rep(iw, 4ul) rep(oh, 4ul) rep(ow, 4ul)
  23. args.emplace_back(
  24. param, TensorShape{n + 1ul, c + 1ul, ih + 1ul, iw + 1ul},
  25. TensorShape{n + 1ul, c + 1ul, oh + 1ul, ow + 1ul});
  26. args.emplace_back(param, TensorShape{1, 1, 10, 10},
  27. TensorShape{1, 1, 20, 20});
  28. args.emplace_back(param, TensorShape{1, 1, 10, 10},
  29. TensorShape{1, 1, 7, 9});
  30. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 2, 6, 8});
  31. args.emplace_back(param, TensorShape{1, 2, 6, 8}, TensorShape{1, 2, 3, 4});
  32. }
  33. TEST_F(ARM_COMMON, RESIZE_CV) {
  34. std::vector<TestArg> args = get_cv_args();
  35. Checker<Resize> checker(handle());
  36. for (auto&& arg : args) {
  37. checker.set_param(arg.param)
  38. .set_epsilon(1 + 1e-3)
  39. .set_dtype(0, dtype::Uint8())
  40. .set_dtype(1, dtype::Uint8())
  41. .execs({arg.src, arg.dst});
  42. }
  43. for (auto&& arg : args) {
  44. checker.set_param(arg.param)
  45. .set_dtype(0, dtype::Float32())
  46. .set_dtype(1, dtype::Float32())
  47. .execs({arg.src, arg.dst});
  48. }
  49. }
  50. #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  51. TEST_F(ARM_COMMON, RESIZE_NCHW_FP16) {
  52. std::vector<TestArg> args;
  53. set_nchw_args(IMode::INTER_LINEAR, args);
  54. set_nchw_args(IMode::INTER_NEAREST, args);
  55. Checker<Resize> checker(handle());
  56. for (auto&& arg : args) {
  57. checker.set_param(arg.param)
  58. .set_epsilon(0.01)
  59. .set_dtype(0, dtype::Float16())
  60. .set_dtype(1, dtype::Float16())
  61. .execs({arg.src, arg.dst});
  62. }
  63. }
  64. #endif
  65. TEST_F(ARM_COMMON, RESIZE_NCHW_FP32) {
  66. std::vector<TestArg> args;
  67. set_nchw_args(IMode::INTER_LINEAR, args);
  68. set_nchw_args(IMode::INTER_NEAREST, args);
  69. Checker<Resize> checker(handle());
  70. for (auto&& arg : args) {
  71. checker.set_param(arg.param)
  72. .set_dtype(0, dtype::Float32())
  73. .set_dtype(1, dtype::Float32())
  74. .execs({arg.src, arg.dst});
  75. }
  76. }
  77. TEST_F(ARM_COMMON, RESIZE_NCHW44_FP32) {
  78. std::vector<TestArg> args = get_nchw44_args();
  79. Checker<Resize> checker(handle());
  80. for (auto&& arg : args) {
  81. checker.set_param(arg.param)
  82. .set_dtype(0, dtype::Float32())
  83. .set_dtype(1, dtype::Float32())
  84. .execs({arg.src, arg.dst});
  85. }
  86. }
  87. #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  88. TEST_F(ARM_COMMON, RESIZE_NCHW88_FP16) {
  89. std::vector<TestArg> args = get_nchw88_args();
  90. Checker<Resize> checker(handle());
  91. for (auto&& arg : args) {
  92. checker.set_param(arg.param)
  93. .set_epsilon(0.01)
  94. .set_dtype(0, dtype::Float16())
  95. .set_dtype(1, dtype::Float16())
  96. .execs({arg.src, arg.dst});
  97. }
  98. }
  99. #endif
  100. } // namespace test
  101. } // namespace megdnn
  102. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台