未验证 提交 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,
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
......
/* 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.
......@@ -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
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 <typename T>
class ElementwiseSubXPUKernel : public framework::OpKernel<T> {
using XPUType = typename XPUTypeTrait<T>::Type;
public:
void Compute(const framework::ExecutionContext& ctx) const override {
XPUElementwise<T, XPUType>(ctx, xpu::broadcast_sub<XPUType>);
}
};
template <typename T>
class ElementwiseSubGradXPUKernel : public ElemwiseGradKernel<T> {
#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 <typename T, typename Context>
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<T>::Type;
public:
void Compute(const framework::ExecutionContext& ctx) const override {
ElemwiseGradKernel<T>::Compute(ctx);
XPUElementwiseGrad<T, XPUType>(
ctx, xpu::broadcast_sub_grad<XPUType>, false);
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP_XPU_KERNEL(elementwise_sub,
ops::ElementwiseSubXPUKernel<float>,
ops::ElementwiseSubXPUKernel<paddle::platform::float16>);
REGISTER_OP_XPU_KERNEL(
elementwise_sub_grad,
ops::ElementwiseSubGradXPUKernel<float>,
ops::ElementwiseSubGradXPUKernel<paddle::platform::float16>);
#endif
phi::XPUElementwiseGrad<T, XPUType>(dev_ctx,
x,
y,
dout,
axis,
dx,
dy,
xpu::broadcast_sub_grad<XPUType>,
false);
}
} // namespace phi
PD_REGISTER_KERNEL(subtract_grad,
XPU,
ALL_LAYOUT,
phi::SubtractGradKernel,
phi::dtype::float16,
float) {}
/* 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.
先完成此消息的编辑!
想要评论请 注册