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 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * \file dnn/src/common/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 "megdnn/oprs.h"
  12. #include "src/common/utils.h"
  13. namespace megdnn {
  14. void SlidingWindowTransposeBase::deduce_layout_fwd(
  15. const TensorLayout& src, TensorLayout& dst) {
  16. auto errmsg = [&]() {
  17. return megdnn_layout_msg(src) + ", " +
  18. "out_h=" + std::to_string(param().out_h) + ", " +
  19. "out_w=" + std::to_string(param().out_w) + ", " +
  20. "pad_h=" + std::to_string(param().pad_h) + ", " +
  21. "pad_w=" + std::to_string(param().pad_w) + ", " +
  22. "stride_h=" + std::to_string(param().stride_h) + ", " +
  23. "stride_w=" + std::to_string(param().stride_w) + ", " +
  24. "window_h=" + std::to_string(param().window_h) + ", " +
  25. "window_w=" + std::to_string(param().window_w);
  26. };
  27. MEGDNN_MARK_USED_VAR(errmsg);
  28. megdnn_assert_contiguous(src);
  29. megdnn_assert(src.ndim == 6_z, "%s", errmsg().c_str());
  30. size_t n = src[0], ic = src[1];
  31. size_t oh = this->param().out_h;
  32. size_t ow = this->param().out_w;
  33. dst = TensorLayout(TensorShape({n, ic, oh, ow}), src.dtype);
  34. }
  35. void SlidingWindowTransposeBase::check_layout_fwd(
  36. const TensorLayout& src, const TensorLayout& dst) {
  37. TensorLayout dst_expected;
  38. deduce_layout_fwd(src, dst_expected);
  39. megdnn_assert_eq_layout(dst_expected, dst);
  40. }
  41. void SlidingWindowTransposeForward::deduce_layout(
  42. const TensorLayout& src, TensorLayout& dst) {
  43. deduce_layout_fwd(src, dst);
  44. }
  45. void SlidingWindowTransposeForward::check_exec(
  46. const TensorLayout& src, const TensorLayout& dst, size_t workspace_in_bytes) {
  47. check_layout_fwd(src, dst);
  48. auto required_workspace_in_bytes = get_workspace_in_bytes(src, dst);
  49. megdnn_assert(workspace_in_bytes >= required_workspace_in_bytes);
  50. }
  51. void SlidingWindowTransposeBackward::check_exec(
  52. const TensorLayout& diff, const TensorLayout& grad, size_t workspace_in_bytes) {
  53. check_layout_fwd(grad, diff);
  54. auto required_workspace_in_bytes = get_workspace_in_bytes(grad, diff);
  55. megdnn_assert(workspace_in_bytes >= required_workspace_in_bytes);
  56. }
  57. } // namespace megdnn
  58. // vim: syntax=cpp.doxygen