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.

tqt.cpp 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * \file dnn/src/common/tqt.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
  10. * implied.
  11. */
  12. #include "megdnn/oprs.h"
  13. #include "src/common/utils.h"
  14. namespace megdnn {
  15. void TQTBase::deduce_layout_fwd(const TensorLayout& input, TensorLayout& output) {
  16. output = TensorLayout(input, input.dtype);
  17. }
  18. void TQTBase::check_layout_fwd(
  19. const TensorLayout& input, const TensorLayout& scale,
  20. const TensorLayout& output) {
  21. megdnn_assert(input.dtype == dtype::Float32());
  22. megdnn_assert(scale.dtype == dtype::Float32());
  23. TensorLayout expected;
  24. deduce_layout_fwd(input, expected);
  25. megdnn_assert_eq_layout(expected, output);
  26. }
  27. void TQTForward::deduce_layout(
  28. const TensorLayout& input, const TensorLayout& /* scale */,
  29. TensorLayout& output) {
  30. deduce_layout_fwd(input, output);
  31. }
  32. void TQTForward::check_exec(
  33. const TensorLayout& input, const TensorLayout& scale,
  34. const TensorLayout& output, size_t workspace_in_bytes) {
  35. check_layout_fwd(input, scale, output);
  36. auto required_workspace_space = get_workspace_in_bytes(input, scale, output);
  37. megdnn_assert(workspace_in_bytes >= required_workspace_space);
  38. }
  39. void TQTBackward::check_exec(
  40. const TensorLayout& diff, const TensorLayout& input, const TensorLayout& scale,
  41. const TensorLayout& grad_x, const TensorLayout& grad_s,
  42. size_t workspace_in_bytes) {
  43. megdnn_assert_eq_shape(diff, input);
  44. megdnn_assert_eq_shape(grad_x, input);
  45. auto required_worspace_space =
  46. get_workspace_in_bytes(diff, input, scale, grad_x, grad_s);
  47. megdnn_assert(workspace_in_bytes >= required_worspace_space);
  48. }
  49. } // namespace megdnn