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.

fake_quant.cpp 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * \file dnn/src/common/fakequant.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 FakeQuantBase::deduce_layout_fwd(const TensorLayout& input, TensorLayout& output) {
  16. output = TensorLayout(input);
  17. }
  18. void FakeQuantBase::check_layout_fwd(
  19. const TensorLayout& input, const TensorLayout& scale,
  20. const TensorLayout& zero_point, const TensorLayout& output) {
  21. megdnn_assert(input.dtype == dtype::Float32());
  22. megdnn_assert(scale.dtype == dtype::Float32());
  23. megdnn_assert(zero_point.dtype == dtype::Float32());
  24. TensorLayout expected;
  25. deduce_layout_fwd(input, expected);
  26. megdnn_assert_eq_layout(expected, output);
  27. }
  28. void FakeQuantForward::deduce_layout(
  29. const TensorLayout& input, const TensorLayout& /*scale*/,
  30. const TensorLayout& /*zero_point*/, TensorLayout& output) {
  31. deduce_layout_fwd(input, output);
  32. }
  33. void FakeQuantForward::check_exec(
  34. const TensorLayout& input, const TensorLayout& scale,
  35. const TensorLayout& zero_point, const TensorLayout& output,
  36. size_t workspace_in_bytes) {
  37. check_layout_fwd(input, scale, zero_point, output);
  38. auto required_workspace_space =
  39. get_workspace_in_bytes(input, scale, zero_point, output);
  40. megdnn_assert(workspace_in_bytes >= required_workspace_space);
  41. }
  42. void FakeQuantBackward::check_exec(
  43. const TensorLayout& diff, const TensorLayout& input, const TensorLayout& scale,
  44. const TensorLayout& zero_point, const TensorLayout& grad,
  45. size_t workspace_in_bytes) {
  46. megdnn_assert_eq_shape(input, diff);
  47. megdnn_assert_eq_shape(input, grad);
  48. auto required_worspace_space =
  49. get_workspace_in_bytes(diff, input, scale, zero_point, grad);
  50. megdnn_assert(workspace_in_bytes >= required_worspace_space);
  51. }
  52. } // namespace megdnn