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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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}, TensorShape{1, 1, 20, 20});
  27. args.emplace_back(param, TensorShape{1, 1, 10, 10}, TensorShape{1, 1, 7, 9});
  28. args.emplace_back(param, TensorShape{2, 2, 3, 4}, TensorShape{2, 2, 6, 8});
  29. args.emplace_back(param, TensorShape{1, 2, 6, 8}, TensorShape{1, 2, 3, 4});
  30. }
  31. TEST_F(ARM_COMMON, RESIZE_CV) {
  32. std::vector<TestArg> args = get_cv_args();
  33. Checker<Resize> checker(handle());
  34. for (auto&& arg : args) {
  35. checker.set_param(arg.param)
  36. .set_epsilon(1 + 1e-3)
  37. .set_dtype(0, dtype::Uint8())
  38. .set_dtype(1, dtype::Uint8())
  39. .execs({arg.src, arg.dst});
  40. }
  41. for (auto&& arg : args) {
  42. checker.set_param(arg.param)
  43. .set_dtype(0, dtype::Float32())
  44. .set_dtype(1, dtype::Float32())
  45. .execs({arg.src, arg.dst});
  46. }
  47. }
  48. #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  49. TEST_F(ARM_COMMON, RESIZE_NCHW_FP16) {
  50. std::vector<TestArg> args;
  51. set_nchw_args(IMode::INTER_LINEAR, args);
  52. set_nchw_args(IMode::INTER_NEAREST, args);
  53. Checker<Resize> checker(handle());
  54. for (auto&& arg : args) {
  55. checker.set_param(arg.param)
  56. .set_epsilon(0.01)
  57. .set_dtype(0, dtype::Float16())
  58. .set_dtype(1, dtype::Float16())
  59. .execs({arg.src, arg.dst});
  60. }
  61. }
  62. #endif
  63. TEST_F(ARM_COMMON, RESIZE_NCHW_FP32) {
  64. std::vector<TestArg> args;
  65. set_nchw_args(IMode::INTER_LINEAR, args);
  66. set_nchw_args(IMode::INTER_NEAREST, args);
  67. Checker<Resize> checker(handle());
  68. for (auto&& arg : args) {
  69. checker.set_param(arg.param)
  70. .set_dtype(0, dtype::Float32())
  71. .set_dtype(1, dtype::Float32())
  72. .execs({arg.src, arg.dst});
  73. }
  74. }
  75. TEST_F(ARM_COMMON, RESIZE_NCHW44_FP32) {
  76. std::vector<TestArg> args = get_nchw44_args();
  77. Checker<Resize> checker(handle());
  78. for (auto&& arg : args) {
  79. checker.set_param(arg.param)
  80. .set_dtype(0, dtype::Float32())
  81. .set_dtype(1, dtype::Float32())
  82. .execs({arg.src, arg.dst});
  83. }
  84. }
  85. #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  86. TEST_F(ARM_COMMON, RESIZE_NCHW88_FP16) {
  87. std::vector<TestArg> args = get_nchw88_args();
  88. Checker<Resize> checker(handle());
  89. for (auto&& arg : args) {
  90. checker.set_param(arg.param)
  91. .set_epsilon(0.01)
  92. .set_dtype(0, dtype::Float16())
  93. .set_dtype(1, dtype::Float16())
  94. .execs({arg.src, arg.dst});
  95. }
  96. }
  97. #endif
  98. } // namespace test
  99. } // namespace megdnn
  100. // vim: syntax=cpp.doxygen

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