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.

sliding_window_transpose.cpp 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * \file dnn/test/cuda/sliding_window_transpose.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/rng.h"
  14. #include "test/common/sliding_window_transpose.h"
  15. #include "test/cuda/benchmark.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(CUDA, SLIDINGWINDOWTRANSPOSE_FORWARD) {
  19. UniformFloatRNG rng(0, 1);
  20. auto args = sliding_window_transpose::get_args();
  21. for (auto&& arg : args) {
  22. Checker<SlidingWindowTransposeForward> checker(handle_cuda());
  23. checker.set_rng(0, &rng);
  24. checker.set_epsilon(1e-2);
  25. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  26. TensorLayout olayout;
  27. {
  28. auto opr = handle_cuda()->create_operator<SlidingWindowTransposeForward>();
  29. opr->param() = arg.param;
  30. opr->deduce_layout(ilayout, olayout);
  31. }
  32. auto set_dtype = [&checker](DType dtype) {
  33. checker.set_dtype(0, dtype).set_dtype(1, dtype);
  34. };
  35. set_dtype(dtype::Float32());
  36. checker.set_param(arg.param).exec(TensorShapeArray{ilayout, olayout});
  37. set_dtype(dtype::Float16());
  38. checker.set_param(arg.param).exec(TensorShapeArray{ilayout, olayout});
  39. }
  40. }
  41. #if MEGDNN_WITH_BENCHMARK
  42. TEST_F(CUDA, BENCHMARK_SLIDINGWINDOWTRANSPOSE_FORWARD) {
  43. auto args = sliding_window_transpose::get_benchmark_args();
  44. for (auto&& arg : args) {
  45. CUBenchmarker<SlidingWindowTransposeForward> bencher(handle_cuda());
  46. bencher.set_param(arg.param)
  47. .set_dtype(0, dtype::Float32())
  48. .exec(TensorShapeArray{arg.ishape, {}});
  49. }
  50. }
  51. #endif
  52. TEST_F(CUDA, SLIDINGWINDOWTRANSPOSE_BACKWARD) {
  53. UniformFloatRNG rng(0, 1);
  54. auto args = sliding_window_transpose::get_args();
  55. for (auto&& arg : args) {
  56. Checker<SlidingWindowTransposeBackward> checker(handle_cuda());
  57. // checker.set_epsilon(1e-2);
  58. checker.set_rng(0, &rng);
  59. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  60. TensorLayout olayout;
  61. {
  62. auto opr = handle_cuda()->create_operator<SlidingWindowTranspose>();
  63. opr->param() = arg.param;
  64. opr->deduce_layout(ilayout, olayout);
  65. }
  66. auto set_dtype = [&checker](DType dtype) {
  67. checker.set_dtype(0, dtype).set_dtype(1, dtype);
  68. };
  69. set_dtype(dtype::Float32());
  70. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  71. set_dtype(dtype::Float16());
  72. checker.set_param(arg.param).exec(TensorShapeArray{olayout, ilayout});
  73. }
  74. }
  75. } // namespace test
  76. } // namespace megdnn
  77. // vim: syntax=cpp.doxygen