未验证 提交 01b3ccae 编写于 作者: D dongfangshenzhu 提交者: GitHub

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
上级 2af286a6
......@@ -166,6 +166,24 @@ struct XPUReluGradFunctor : public BaseActivationFunctor<T> {
}
};
template <typename T>
struct XPURelu6Functor : public BaseActivationFunctor<T> {
using XPUType = typename XPUTypeTrait<T>::Type;
void operator()(const framework::ExecutionContext &ctx) const {
xpu_activation_forward<paddle::platform::XPUDeviceContext, T, XPUType>(
ctx, xpu::relu6<XPUType>);
}
};
template <typename T>
struct XPURelu6GradFunctor : public BaseActivationFunctor<T> {
using XPUType = typename XPUTypeTrait<T>::Type;
void operator()(const framework::ExecutionContext &ctx) const {
xpu_activation_backward<paddle::platform::XPUDeviceContext, T, XPUType>(
ctx, xpu::relu6_grad<XPUType>);
}
};
template <typename T>
struct XPUSigmoidFunctor : public BaseActivationFunctor<T> {
using XPUType = typename XPUTypeTrait<T>::Type;
......@@ -548,6 +566,10 @@ REGISTER_OP_XPU_KERNEL(
ops::XPUActivationGradKernel<ops::XPUReluGradFunctor<float>>,
ops::XPUActivationGradKernel<
ops::XPUReluGradFunctor<paddle::platform::float16>>);
REGISTER_OP_XPU_KERNEL(relu6,
ops::XPUActivationKernel<ops::XPURelu6Functor<float>>);
REGISTER_OP_XPU_KERNEL(
relu6_grad, ops::XPUActivationKernel<ops::XPURelu6GradFunctor<float>>);
REGISTER_OP_XPU_KERNEL(
tanh,
ops::XPUActivationKernel<ops::XPUTanhFunctor<float>>,
......
......@@ -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())})},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册