From 01b3ccaed6deb4f05b63c547ab756ab6e2b754d6 Mon Sep 17 00:00:00 2001 From: dongfangshenzhu <102794151+dongfangshenzhu@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:59:43 +0800 Subject: [PATCH] Zhusonghe (#44274) * add relu6 and relu6_grad * change code style of relu6 and relu6_grad * add relu6 and relu6_grad *test=kunlun * add relu6 and relu6_grad *test=kunlun --- paddle/fluid/operators/activation_op_xpu.cc | 22 +++++++++++++++++++ .../fluid/platform/device/xpu/xpu2_op_list.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/paddle/fluid/operators/activation_op_xpu.cc b/paddle/fluid/operators/activation_op_xpu.cc index 613eea90a6..0e7136b9f6 100644 --- a/paddle/fluid/operators/activation_op_xpu.cc +++ b/paddle/fluid/operators/activation_op_xpu.cc @@ -166,6 +166,24 @@ struct XPUReluGradFunctor : public BaseActivationFunctor { } }; +template +struct XPURelu6Functor : public BaseActivationFunctor { + using XPUType = typename XPUTypeTrait::Type; + void operator()(const framework::ExecutionContext &ctx) const { + xpu_activation_forward( + ctx, xpu::relu6); + } +}; + +template +struct XPURelu6GradFunctor : public BaseActivationFunctor { + using XPUType = typename XPUTypeTrait::Type; + void operator()(const framework::ExecutionContext &ctx) const { + xpu_activation_backward( + ctx, xpu::relu6_grad); + } +}; + template struct XPUSigmoidFunctor : public BaseActivationFunctor { using XPUType = typename XPUTypeTrait::Type; @@ -548,6 +566,10 @@ REGISTER_OP_XPU_KERNEL( ops::XPUActivationGradKernel>, ops::XPUActivationGradKernel< ops::XPUReluGradFunctor>); +REGISTER_OP_XPU_KERNEL(relu6, + ops::XPUActivationKernel>); +REGISTER_OP_XPU_KERNEL( + relu6_grad, ops::XPUActivationKernel>); REGISTER_OP_XPU_KERNEL( tanh, ops::XPUActivationKernel>, diff --git a/paddle/fluid/platform/device/xpu/xpu2_op_list.h b/paddle/fluid/platform/device/xpu/xpu2_op_list.h index 9f07f05ff7..e7570de695 100644 --- a/paddle/fluid/platform/device/xpu/xpu2_op_list.h +++ b/paddle/fluid/platform/device/xpu/xpu2_op_list.h @@ -349,6 +349,8 @@ XPUOpMap& get_kl2_ops() { {"reduce_sum_grad", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace())})}, {"reduce_sum", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace())})}, + {"relu6", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace())})}, + {"relu6_grad", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace())})}, {"relu_grad", XPUKernelSet({pOpKernelType(vartype::FP32, XPUPlace()), pOpKernelType(vartype::FP16, XPUPlace())})}, -- GitLab