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

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * \file src/opr/impl/dnn/fake_quant.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 "megbrain/opr/dnn/fake_quant.h"
  13. #include "../internal/megdnn_opr_wrapper.inl"
  14. #include "megbrain/graph/grad_impl.h"
  15. #include "megbrain/opr/internal/out_shape_by_sym_var.h"
  16. #include "megbrain/opr/utility.h"
  17. using namespace mgb;
  18. using namespace opr;
  19. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FakeQuantForward);
  20. MEGDNN_OPR_INIT3(FakeQuantForward, "fakequant_fwd");
  21. #ifdef MGB_ENABLE_GRAD
  22. MGB_IMPL_OPR_GRAD(FakeQuantForward) {
  23. if (wrt_idx == 0) {
  24. // wrt src
  25. SymbolVar grad = FakeQuantBackward::make(
  26. out_grad[0], opr.input(0), opr.input(1), opr.input(2), opr.param());
  27. return grad.node();
  28. } else {
  29. return nullptr;
  30. }
  31. }
  32. #endif
  33. MGB_DYN_TYPE_OBJ_FINAL_IMPL(FakeQuantBackward);
  34. MEGDNN_OPR_INIT4(FakeQuantBackward, "fakequant_bwd", 1, true);