diff --git a/paddle/fluid/operators/elementwise/elementwise_sub_op_xpu.cc b/paddle/fluid/operators/elementwise/elementwise_sub_op_xpu.cc deleted file mode 100644 index b586db4601fafac14dac576b0fd6a6f91723b3e3..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/elementwise/elementwise_sub_op_xpu.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ - -#ifdef PADDLE_WITH_XPU -#include "paddle/fluid/operators/elementwise/elementwise_op.h" -#include "paddle/fluid/operators/elementwise/elementwise_xpu.h" -#include "xpu/refactor/math.h" - -namespace paddle { -namespace operators { - -template -class ElementwiseSubXPUKernel : public framework::OpKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - XPUElementwise(ctx, xpu::broadcast_sub); - } -}; - -template -class ElementwiseSubGradXPUKernel : public ElemwiseGradKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - ElemwiseGradKernel::Compute(ctx); - XPUElementwiseGrad( - ctx, xpu::broadcast_sub_grad, false); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -REGISTER_OP_XPU_KERNEL(elementwise_sub, - ops::ElementwiseSubXPUKernel, - ops::ElementwiseSubXPUKernel); -REGISTER_OP_XPU_KERNEL( - elementwise_sub_grad, - ops::ElementwiseSubGradXPUKernel, - ops::ElementwiseSubGradXPUKernel); - -#endif diff --git a/paddle/phi/kernels/elementwise_kernel.cc b/paddle/phi/kernels/elementwise_kernel.cc index 95f7cc1070916ee01fd5d7b2b134347a6513148a..0c208d2db09d294be521f1c03d18a9974e2f115d 100644 --- a/paddle/phi/kernels/elementwise_kernel.cc +++ b/paddle/phi/kernels/elementwise_kernel.cc @@ -334,7 +334,12 @@ PD_REGISTER_KERNEL(multiply, phi::MultiplyKernel, phi::dtype::float16, float) {} - +PD_REGISTER_KERNEL(subtract, + XPU, + ALL_LAYOUT, + phi::SubtractKernel, + float, + phi::dtype::float16) {} #endif #if defined PADDLE_WITH_XPU diff --git a/paddle/phi/kernels/xpu/elementwise_subtract_grad_kernel.cc b/paddle/phi/kernels/xpu/elementwise_subtract_grad_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..0fb0ced46b8439753f9a9115412a1a7973159387 --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_subtract_grad_kernel.cc @@ -0,0 +1,49 @@ +/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "paddle/phi/kernels/elementwise_subtract_grad_kernel.h" +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/backends/xpu/xpu_header.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/xpu/elementwise.h" + +namespace phi { +template +void SubtractGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& dout, + int axis, + DenseTensor* dx, + DenseTensor* dy) { + using XPUType = typename XPUTypeTrait::Type; + phi::XPUElementwiseGrad(dev_ctx, + x, + y, + dout, + axis, + dx, + dy, + xpu::broadcast_sub_grad, + false); +} + +} // namespace phi + +PD_REGISTER_KERNEL(subtract_grad, + XPU, + ALL_LAYOUT, + phi::SubtractGradKernel, + phi::dtype::float16, + float) {} diff --git a/paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc b/paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..299b5f80d7dde74e84d622dbbcf771e44b199344 --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_subtract_kernel.cc @@ -0,0 +1,39 @@ +/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "paddle/phi/kernels/elementwise_subtract_kernel.h" +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/backends/xpu/xpu_header.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/xpu/elementwise.h" +namespace phi { + +template +void SubtractRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + int axis, + DenseTensor* out) { + using XPUType = typename XPUTypeTrait::Type; + phi::XPUElementwise( + dev_ctx, x, y, axis, out, xpu::broadcast_sub); +} + +} // namespace phi +PD_REGISTER_KERNEL(subtract_raw, + XPU, + ALL_LAYOUT, + phi::SubtractRawKernel, + float, + phi::dtype::float16) {}