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.

images2neibs.cpp 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * \file dnn/test/cuda/images2neibs.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 implied.
  10. */
  11. #include "test/cuda/fixture.h"
  12. #include "test/common/checker.h"
  13. #include "test/common/images2neibs.h"
  14. #include "test/common/rng.h"
  15. #include "test/cuda/benchmark.h"
  16. #include "test/cuda/utils.h"
  17. namespace megdnn {
  18. namespace test {
  19. TEST_F(CUDA, IMAGES2NEIBS_FORWARD) {
  20. auto args = images2neibs::get_args();
  21. for (auto&& arg : args) {
  22. Checker<Images2NeibsForward> checker(handle_cuda());
  23. checker.set_param(arg.param)
  24. .set_dtype(0, dtype::Float32())
  25. .exec(TensorShapeArray{arg.ishape, {}});
  26. checker.set_param(arg.param)
  27. .set_dtype(0, dtype::Float16())
  28. .exec(TensorShapeArray{arg.ishape, {}});
  29. }
  30. }
  31. #if MEGDNN_WITH_BENCHMARK
  32. TEST_F(CUDA, BENCHMARK_IMAGES2NEIBS_FORWARD) {
  33. auto args = images2neibs::get_benchmark_args();
  34. for (auto&& arg : args) {
  35. CUBenchmarker<Images2NeibsForward> bencher(handle_cuda());
  36. bencher.set_param(arg.param)
  37. .set_dtype(0, dtype::Float32())
  38. .exec(TensorShapeArray{arg.ishape, {}});
  39. }
  40. }
  41. #endif
  42. TEST_F(CUDA, IMAGES2NEIBS_BACKWARD) {
  43. require_compute_capability(6, 1);
  44. UniformFloatRNG rng(0, 1);
  45. auto args = images2neibs::get_args();
  46. for (auto&& arg : args) {
  47. Checker<Images2NeibsBackward> checker(handle_cuda());
  48. checker.set_epsilon(1e-2);
  49. checker.set_rng(0, &rng);
  50. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  51. TensorLayout olayout;
  52. {
  53. auto opr = handle_cuda()->create_operator<Images2Neibs>();
  54. opr->param() = arg.param;
  55. opr->deduce_layout(ilayout, olayout);
  56. }
  57. auto set_dtype = [&checker](DType dtype) {
  58. checker.set_dtype(0, dtype).set_dtype(1, dtype);
  59. };
  60. set_dtype(dtype::Float32());
  61. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  62. set_dtype(dtype::Float16());
  63. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  64. }
  65. }
  66. } // namespace test
  67. } // namespace megdnn
  68. // vim: syntax=cpp.doxygen