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.

transpose.cpp 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * \file dnn/src/common/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 TransposeForward::deduce_layout(const TensorLayout& src, TensorLayout& dst) {
  15. dst = src;
  16. dst.dtype = src.dtype;
  17. std::swap(dst.shape[0], dst.shape[1]);
  18. dst.init_contiguous_stride();
  19. }
  20. void TransposeForward::check_exec(
  21. const TensorLayout& src, const TensorLayout& dst, size_t workspace_in_bytes) {
  22. // dtype must collide
  23. megdnn_assert(src.dtype == dst.dtype);
  24. // ndim must be 2
  25. megdnn_assert(src.ndim == 2);
  26. megdnn_assert(dst.ndim == 2);
  27. // shapes are swapped
  28. megdnn_assert(src.shape[0] == dst.shape[1]);
  29. megdnn_assert(src.shape[1] == dst.shape[0]);
  30. // last dimension stride must be 1
  31. megdnn_assert(src.stride[1] == 1);
  32. megdnn_assert(dst.stride[1] == 1);
  33. // leading dimension stride must be geq last dimension shape
  34. megdnn_assert(src.stride[0] > 0);
  35. megdnn_assert(dst.stride[0] > 0);
  36. megdnn_assert(static_cast<size_t>(src.stride[0]) >= src.shape[1]);
  37. megdnn_assert(static_cast<size_t>(dst.stride[0]) >= dst.shape[1]);
  38. auto required_workspace_in_bytes = get_workspace_in_bytes(src, dst);
  39. megdnn_assert(workspace_in_bytes >= required_workspace_in_bytes);
  40. }
  41. } // namespace megdnn
  42. // vim: syntax=cpp.doxygen