未验证 提交 fb42ba70 编写于 作者: R risemeup1 提交者: GitHub

move elementwise_sub and elementwise_sub_grad XPU kernel to PHI,test=kunlun (#45623)

* move elementwise_sub and elementwise_sub_grad XPU kernel to PHI,test=kunlun

* modify code style,test=kunlun

* modify elementwise_subtract_grad_kernel.cc,test=kunlun

* modify elementwise_subtract_kernel.cc,test=kunlun

* modify elementwise_subtract_grad_kernel.cc,test=kunlun

* modify elementwise_kernel.cc and elementwise_subtract_kernel.cc,test=kunlun

* modify codestyle,test=kunlun

* modify elementwise_kernel.cc,test=kunlun
上级 f3c6d19c
...@@ -334,7 +334,12 @@ PD_REGISTER_KERNEL(multiply, ...@@ -334,7 +334,12 @@ PD_REGISTER_KERNEL(multiply,
phi::MultiplyKernel, phi::MultiplyKernel,
phi::dtype::float16, phi::dtype::float16,
float) {} float) {}
PD_REGISTER_KERNEL(subtract,
XPU,
ALL_LAYOUT,
phi::SubtractKernel,
float,
phi::dtype::float16) {}
#endif #endif
#if defined PADDLE_WITH_XPU #if defined PADDLE_WITH_XPU
......
/* 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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -12,46 +12,38 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,46 +12,38 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#ifdef PADDLE_WITH_XPU #include "paddle/phi/kernels/elementwise_subtract_grad_kernel.h"
#include "paddle/fluid/operators/elementwise/elementwise_op.h" #include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/fluid/operators/elementwise/elementwise_xpu.h" #include "paddle/phi/backends/xpu/xpu_header.h"
#include "xpu/refactor/math.h" #include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/xpu/elementwise.h"
namespace paddle {
namespace operators { namespace phi {
template <typename T, typename Context>
template <typename T> void SubtractGradKernel(const Context& dev_ctx,
class ElementwiseSubXPUKernel : public framework::OpKernel<T> { const DenseTensor& x,
using XPUType = typename XPUTypeTrait<T>::Type; const DenseTensor& y,
const DenseTensor& dout,
public: int axis,
void Compute(const framework::ExecutionContext& ctx) const override { DenseTensor* dx,
XPUElementwise<T, XPUType>(ctx, xpu::broadcast_sub<XPUType>); DenseTensor* dy) {
}
};
template <typename T>
class ElementwiseSubGradXPUKernel : public ElemwiseGradKernel<T> {
using XPUType = typename XPUTypeTrait<T>::Type; using XPUType = typename XPUTypeTrait<T>::Type;
phi::XPUElementwiseGrad<T, XPUType>(dev_ctx,
public: x,
void Compute(const framework::ExecutionContext& ctx) const override { y,
ElemwiseGradKernel<T>::Compute(ctx); dout,
XPUElementwiseGrad<T, XPUType>( axis,
ctx, xpu::broadcast_sub_grad<XPUType>, false); dx,
} dy,
}; xpu::broadcast_sub_grad<XPUType>,
false);
} // namespace operators }
} // namespace paddle
} // namespace phi
namespace ops = paddle::operators;
REGISTER_OP_XPU_KERNEL(elementwise_sub, PD_REGISTER_KERNEL(subtract_grad,
ops::ElementwiseSubXPUKernel<float>, XPU,
ops::ElementwiseSubXPUKernel<paddle::platform::float16>); ALL_LAYOUT,
REGISTER_OP_XPU_KERNEL( phi::SubtractGradKernel,
elementwise_sub_grad, phi::dtype::float16,
ops::ElementwiseSubGradXPUKernel<float>, float) {}
ops::ElementwiseSubGradXPUKernel<paddle::platform::float16>);
#endif
/* 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 <typename T, typename Context>
void SubtractRawKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& y,
int axis,
DenseTensor* out) {
using XPUType = typename XPUTypeTrait<T>::Type;
phi::XPUElementwise<T, XPUType>(
dev_ctx, x, y, axis, out, xpu::broadcast_sub<XPUType>);
}
} // namespace phi
PD_REGISTER_KERNEL(subtract_raw,
XPU,
ALL_LAYOUT,
phi::SubtractRawKernel,
float,
phi::dtype::float16) {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册