From a19acd20f07eee82622701a3015e6e9c073a5e0b Mon Sep 17 00:00:00 2001 From: Zhen Wang Date: Mon, 6 May 2019 12:59:10 +0800 Subject: [PATCH] change the output into inplace. test=develop --- paddle/fluid/operators/fake_quantize_op.cc | 16 +++++++++++++++- paddle/fluid/operators/fake_quantize_op.h | 5 ++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/fake_quantize_op.cc b/paddle/fluid/operators/fake_quantize_op.cc index 25ca1f7e0a0..beaa4392f20 100644 --- a/paddle/fluid/operators/fake_quantize_op.cc +++ b/paddle/fluid/operators/fake_quantize_op.cc @@ -458,6 +458,18 @@ $$Out = X$$ } }; +class MovingAverageAbsMaxScaleOpInplaceInToOut + : public framework::InplaceOpInference { + public: + std::unordered_map operator()( + const framework::OpDesc& op_desc) const override { + std::unordered_map inplace_in_to_out = { + {"X", "Out"}, + }; + return inplace_in_to_out; + } +}; + } // namespace operators } // namespace paddle @@ -482,6 +494,7 @@ REGISTER_OPERATOR(fake_quantize_moving_average_abs_max, paddle::framework::EmptyGradOpMaker); REGISTER_OP_CPU_KERNEL(fake_quantize_moving_average_abs_max, ops::FakeQuantizeMovingAverageAbsMaxKernel); + REGISTER_OPERATOR(fake_channel_wise_quantize_abs_max, ops::FakeChannelWiseQuantizeAbsMaxOp, ops::FakeChannelWiseQuantizeAbsMaxOpMaker, @@ -491,6 +504,7 @@ REGISTER_OP_CPU_KERNEL(fake_channel_wise_quantize_abs_max, REGISTER_OPERATOR(moving_average_abs_max_scale, ops::MovingAverageAbsMaxScaleOp, ops::MovingAverageAbsMaxScaleOpMaker, - paddle::framework::EmptyGradOpMaker); + paddle::framework::EmptyGradOpMaker, + ops::MovingAverageAbsMaxScaleOpInplaceInToOut); REGISTER_OP_CPU_KERNEL(moving_average_abs_max_scale, ops::MovingAverageAbsMaxScaleKernel); diff --git a/paddle/fluid/operators/fake_quantize_op.h b/paddle/fluid/operators/fake_quantize_op.h index 87bcece5824..b0fd4590951 100644 --- a/paddle/fluid/operators/fake_quantize_op.h +++ b/paddle/fluid/operators/fake_quantize_op.h @@ -15,9 +15,9 @@ limitations under the License. */ #pragma once #include +#include #include "paddle/fluid/framework/eigen.h" #include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/framework/tensor_util.h" #include "paddle/fluid/operators/math/blas.h" namespace paddle { @@ -204,9 +204,8 @@ class MovingAverageAbsMaxScaleKernel : public framework::OpKernel { void Compute(const framework::ExecutionContext& context) const override { auto* in = context.Input("X"); auto* out = context.Output("Out"); - out->mutable_data(context.GetPlace()); auto& dev_ctx = context.template device_context(); - framework::TensorCopy(*in, context.GetPlace(), dev_ctx, out); + out->ShareDataWith(*in); bool is_test = context.Attr("is_test"); // testing -- GitLab