diff --git a/paddle/phi/kernels/copysign_grad_kernel.h b/paddle/phi/kernels/copysign_grad_kernel.h deleted file mode 100755 index c6f9ecefa930a..0000000000000 --- a/paddle/phi/kernels/copysign_grad_kernel.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2023 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. - -#pragma once - -#include "paddle/phi/core/dense_tensor.h" - -namespace phi { - -using float16 = phi::dtype::float16; -using bfloat16 = phi::dtype::bfloat16; - -template -inline HOSTDEVICE auto copysign_func(const T& a, const T& b) { -#ifdef WIN32 - using U = typename std::conditional_t::value, float, T>; - return static_cast(std::copysign(static_cast(a), static_cast(b))); -#else - return static_cast(std::copysign(a, b)); -#endif -} - -inline HOSTDEVICE phi::dtype::float16 copysign_func(phi::dtype::float16 a, - phi::dtype::float16 b) { - return phi::dtype::raw_uint16_to_float16((a.x & 0x7fff) | (b.x & 0x8000)); -} - -inline HOSTDEVICE phi::dtype::bfloat16 copysign_func(phi::dtype::bfloat16 a, - phi::dtype::bfloat16 b) { - return phi::dtype::raw_uint16_to_bfloat16((a.x & 0x7fff) | (b.x & 0x8000)); -} - -template -void CopySignGradKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& out_grad, - DenseTensor* x_grad, - DenseTensor* y_grad); -} // namespace phi diff --git a/paddle/phi/kernels/copysign_kernel.h b/paddle/phi/kernels/copysign_kernel.h deleted file mode 100644 index cdbc14da673a7..0000000000000 --- a/paddle/phi/kernels/copysign_kernel.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2023 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. - -#pragma once - -#include "paddle/phi/core/dense_tensor.h" -namespace phi { - -using float16 = phi::dtype::float16; -using bfloat16 = phi::dtype::bfloat16; - -template -inline HOSTDEVICE auto copysign_func(const T& a, const T& b) { -#ifdef WIN32 - using U = typename std::conditional_t::value, float, T>; - return static_cast(std::copysign(static_cast(a), static_cast(b))); -#else - return static_cast(std::copysign(a, b)); -#endif -} - -inline HOSTDEVICE phi::dtype::float16 copysign_func(phi::dtype::float16 a, - phi::dtype::float16 b) { - return phi::dtype::raw_uint16_to_float16((a.x & 0x7fff) | (b.x & 0x8000)); -} - -inline HOSTDEVICE phi::dtype::bfloat16 copysign_func(phi::dtype::bfloat16 a, - phi::dtype::bfloat16 b) { - return phi::dtype::raw_uint16_to_bfloat16((a.x & 0x7fff) | (b.x & 0x8000)); -} - -template -struct CopySignFunctor { - inline HOSTDEVICE T operator()(const T a, const T b) const { - return copysign_func(a, b); - } -}; -template -struct InverseCopySignFunctor { - inline HOSTDEVICE T operator()(const T a, const T b) const { - return copysign_func(b, a); - } -}; - -template -void CopySignKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out); -} // namespace phi diff --git a/paddle/phi/kernels/cpu/copysign_grad_kernel.cc b/paddle/phi/kernels/cpu/copysign_grad_kernel.cc deleted file mode 100644 index 2809b65ef5599..0000000000000 --- a/paddle/phi/kernels/cpu/copysign_grad_kernel.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2023 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/copysign_grad_kernel.h" -#include "paddle/phi/backends/cpu/cpu_context.h" -#include "paddle/phi/core/kernel_registry.h" -#include "paddle/phi/kernels/cpu/elementwise_grad.h" -#include "paddle/phi/kernels/funcs/elementwise_base.h" -#include "paddle/phi/kernels/funcs/elementwise_functor.h" - -namespace phi { - -template -HOSTDEVICE T compute_copysign_grad_dx(T x, T y, T out, T dout) { - if (x == static_cast(0)) - return x; - else - return static_cast(dout * (phi::copysign_func(x, y) / x)); -} - -template -struct CopySignGradDX { - HOSTDEVICE T operator()(T x, T y, T out, T dout) const { - return compute_copysign_grad_dx(x, y, out, dout); - } -}; - -template -struct CopySignGradDY { - HOSTDEVICE T operator()(T x, T y, T out, T dout) const { - return static_cast(0); - } -}; - -template -void CopySignGradKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& out_grad, - DenseTensor* x_grad, - DenseTensor* y_grad) { - funcs::ElementwiseGradPreProcess(out_grad, x_grad); - int axis = -1; - phi::funcs:: - ElemwiseGradCompute, CopySignGradDY>( - dev_ctx, - x, - y, - out_grad, - out_grad, - axis, - x_grad, - y_grad, - CopySignGradDX(), - CopySignGradDY()); -} -} // namespace phi - -PD_REGISTER_KERNEL(copysign_grad, - CPU, - ALL_LAYOUT, - phi::CopySignGradKernel, - bool, - uint8_t, - int8_t, - int16_t, - int, - int64_t, - float, - double, - phi::dtype::float16, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/cpu/copysign_kernel.cc b/paddle/phi/kernels/cpu/copysign_kernel.cc deleted file mode 100644 index 1fa62cf65ed5a..0000000000000 --- a/paddle/phi/kernels/cpu/copysign_kernel.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2023 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/copysign_kernel.h" -#include "paddle/phi/backends/cpu/cpu_context.h" -#include "paddle/phi/core/kernel_registry.h" -#include "paddle/phi/kernels/funcs/broadcast_function.h" -#include "paddle/phi/kernels/funcs/elementwise_base.h" -namespace phi { -template -void CopySignKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - dev_ctx.template Alloc(out); - auto x_dims = x.dims(); - auto y_dims = y.dims(); - if (x_dims.size() >= y_dims.size()) { - funcs::ElementwiseCompute, T>( - dev_ctx, x, y, phi::CopySignFunctor(), out); - } else { - funcs::ElementwiseCompute, T>( - dev_ctx, x, y, phi::InverseCopySignFunctor(), out); - } -} -} // namespace phi - -PD_REGISTER_KERNEL(copysign, - CPU, - ALL_LAYOUT, - phi::CopySignKernel, - bool, - uint8_t, - int8_t, - int16_t, - int, - int64_t, - float, - double, - phi::dtype::float16, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/cpu/elementwise_grad_kernel.cc b/paddle/phi/kernels/cpu/elementwise_grad_kernel.cc index dfcea53207c22..2572559637553 100644 --- a/paddle/phi/kernels/cpu/elementwise_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_grad_kernel.cc @@ -49,6 +49,28 @@ void MinimumGradKernel(const Context& dev_ctx, dev_ctx, x, y, dout, dout, axis, dx, dy, MinGradDx(), MinGradDy()); } +template +void CopySignGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& out_grad, + DenseTensor* x_grad, + DenseTensor* y_grad) { + funcs::ElementwiseGradPreProcess(out_grad, x_grad); + int axis = -1; + phi::funcs:: + ElemwiseGradCompute, CopySignGradDY>( + dev_ctx, + x, + y, + out_grad, + out_grad, + axis, + x_grad, + y_grad, + CopySignGradDX(), + CopySignGradDY()); +} } // namespace phi PD_REGISTER_KERNEL(fmax_grad, @@ -107,3 +129,18 @@ PD_REGISTER_KERNEL(elementwise_pow_grad, int, int64_t, phi::dtype::bfloat16) {} + +PD_REGISTER_KERNEL(copysign_grad, + CPU, + ALL_LAYOUT, + phi::CopySignGradKernel, + bool, + uint8_t, + int8_t, + int16_t, + int, + int64_t, + float, + double, + phi::dtype::float16, + phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/cpu/elementwise_kernel.cc b/paddle/phi/kernels/cpu/elementwise_kernel.cc index 418236f413041..493ab84422a35 100644 --- a/paddle/phi/kernels/cpu/elementwise_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_kernel.cc @@ -78,6 +78,23 @@ void HeavisideKernel(const Context& dev_ctx, dev_ctx, x, y, funcs::ElementwiseHeavisideFunctor(), out); } +template +void CopySignKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + dev_ctx.template Alloc(out); + auto x_dims = x.dims(); + auto y_dims = y.dims(); + if (x_dims.size() >= y_dims.size()) { + funcs::ElementwiseCompute, T>( + dev_ctx, x, y, funcs::CopySignFunctor(), out); + } else { + funcs::ElementwiseCompute, T>( + dev_ctx, x, y, funcs::InverseCopySignFunctor(), out); + } +} + } // namespace phi using complex64 = ::phi::dtype::complex; @@ -148,3 +165,18 @@ PD_REGISTER_KERNEL(heaviside, double, int, int64_t) {} + +PD_REGISTER_KERNEL(copysign, + CPU, + ALL_LAYOUT, + phi::CopySignKernel, + bool, + uint8_t, + int8_t, + int16_t, + int, + int64_t, + float, + double, + phi::dtype::float16, + phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/elementwise_grad_kernel.h b/paddle/phi/kernels/elementwise_grad_kernel.h index 32137e600d1fa..0ca934cc8f35b 100644 --- a/paddle/phi/kernels/elementwise_grad_kernel.h +++ b/paddle/phi/kernels/elementwise_grad_kernel.h @@ -66,4 +66,13 @@ void ElementwisePowGradKernel(const Context& dev_ctx, const DenseTensor& dout, DenseTensor* dx, DenseTensor* dy); + +template +void CopySignGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& out_grad, + DenseTensor* x_grad, + DenseTensor* y_grad); + } // namespace phi diff --git a/paddle/phi/kernels/elementwise_kernel.h b/paddle/phi/kernels/elementwise_kernel.h index 5c01639dd7cc2..b8956803bdb6f 100644 --- a/paddle/phi/kernels/elementwise_kernel.h +++ b/paddle/phi/kernels/elementwise_kernel.h @@ -67,6 +67,12 @@ void HeavisideKernel(const Context& dev_ctx, const DenseTensor& y, DenseTensor* out); +template +void CopySignKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out); + template DenseTensor Maximum(const Context& dev_ctx, const DenseTensor& x, diff --git a/paddle/phi/kernels/funcs/elementwise_functor.h b/paddle/phi/kernels/funcs/elementwise_functor.h index 5477b952d08b3..82ed5bbd0da3b 100644 --- a/paddle/phi/kernels/funcs/elementwise_functor.h +++ b/paddle/phi/kernels/funcs/elementwise_functor.h @@ -895,5 +895,71 @@ struct ElementwiseInversePowFunctor { } }; +// copysign forward and grad functors +template +inline HOSTDEVICE auto copysign_func(const T& a, const T& b) { +#ifdef WIN32 + using U = typename std::conditional_t::value, float, T>; + return static_cast(std::copysign(static_cast(a), static_cast(b))); +#else + return static_cast(std::copysign(a, b)); +#endif +} + +inline HOSTDEVICE phi::dtype::float16 copysign_func(phi::dtype::float16 a, + phi::dtype::float16 b) { + return phi::dtype::raw_uint16_to_float16((a.x & 0x7fff) | (b.x & 0x8000)); +} + +inline HOSTDEVICE phi::dtype::bfloat16 copysign_func(phi::dtype::bfloat16 a, + phi::dtype::bfloat16 b) { + return phi::dtype::raw_uint16_to_bfloat16((a.x & 0x7fff) | (b.x & 0x8000)); +} + +template +struct CopySignGradXFunctor { + inline HOSTDEVICE T operator()(const T x, const T y, const T dout) const { + if (x == static_cast(0)) return x; + return dout * (funcs::copysign_func(x, y) / x); + } +}; + +template +struct CopySignGradYFunctor { + inline HOSTDEVICE T operator()(const T x, const T y, const T dout) const { + return static_cast(0); + } +}; + +template +struct CopySignGradXYFunctor { + inline HOSTDEVICE phi::Array operator()(const InT x, + const InT y, + const InT dout) { + phi::Array outs; + // dx + if (x == static_cast(0)) + outs[0] = static_cast(0); + else + outs[0] = static_cast(dout * (funcs::copysign_func(x, y)) / x); + // dy = 0 + outs[1] = static_cast(0); + return outs; + } +}; + +template +struct CopySignFunctor { + inline HOSTDEVICE T operator()(const T a, const T b) const { + return copysign_func(a, b); + } +}; +template +struct InverseCopySignFunctor { + inline HOSTDEVICE T operator()(const T a, const T b) const { + return copysign_func(b, a); + } +}; + } // namespace funcs } // namespace phi diff --git a/paddle/phi/kernels/gpu/copysign_grad_kernel.cu b/paddle/phi/kernels/gpu/copysign_grad_kernel.cu deleted file mode 100644 index 7aa5f21eb124d..0000000000000 --- a/paddle/phi/kernels/gpu/copysign_grad_kernel.cu +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2023 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/copysign_grad_kernel.h" -#include "paddle/phi/backends/gpu/gpu_context.h" -#include "paddle/phi/core/kernel_registry.h" -#include "paddle/phi/kernels/funcs/elementwise_base.h" -#include "paddle/phi/kernels/funcs/elementwise_functor.h" -#include "paddle/phi/kernels/gpu/elementwise_grad.h" - -namespace phi { - -template -struct CopySignGradXFunctor { - inline HOSTDEVICE T operator()(const T x, const T y, const T dout) const { - if (x == static_cast(0)) return x; - return dout * (phi::copysign_func(x, y) / x); - } -}; - -template -struct CopySignGradYFunctor { - inline HOSTDEVICE T operator()(const T x, const T y, const T dout) const { - return static_cast(0); - } -}; - -template -struct CopySignGradXYFunctor { - inline HOSTDEVICE phi::Array operator()(const InT x, - const InT y, - const InT dout) { - phi::Array outs; - // dx - if (x == static_cast(0)) - outs[0] = static_cast(0); - else - outs[0] = static_cast(dout * (phi::copysign_func(x, y)) / x); - // dy = 0 - outs[1] = static_cast(0); - return outs; - } -}; - -template -void CopySignGradKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - const DenseTensor& out_grad, - DenseTensor* x_grad, - DenseTensor* y_grad) { - const auto place = dev_ctx.GetPlace(); - int axis = -1; - if (x_grad != nullptr && y_grad != nullptr) { - std::vector ins = {&x, &y, &out_grad}; - GetGradXAndYOut(dev_ctx, - place, - axis, - ins, - out_grad, - x_grad, - y_grad, - CopySignGradXYFunctor()); - } else if (x_grad != nullptr && y_grad == nullptr) { - std::vector ins = {&x, &y, &out_grad}; - GetGradXOrYOut( - dev_ctx, place, axis, ins, out_grad, x_grad, CopySignGradXFunctor()); - } else if (y_grad != nullptr && x_grad == nullptr) { - std::vector ins = {&x, &y, &out_grad}; - GetGradXOrYOut( - dev_ctx, place, axis, ins, out_grad, y_grad, CopySignGradYFunctor()); - } -} -} // namespace phi - -PD_REGISTER_KERNEL(copysign_grad, - GPU, - ALL_LAYOUT, - phi::CopySignGradKernel, - bool, - uint8_t, - int8_t, - int16_t, - int, - int64_t, - float, - double, - phi::dtype::float16, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/gpu/copysign_kernel.cu b/paddle/phi/kernels/gpu/copysign_kernel.cu deleted file mode 100644 index 977223b347ca7..0000000000000 --- a/paddle/phi/kernels/gpu/copysign_kernel.cu +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2023 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/copysign_kernel.h" -#include "paddle/phi/backends/gpu/gpu_context.h" -#include "paddle/phi/core/kernel_registry.h" -#include "paddle/phi/kernels/funcs/broadcast_function.h" -#include "paddle/phi/kernels/funcs/elementwise_base.h" -namespace phi { -template -void CopySignKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { - std::vector inputs = {&x, &y}; - std::vector outputs = {out}; - dev_ctx.template Alloc(out); - funcs::BroadcastKernel( - dev_ctx, inputs, &outputs, phi::CopySignFunctor()); -} -} // namespace phi - -PD_REGISTER_KERNEL(copysign, - GPU, - ALL_LAYOUT, - phi::CopySignKernel, - bool, - uint8_t, - int8_t, - int16_t, - int, - int64_t, - float, - double, - phi::dtype::float16, - phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/gpu/elementwise_grad_kernel.cu b/paddle/phi/kernels/gpu/elementwise_grad_kernel.cu index 3261243c986c0..ddb3d3233a029 100644 --- a/paddle/phi/kernels/gpu/elementwise_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/elementwise_grad_kernel.cu @@ -209,6 +209,46 @@ void MinimumGradKernel(const Context& dev_ctx, dev_ctx, place, axis, ins, dout, dy, funcs::MinGradYFunctor()); } } + +template +void CopySignGradKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + const DenseTensor& out_grad, + DenseTensor* x_grad, + DenseTensor* y_grad) { + const auto place = dev_ctx.GetPlace(); + int axis = -1; + if (x_grad != nullptr && y_grad != nullptr) { + std::vector ins = {&x, &y, &out_grad}; + GetGradXAndYOut(dev_ctx, + place, + axis, + ins, + out_grad, + x_grad, + y_grad, + funcs::CopySignGradXYFunctor()); + } else if (x_grad != nullptr && y_grad == nullptr) { + std::vector ins = {&x, &y, &out_grad}; + GetGradXOrYOut(dev_ctx, + place, + axis, + ins, + out_grad, + x_grad, + funcs::CopySignGradXFunctor()); + } else if (y_grad != nullptr && x_grad == nullptr) { + std::vector ins = {&x, &y, &out_grad}; + GetGradXOrYOut(dev_ctx, + place, + axis, + ins, + out_grad, + y_grad, + funcs::CopySignGradYFunctor()); + } +} } // namespace phi PD_REGISTER_KERNEL(fmax_grad, @@ -414,3 +454,18 @@ PD_REGISTER_KERNEL(subtract_double_grad, phi::dtype::bfloat16, phi::dtype::complex, phi::dtype::complex) {} + +PD_REGISTER_KERNEL(copysign_grad, + GPU, + ALL_LAYOUT, + phi::CopySignGradKernel, + bool, + uint8_t, + int8_t, + int16_t, + int, + int64_t, + float, + double, + phi::dtype::float16, + phi::dtype::bfloat16) {} diff --git a/paddle/phi/kernels/impl/elementwise_grad_kernel_impl.h b/paddle/phi/kernels/impl/elementwise_grad_kernel_impl.h index 280c38633b462..db6858bc9d7d7 100644 --- a/paddle/phi/kernels/impl/elementwise_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/elementwise_grad_kernel_impl.h @@ -978,4 +978,31 @@ void ElementwisePowGradKernel(const Context& dev_ctx, dev_ctx, x, y, dout, dout, axis, dx, dy, PowGradDX(), PowGradDY()); } +/* +****************************** + Copysign Grad +****************************** +*/ +template +HOSTDEVICE T compute_copysign_grad_dx(T x, T y, T out, T dout) { + if (x == static_cast(0)) + return x; + else + return static_cast(dout * (funcs::copysign_func(x, y) / x)); +} + +template +struct CopySignGradDX { + HOSTDEVICE T operator()(T x, T y, T out, T dout) const { + return compute_copysign_grad_dx(x, y, out, dout); + } +}; + +template +struct CopySignGradDY { + HOSTDEVICE T operator()(T x, T y, T out, T dout) const { + return static_cast(0); + } +}; + } // namespace phi diff --git a/paddle/phi/kernels/kps/elementwise_kernel.cu b/paddle/phi/kernels/kps/elementwise_kernel.cu index efb6342c149da..a6caa95b766e1 100644 --- a/paddle/phi/kernels/kps/elementwise_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_kernel.cu @@ -162,6 +162,18 @@ void ElementwisePowKernel(const Context& dev_ctx, ElementwisePowRawKernel(dev_ctx, x, y, axis, out); } +template +void CopySignKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { + std::vector inputs = {&x, &y}; + std::vector outputs = {out}; + dev_ctx.template Alloc(out); + funcs::BroadcastKernel( + dev_ctx, inputs, &outputs, funcs::CopySignFunctor()); +} + } // namespace phi #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) @@ -219,6 +231,20 @@ PD_REGISTER_KERNEL(elementwise_pow, int64_t, phi::dtype::float16, phi::dtype::bfloat16) {} +PD_REGISTER_KERNEL(copysign, + GPU, + ALL_LAYOUT, + phi::CopySignKernel, + bool, + uint8_t, + int8_t, + int16_t, + int, + int64_t, + float, + double, + phi::dtype::float16, + phi::dtype::bfloat16) {} #endif