Skip to content

Commit cac00e0

Browse files
authored
[Phi]Delete kernel registry of elementwise_sub op in Fluid (#40039)
* delete elementwise_sub kernel registry * fix compile bugs in xpu ci * fix bugs when run inference ci
1 parent c3f3643 commit cac00e0

File tree

9 files changed

+20
-212
lines changed

9 files changed

+20
-212
lines changed

paddle/fluid/operators/elementwise/elementwise_op_npu_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace p = paddle::platform;
3333

3434
USE_OP_ITSELF(elementwise_add);
3535
USE_OP_DEVICE_KERNEL(elementwise_add, NPU);
36-
USE_OP(elementwise_sub);
36+
USE_OP_ITSELF(elementwise_sub);
3737
USE_OP_DEVICE_KERNEL(elementwise_sub, NPU);
3838

3939
template <typename T>

paddle/fluid/operators/elementwise/elementwise_pow_op_xpu.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ limitations under the License. */
1414

1515
#ifdef PADDLE_WITH_XPU
1616
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
17-
#include "paddle/fluid/operators/elementwise/elementwise_sub_op.h"
1817
#include "paddle/fluid/operators/elementwise/elementwise_xpu.h"
1918
#include "xpu/refactor/math.h"
2019

paddle/fluid/operators/elementwise/elementwise_sub_op.cc

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
#include "paddle/fluid/operators/elementwise/elementwise_sub_op.h"
16-
1715
#include <string>
1816

1917
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
@@ -78,10 +76,16 @@ class ElementwiseSubDoubleGradMaker : public framework::SingleGradOpMaker<T> {
7876
} // namespace paddle
7977

8078
REGISTER_ELEMWISE_GRAD_MAKER(elementwise_sub, Sub);
81-
REGISTER_ELEMWISE_EXPLICIT_OP_WITHOUT_GRAD(elementwise_sub, Sub);
8279

8380
namespace ops = paddle::operators;
8481

82+
REGISTER_OPERATOR(elementwise_sub, ::paddle::operators::ElementwiseOp,
83+
::paddle::operators::ElementwiseSubOpMaker,
84+
::paddle::operators::ElementwiseOpInferVarType,
85+
elementwise_subGradMaker<::paddle::framework::OpDesc>,
86+
elementwise_subGradMaker<::paddle::imperative::OpBase>,
87+
::paddle::operators::ElementwiseOpInplaceInferer);
88+
8589
REGISTER_OPERATOR(
8690
elementwise_sub_grad, ops::ElementwiseOpGrad,
8791
ops::ElementwiseGradOpInplaceInferer, ops::ElementwiseGradNoBufVarsInferer,
@@ -92,51 +96,6 @@ REGISTER_OPERATOR(elementwise_sub_grad_grad,
9296
ops::ElementwiseDoubleGradOpInplaceInferer,
9397
ops::ElementwiseDoubleGradNoBufVarsInferer);
9498

95-
REGISTER_OP_CPU_KERNEL(
96-
elementwise_sub,
97-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext, float>,
98-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext, double>,
99-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext, int16_t>,
100-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext, int>,
101-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext, int64_t>,
102-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext,
103-
paddle::platform::bfloat16>,
104-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext,
105-
paddle::platform::complex<float>>,
106-
ops::ElementwiseSubKernel<paddle::platform::CPUDeviceContext,
107-
paddle::platform::complex<double>>);
108-
REGISTER_OP_CPU_KERNEL(
109-
elementwise_sub_grad,
110-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext, float>,
111-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext, double>,
112-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext, int16_t>,
113-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext, int>,
114-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext, int64_t>,
115-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext,
116-
paddle::platform::bfloat16>,
117-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext,
118-
paddle::platform::complex<float>>,
119-
ops::ElementwiseSubGradKernel<paddle::platform::CPUDeviceContext,
120-
paddle::platform::complex<double>>);
121-
REGISTER_OP_CPU_KERNEL(
122-
elementwise_sub_grad_grad,
123-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
124-
float>,
125-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
126-
double>,
127-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
128-
int16_t>,
129-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
130-
int>,
131-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
132-
int64_t>,
133-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
134-
paddle::platform::bfloat16>,
135-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
136-
paddle::platform::complex<float>>,
137-
ops::ElementwiseSubDoubleGradKernel<paddle::platform::CPUDeviceContext,
138-
paddle::platform::complex<double>>);
139-
14099
REGISTER_OP_VERSION(elementwise_sub)
141100
.AddCheckpoint(
142101
R"ROC(Register elementwise_sub for adding the attribute of Scale_y)ROC",

paddle/fluid/operators/elementwise/elementwise_sub_op.cu

Lines changed: 0 additions & 63 deletions
This file was deleted.

paddle/fluid/operators/elementwise/elementwise_sub_op.h

Lines changed: 0 additions & 96 deletions
This file was deleted.

paddle/fluid/operators/elementwise/elementwise_sub_op_npu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License. */
1515
#include <memory>
1616
#include <string>
1717

18-
#include "paddle/fluid/operators/elementwise/elementwise_sub_op.h"
18+
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
1919
#include "paddle/fluid/platform/device/npu/npu_op_runner.h"
2020

2121
namespace paddle {

paddle/fluid/operators/elementwise/elementwise_sub_op_xpu.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#ifdef PADDLE_WITH_XPU
16-
#include "paddle/fluid/operators/elementwise/elementwise_sub_op.h"
1716
#include "paddle/fluid/operators/elementwise/elementwise_op.h"
1817
#include "paddle/fluid/operators/elementwise/elementwise_xpu.h"
1918
#include "xpu/refactor/math.h"

paddle/phi/kernels/math_kernel.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ PD_REGISTER_KERNEL(subtract,
197197
int64_t,
198198
phi::dtype::float16,
199199
complex64,
200-
complex128) {}
200+
complex128,
201+
phi::dtype::bfloat16) {}
201202
PD_REGISTER_KERNEL(divide,
202203
GPU,
203204
ALL_LAYOUT,

paddle/phi/ops/compat/elementwise_sig.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ KernelSignature ElementwiseSubGradOpArgumentMapping(
100100
return KernelSignature("unregistered", {}, {}, {});
101101
}
102102

103+
KernelSignature ElementwiseSubDoubleGradOpArgumentMapping(
104+
const ArgumentMappingContext& ctx) {
105+
return KernelSignature(
106+
"subtract_double_grad", {"Y", "DDX", "DDY", "DOut"}, {"axis"}, {"DDOut"});
107+
}
108+
103109
} // namespace phi
104110

105111
PD_REGISTER_BASE_KERNEL_NAME(elementwise_add, add);
@@ -110,6 +116,7 @@ PD_REGISTER_BASE_KERNEL_NAME(elementwise_add_grad, add_grad);
110116
PD_REGISTER_BASE_KERNEL_NAME(elementwise_add_grad_grad, add_double_grad);
111117
PD_REGISTER_BASE_KERNEL_NAME(elementwise_add_triple_grad, add_triple_grad);
112118
PD_REGISTER_BASE_KERNEL_NAME(elementwise_sub_grad, subtract_grad);
119+
PD_REGISTER_BASE_KERNEL_NAME(elementwise_sub_grad_grad, subtract_double_grad);
113120

114121
PD_REGISTER_ARG_MAPPING_FN(elementwise_add,
115122
phi::ElementwiseAddOpArgumentMapping);
@@ -127,3 +134,5 @@ PD_REGISTER_ARG_MAPPING_FN(elementwise_add_triple_grad,
127134
phi::ElementwiseAddTripleGradOpArgumentMapping);
128135
PD_REGISTER_ARG_MAPPING_FN(elementwise_sub_grad,
129136
phi::ElementwiseSubGradOpArgumentMapping);
137+
PD_REGISTER_ARG_MAPPING_FN(elementwise_sub_grad_grad,
138+
phi::ElementwiseSubDoubleGradOpArgumentMapping);

0 commit comments

Comments
 (0)