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

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