diff --git a/paddle/fluid/operators/elementwise/elementwise_div_op_xpu.cc b/paddle/fluid/operators/elementwise/elementwise_div_op_xpu.cc deleted file mode 100644 index 147e6976f4fd714deb3f49ab2a3a2af49c7aabe0..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/elementwise/elementwise_div_op_xpu.cc +++ /dev/null @@ -1,53 +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_div_op.h" -#include "paddle/fluid/operators/elementwise/elementwise_op.h" -#include "paddle/fluid/operators/elementwise/elementwise_xpu.h" -namespace paddle { -namespace operators { - -template -class ElementwiseDivXPUKernel : public framework::OpKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - XPUElementwise(ctx, xpu::broadcast_div); - } -}; - -template -class ElementwiseDivGradXPUKernel : public ElemwiseGradKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - ElemwiseGradKernel::Compute(ctx); - XPUElementwiseGrad(ctx, xpu::broadcast_div_grad, true); - } -}; - -} // namespace operators -} // namespace paddle -namespace ops = paddle::operators; -REGISTER_OP_XPU_KERNEL(elementwise_div, - ops::ElementwiseDivXPUKernel, - ops::ElementwiseDivXPUKernel); -REGISTER_OP_XPU_KERNEL( - elementwise_div_grad, - ops::ElementwiseDivGradXPUKernel, - ops::ElementwiseDivGradXPUKernel); -#endif diff --git a/paddle/fluid/operators/elementwise/elementwise_mul_op_xpu.cc b/paddle/fluid/operators/elementwise/elementwise_mul_op_xpu.cc deleted file mode 100644 index 5e95eee3696391e9ed89e7523453bd27fb468f70..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/elementwise/elementwise_mul_op_xpu.cc +++ /dev/null @@ -1,55 +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_mul_op.h" -#include "paddle/fluid/operators/elementwise/elementwise_op.h" -#include "paddle/fluid/operators/elementwise/elementwise_xpu.h" -namespace paddle { -namespace operators { - -template -class ElementwiseMulXPUKernel : public framework::OpKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - XPUElementwise(ctx, xpu::broadcast_mul); - } -}; - -template -class ElementwiseMulGradXPUKernel : public ElemwiseGradKernel { - using XPUType = typename XPUTypeTrait::Type; - - public: - void Compute(const framework::ExecutionContext& ctx) const override { - ElemwiseGradKernel::Compute(ctx); - XPUElementwiseGrad(ctx, xpu::broadcast_mul_grad, true); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -REGISTER_OP_XPU_KERNEL(elementwise_mul, - ops::ElementwiseMulXPUKernel, - ops::ElementwiseMulXPUKernel); -REGISTER_OP_XPU_KERNEL( - elementwise_mul_grad, - ops::ElementwiseMulGradXPUKernel, - ops::ElementwiseMulGradXPUKernel); - -#endif diff --git a/paddle/phi/kernels/cpu/elementwise_add_kernel.cc b/paddle/phi/kernels/cpu/elementwise_add_kernel.cc index b5e28ab39e5a629cc2f3f97bf25569bf4aca38ce..33cd1fd12b4099ecbdbd3a305d54f3267447ccfc 100644 --- a/paddle/phi/kernels/cpu/elementwise_add_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_add_kernel.cc @@ -25,21 +25,12 @@ namespace phi { // Create the definition of Add DEFINE_CPU_ELEMENTWISE_OP(Add) -template -void AddKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - AddRawKernel(dev_ctx, x, y, axis, out); -} - template void GradAddKernel(const Context& dev_ctx, const DenseTensor& x, const DenseTensor& y, DenseTensor* out) { - AddKernel(dev_ctx, x, y, out); + AddRawKernel(dev_ctx, x, y, -1, out); } } // namespace phi @@ -62,18 +53,6 @@ PD_REGISTER_KERNEL(add_raw, complex64, complex128) {} -PD_REGISTER_KERNEL(add, - CPU, - ALL_LAYOUT, - phi::AddKernel, - float, - double, - int16_t, - int, - int64_t, - complex64, - complex128) {} - PD_REGISTER_KERNEL(grad_add, CPU, ALL_LAYOUT, diff --git a/paddle/phi/kernels/cpu/elementwise_divide_kernel.cc b/paddle/phi/kernels/cpu/elementwise_divide_kernel.cc index 15fe92c9291942f99b53e06ef57b9a0c0dbbc719..40d0e863ea50e92484e80e9f005f7cf2059caeeb 100644 --- a/paddle/phi/kernels/cpu/elementwise_divide_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_divide_kernel.cc @@ -46,15 +46,6 @@ void DivideRawKernel(const Context& dev_ctx, } } -template -void DivideKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - DivideRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi using complex64 = ::phi::dtype::complex; @@ -73,13 +64,3 @@ PD_REGISTER_KERNEL(divide_raw, int64_t, complex64, complex128) {} -PD_REGISTER_KERNEL(divide, - CPU, - ALL_LAYOUT, - phi::DivideKernel, - float, - double, - int, - int64_t, - complex64, - complex128) {} diff --git a/paddle/phi/kernels/cpu/elementwise_multiply_kernel.cc b/paddle/phi/kernels/cpu/elementwise_multiply_kernel.cc index 349150373844b974377d45626d714a9703bbff91..816a5173454bfb4335f7f002656d759ac3d3f0ce 100644 --- a/paddle/phi/kernels/cpu/elementwise_multiply_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_multiply_kernel.cc @@ -25,15 +25,6 @@ namespace phi { // Create the definition of Multiply DEFINE_CPU_ELEMENTWISE_OP(Multiply) -template -void MultiplyKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - MultiplyRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi using complex64 = ::phi::dtype::complex; @@ -54,16 +45,3 @@ PD_REGISTER_KERNEL(multiply_raw, complex64, complex128, phi::dtype::bfloat16) {} - -PD_REGISTER_KERNEL(multiply, - CPU, - ALL_LAYOUT, - phi::MultiplyKernel, - float, - double, - int, - int64_t, - bool, - complex64, - complex128, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc b/paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc index a013309233d47dc8d9ed40ba65b5397d832f8998..0c732659cb991ec780423af052e467aa7689e332 100644 --- a/paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_subtract_kernel.cc @@ -25,15 +25,6 @@ namespace phi { // Create the definition of Subtract DEFINE_CPU_ELEMENTWISE_OP(Subtract) -template -void SubtractKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - SubtractRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi using complex64 = ::phi::dtype::complex; @@ -54,15 +45,3 @@ PD_REGISTER_KERNEL(subtract_raw, complex64, complex128, phi::dtype::bfloat16) {} -PD_REGISTER_KERNEL(subtract, - CPU, - ALL_LAYOUT, - phi::SubtractKernel, - float, - double, - int16_t, - int, - int64_t, - complex64, - complex128, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/elementwise_kernel.cc b/paddle/phi/kernels/elementwise_kernel.cc index ebdb6299f352ff43ef0a940722e8599c4e56a308..6db4a036bac629fd8f5cba2566b4962fa6a64bd9 100644 --- a/paddle/phi/kernels/elementwise_kernel.cc +++ b/paddle/phi/kernels/elementwise_kernel.cc @@ -13,6 +13,10 @@ // limitations under the License. #include "paddle/phi/kernels/elementwise_kernel.h" +#include "paddle/phi/kernels/elementwise_add_kernel.h" +#include "paddle/phi/kernels/elementwise_divide_kernel.h" +#include "paddle/phi/kernels/elementwise_multiply_kernel.h" +#include "paddle/phi/kernels/elementwise_subtract_kernel.h" #include "paddle/phi/backends/all_context.h" #include "paddle/phi/core/kernel_registry.h" @@ -73,8 +77,40 @@ void ElementwiseHeavisideKernel(const Context& dev_ctx, ElementwiseHeavisideRawKernel(dev_ctx, x, y, axis, out); } -} // namespace phi +template +void DivideKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + DivideRawKernel(dev_ctx, x, y, -1, out); +} + +template +void MultiplyKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + MultiplyRawKernel(dev_ctx, x, y, -1, out); +} + +template +void AddKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + AddRawKernel(dev_ctx, x, y, -1, out); +} + +template +void SubtractKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + int axis = -1; + SubtractRawKernel(dev_ctx, x, y, axis, out); +} +} // namespace phi using complex64 = ::phi::dtype::complex; using complex128 = ::phi::dtype::complex; @@ -123,6 +159,55 @@ PD_REGISTER_KERNEL(elementwise_pow, int, int64_t) {} +PD_REGISTER_KERNEL(subtract, + CPU, + ALL_LAYOUT, + phi::SubtractKernel, + float, + double, + int16_t, + int, + int64_t, + complex64, + complex128, + phi::dtype::bfloat16) {} + +PD_REGISTER_KERNEL(add, + CPU, + ALL_LAYOUT, + phi::AddKernel, + float, + double, + int16_t, + int, + int64_t, + complex64, + complex128) {} + +PD_REGISTER_KERNEL(multiply, + CPU, + ALL_LAYOUT, + phi::MultiplyKernel, + float, + double, + int, + int64_t, + bool, + complex64, + complex128, + phi::dtype::bfloat16) {} + +PD_REGISTER_KERNEL(divide, + CPU, + ALL_LAYOUT, + phi::DivideKernel, + float, + double, + int, + int64_t, + complex64, + complex128) {} + #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) PD_REGISTER_KERNEL(maximum, @@ -171,4 +256,83 @@ PD_REGISTER_KERNEL(elementwise_pow, double, int, int64_t) {} + +#endif + +#if defined(PADDLE_WITH_XPU_KP) && !defined(PADDLE_WITH_XPU) +PD_REGISTER_KERNEL(subtract, KPS, ALL_LAYOUT, phi::SubtractKernel, float) {} +PD_REGISTER_KERNEL(add, KPS, ALL_LAYOUT, phi::AddKernel, float) {} +PD_REGISTER_KERNEL(multiply, KPS, ALL_LAYOUT, phi::MultiplyKernel, float) {} +PD_REGISTER_KERNEL(divide, KPS, ALL_LAYOUT, phi::DivideKernel, float) {} +#elif defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +PD_REGISTER_KERNEL(subtract, + KPS, + ALL_LAYOUT, + phi::SubtractKernel, + float, + double, + int16_t, + int, + int64_t, + phi::dtype::float16, + complex64, + complex128, + phi::dtype::bfloat16) {} + +PD_REGISTER_KERNEL(add, + KPS, + ALL_LAYOUT, + phi::AddKernel, + float, + double, + int16_t, + int, + int64_t, + phi::dtype::float16, + phi::dtype::bfloat16, + complex64, + complex128) {} + +PD_REGISTER_KERNEL(multiply, + KPS, + ALL_LAYOUT, + phi::MultiplyKernel, + float, + double, + int, + int64_t, + bool, + phi::dtype::float16, + phi::dtype::bfloat16, + complex64, + complex128) {} +PD_REGISTER_KERNEL(divide, + KPS, + ALL_LAYOUT, + phi::DivideKernel, + float, + double, + int, + int64_t, + phi::dtype::float16, + phi::dtype::bfloat16, + complex64, + complex128) {} +#endif + +#if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP) + +PD_REGISTER_KERNEL( + divide, XPU, ALL_LAYOUT, phi::DivideKernel, phi::dtype::float16, float) {} + +PD_REGISTER_KERNEL( + add, XPU, ALL_LAYOUT, phi::AddKernel, phi::dtype::float16, float) {} + +PD_REGISTER_KERNEL(multiply, + XPU, + ALL_LAYOUT, + phi::MultiplyKernel, + phi::dtype::float16, + float) {} + #endif diff --git a/paddle/phi/kernels/kps/elementwise_add_kernel.cu b/paddle/phi/kernels/kps/elementwise_add_kernel.cu index 98e39ada32b8be0fa0efd3f5f711f13881383167..64519a2e6599c466541436282ea7bd69cc3e8bbc 100644 --- a/paddle/phi/kernels/kps/elementwise_add_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_add_kernel.cu @@ -24,27 +24,17 @@ namespace phi { DEFINE_CUDA_ELEMENTWISE_OP(Add) -template -void AddKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - AddRawKernel(dev_ctx, x, y, axis, out); -} - template void GradAddKernel(const Context& dev_ctx, const DenseTensor& x, const DenseTensor& y, DenseTensor* out) { - AddKernel(dev_ctx, x, y, out); + AddRawKernel(dev_ctx, x, y, -1, out); } } // namespace phi #ifdef PADDLE_WITH_XPU_KP -PD_REGISTER_KERNEL(add, KPS, ALL_LAYOUT, phi::AddKernel, float) {} PD_REGISTER_KERNEL(add_raw, KPS, ALL_LAYOUT, phi::AddRawKernel, float) {} #else @@ -66,19 +56,6 @@ PD_REGISTER_KERNEL(add_raw, bfloat16, complex64, complex128) {} -PD_REGISTER_KERNEL(add, - KPS, - ALL_LAYOUT, - phi::AddKernel, - float, - double, - int16_t, - int, - int64_t, - phi::dtype::float16, - phi::dtype::bfloat16, - complex64, - complex128) {} PD_REGISTER_KERNEL(grad_add, KPS, diff --git a/paddle/phi/kernels/kps/elementwise_divide_kernel.cu b/paddle/phi/kernels/kps/elementwise_divide_kernel.cu index 827c478de9775c84da3254492ea582ee9698161a..e37b3919d5903ab1703cb9f328a075eec204e56d 100644 --- a/paddle/phi/kernels/kps/elementwise_divide_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_divide_kernel.cu @@ -25,19 +25,9 @@ namespace phi { // Create the definition of Divide DEFINE_CUDA_ELEMENTWISE_OP(Divide) -template -void DivideKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - DivideRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi #ifdef PADDLE_WITH_XPU_KP -PD_REGISTER_KERNEL(divide, KPS, ALL_LAYOUT, phi::DivideKernel, float) {} PD_REGISTER_KERNEL(divide_raw, KPS, ALL_LAYOUT, phi::DivideRawKernel, float) {} #else @@ -59,16 +49,4 @@ PD_REGISTER_KERNEL(divide_raw, complex64, complex128) {} -PD_REGISTER_KERNEL(divide, - KPS, - ALL_LAYOUT, - phi::DivideKernel, - float, - double, - int, - int64_t, - phi::dtype::float16, - phi::dtype::bfloat16, - complex64, - complex128) {} #endif diff --git a/paddle/phi/kernels/kps/elementwise_multiply_kernel.cu b/paddle/phi/kernels/kps/elementwise_multiply_kernel.cu index 99408ff214268606409bd1e9ded4a8d5224c59ab..11b02a62780587bd768650b583e51e20519fb419 100644 --- a/paddle/phi/kernels/kps/elementwise_multiply_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_multiply_kernel.cu @@ -25,19 +25,9 @@ namespace phi { // Create the definition of Multiply DEFINE_CUDA_ELEMENTWISE_OP(Multiply) -template -void MultiplyKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - MultiplyRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi #ifdef PADDLE_WITH_XPU_KP -PD_REGISTER_KERNEL(multiply, KPS, ALL_LAYOUT, phi::MultiplyKernel, float) {} PD_REGISTER_KERNEL( multiply_raw, KPS, ALL_LAYOUT, phi::MultiplyRawKernel, float) {} #else @@ -60,17 +50,5 @@ PD_REGISTER_KERNEL(multiply_raw, complex64, complex128, bfloat16) {} -PD_REGISTER_KERNEL(multiply, - KPS, - ALL_LAYOUT, - phi::MultiplyKernel, - float, - double, - int, - int64_t, - bool, - phi::dtype::float16, - phi::dtype::bfloat16, - complex64, - complex128) {} + #endif diff --git a/paddle/phi/kernels/kps/elementwise_subtract_kernel.cu b/paddle/phi/kernels/kps/elementwise_subtract_kernel.cu index b99f687b59f4e139bc40cf99745d07c47ecf6688..8f1f9e9dee8c9459bcb096856fd6b3dbcf68230b 100644 --- a/paddle/phi/kernels/kps/elementwise_subtract_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_subtract_kernel.cu @@ -25,19 +25,9 @@ namespace phi { // Create the definition of Subtract DEFINE_CUDA_ELEMENTWISE_OP(Subtract) -template -void SubtractKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - int axis = -1; - SubtractRawKernel(dev_ctx, x, y, axis, out); -} - } // namespace phi #ifdef PADDLE_WITH_XPU_KP -PD_REGISTER_KERNEL(subtract, KPS, ALL_LAYOUT, phi::SubtractKernel, float) {} PD_REGISTER_KERNEL( subtract_raw, KPS, ALL_LAYOUT, phi::SubtractRawKernel, float) {} #else @@ -60,17 +50,5 @@ PD_REGISTER_KERNEL(subtract_raw, bfloat16, complex64, complex128) {} -PD_REGISTER_KERNEL(subtract, - KPS, - ALL_LAYOUT, - phi::SubtractKernel, - float, - double, - int16_t, - int, - int64_t, - phi::dtype::float16, - complex64, - complex128, - phi::dtype::bfloat16) {} + #endif diff --git a/paddle/phi/kernels/xpu/elementwise.h b/paddle/phi/kernels/xpu/elementwise.h index b0aeff070ae2de4e1aa48d044937450c71df912c..7c0c2a3497b00f8bf5eddd5e92853e6f48745e9e 100644 --- a/paddle/phi/kernels/xpu/elementwise.h +++ b/paddle/phi/kernels/xpu/elementwise.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +/* 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. @@ -19,6 +19,7 @@ limitations under the License. */ #include #include +#include "paddle/phi/backends/xpu/enforce_xpu.h" #include "paddle/phi/backends/xpu/xpu_context.h" #include "paddle/phi/common/place.h" #include "paddle/phi/core/dense_tensor.h" @@ -88,13 +89,7 @@ void XPUElementwise(const XPUContext& dev_ctx, reinterpret_cast(z_data), x_dims_vec, y_dims_vec); - PADDLE_ENFORCE_EQ( - ret, - xpu::SUCCESS, - errors::External( - "XPU kernel Elementwise occur error in XPUElementwise error code ", - ret, - XPUAPIErrorMsg[ret])); + PADDLE_ENFORCE_XDNN_SUCCESS(ret, "elementwise"); } template @@ -177,13 +172,7 @@ void XPUElementwiseGrad(const XPUContext& dev_ctx, reinterpret_cast(dx_data), x_dims_vec, y_dims_vec); - PADDLE_ENFORCE_EQ( - ret, - xpu::SUCCESS, - errors::External( - "XPU kernel Elementwise occur error in XPUElementwise error code ", - ret, - XPUAPIErrorMsg[ret])); + PADDLE_ENFORCE_XDNN_SUCCESS(ret, "elementwise"); } } // namespace phi diff --git a/paddle/phi/kernels/xpu/elementwise_add_grad_kernel.cc b/paddle/phi/kernels/xpu/elementwise_add_grad_kernel.cc index 27fd9ed39f2c1fde1f911af14a055ffa6a78613c..829747932b3ecc0bf021a6203af35f736118340d 100644 --- a/paddle/phi/kernels/xpu/elementwise_add_grad_kernel.cc +++ b/paddle/phi/kernels/xpu/elementwise_add_grad_kernel.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "paddle/phi/kernels/elementwise_add_grad_kernel.h" + #include #include -#include "paddle/phi/kernels/elementwise_add_grad_kernel.h" - #include "paddle/phi/backends/xpu/enforce_xpu.h" #include "paddle/phi/backends/xpu/xpu_context.h" #include "paddle/phi/backends/xpu/xpu_header.h" diff --git a/paddle/phi/kernels/xpu/elementwise_add_kernel.cc b/paddle/phi/kernels/xpu/elementwise_add_kernel.cc index b91b99bc2064f7a7bf51e1df6b851d6013ccd6e1..1e838acaa8a88c4c53dc9882f1937acad603c6b3 100644 --- a/paddle/phi/kernels/xpu/elementwise_add_kernel.cc +++ b/paddle/phi/kernels/xpu/elementwise_add_kernel.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "paddle/phi/kernels/elementwise_add_kernel.h" + #include #include -#include "paddle/phi/kernels/elementwise_add_kernel.h" - #include "paddle/phi/api/ext/dispatch.h" #include "paddle/phi/backends/xpu/enforce_xpu.h" #include "paddle/phi/backends/xpu/xpu_context.h" @@ -58,14 +58,6 @@ void AddRawKernel(const Context& dev_ctx, dev_ctx, x, y, axis, out, xpu::broadcast_add); } -template -void AddKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - AddRawKernel(dev_ctx, x, y, -1, out); -} - } // namespace phi PD_REGISTER_KERNEL(grad_add, @@ -76,6 +68,3 @@ PD_REGISTER_KERNEL(grad_add, float) {} PD_REGISTER_KERNEL( add_raw, XPU, ALL_LAYOUT, phi::AddRawKernel, phi::dtype::float16, float) {} - -PD_REGISTER_KERNEL( - add, XPU, ALL_LAYOUT, phi::AddKernel, phi::dtype::float16, float) {} diff --git a/paddle/phi/kernels/xpu/elementwise_divide_grad_kernel.cc b/paddle/phi/kernels/xpu/elementwise_divide_grad_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..9251286e495a89b4426d04a064c5d5cf118a6681 --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_divide_grad_kernel.cc @@ -0,0 +1,56 @@ +// 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_divide_grad_kernel.h" + +#include +#include + +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/elementwise_base.h" +#include "paddle/phi/kernels/xpu/elementwise.h" + +namespace phi { + +template +void DivideGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& out, + const DenseTensor& dout, + int axis, + DenseTensor* dx, + DenseTensor* dy) { + using XPUType = typename XPUTypeTrait::Type; + funcs::ElementwiseGradPreProcess(dout, dx); + XPUElementwiseGrad(dev_ctx, + x, + y, + dout, + axis, + dx, + dy, + xpu::broadcast_div_grad, + true); +} + +} // namespace phi + +PD_REGISTER_KERNEL(divide_grad, + XPU, + ALL_LAYOUT, + phi::DivideGradKernel, + phi::dtype::float16, + float) {} diff --git a/paddle/phi/kernels/xpu/elementwise_divide_kernel.cc b/paddle/phi/kernels/xpu/elementwise_divide_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..ebefd05a02af4dd5933bf1c176c44ce86a88b6f5 --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_divide_kernel.cc @@ -0,0 +1,45 @@ +// 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_divide_kernel.h" + +#include +#include + +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/elementwise_base.h" +#include "paddle/phi/kernels/xpu/elementwise.h" + +namespace phi { + +template +void DivideRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + int axis, + DenseTensor* out) { + using XPUType = typename XPUTypeTrait::Type; + XPUElementwise( + dev_ctx, x, y, axis, out, xpu::broadcast_div); +} + +} // namespace phi + +PD_REGISTER_KERNEL(divide_raw, + XPU, + ALL_LAYOUT, + phi::DivideRawKernel, + phi::dtype::float16, + float) {} diff --git a/paddle/phi/kernels/xpu/elementwise_multiply_grad_kernel.cc b/paddle/phi/kernels/xpu/elementwise_multiply_grad_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..b111630506f8388c370e46a9cc11da964a11a4b4 --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_multiply_grad_kernel.cc @@ -0,0 +1,55 @@ +// 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_multiply_grad_kernel.h" + +#include +#include + +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/elementwise_base.h" +#include "paddle/phi/kernels/xpu/elementwise.h" + +namespace phi { + +template +void MultiplyGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& dout, + int axis, + DenseTensor* dx, + DenseTensor* dy) { + using XPUType = typename XPUTypeTrait::Type; + funcs::ElementwiseGradPreProcess(dout, dx); + XPUElementwiseGrad(dev_ctx, + x, + y, + dout, + axis, + dx, + dy, + xpu::broadcast_mul_grad, + true); +} + +} // namespace phi + +PD_REGISTER_KERNEL(multiply_grad, + XPU, + ALL_LAYOUT, + phi::MultiplyGradKernel, + phi::dtype::float16, + float) {} diff --git a/paddle/phi/kernels/xpu/elementwise_multiply_kernel.cc b/paddle/phi/kernels/xpu/elementwise_multiply_kernel.cc new file mode 100644 index 0000000000000000000000000000000000000000..811e09bf333349ae2cdc36c489496ac7c27c2f8d --- /dev/null +++ b/paddle/phi/kernels/xpu/elementwise_multiply_kernel.cc @@ -0,0 +1,45 @@ +// 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_multiply_kernel.h" + +#include +#include + +#include "paddle/phi/backends/xpu/xpu_context.h" +#include "paddle/phi/core/kernel_registry.h" +#include "paddle/phi/kernels/funcs/elementwise_base.h" +#include "paddle/phi/kernels/xpu/elementwise.h" + +namespace phi { + +template +void MultiplyRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + int axis, + DenseTensor* out) { + using XPUType = typename XPUTypeTrait::Type; + XPUElementwise( + dev_ctx, x, y, axis, out, xpu::broadcast_mul); +} + +} // namespace phi + +PD_REGISTER_KERNEL(multiply_raw, + XPU, + ALL_LAYOUT, + phi::MultiplyRawKernel, + phi::dtype::float16, + float) {}