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. TEST_F(CUDA, SLIDINGWINDOWTRANSPOSE_BACKWARD) {
  42. UniformFloatRNG rng(0, 1);
  43. auto args = sliding_window_transpose::get_args();
  44. for (auto&& arg : args) {
  45. Checker<SlidingWindowTransposeBackward> 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<SlidingWindowTranspose>();
  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. #if MEGDNN_WITH_BENCHMARK
  65. TEST_F(CUDA, BENCHMARK_SLIDINGWINDOWTRANSPOSE_FORWARD) {
  66. auto args = sliding_window_transpose::get_benchmark_args();
  67. for (auto&& arg : args) {
  68. CUBenchmarker<SlidingWindowTransposeForward> bencher(handle_cuda());
  69. bencher.set_param(arg.param)
  70. .set_dtype(0, dtype::Float32())
  71. .exec(TensorShapeArray{arg.ishape, {}});
  72. }
  73. }
  74. #endif
  75. } // namespace test
  76. } // namespace megdnn
  77. // vim: syntax=cpp.doxygen