From b1bb74849998b0887f1ce0eec9896c114715256a Mon Sep 17 00:00:00 2001 From: huangjiyi <43315610+huangjiyi@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:30:18 +0800 Subject: [PATCH] update (#52879) --- paddle/fluid/operators/gru_op.cc | 14 ++++++-------- paddle/fluid/operators/gru_op.cu.cc | 13 ++++++------- paddle/fluid/operators/gru_op.h | 2 +- paddle/fluid/operators/gru_unit_op.cc | 10 ++++------ paddle/fluid/operators/gru_unit_op.cu | 11 +++++------ paddle/fluid/operators/gru_unit_op.h | 4 ++-- paddle/fluid/operators/lrn_op.cc | 6 ++++-- paddle/fluid/operators/lrn_op.cu | 5 +++-- paddle/fluid/operators/lrn_op.h | 4 ++-- paddle/fluid/operators/lstm_op.cc | 11 +++++------ paddle/fluid/operators/lstm_op.cu.cc | 10 ++++------ paddle/fluid/operators/lstm_op.h | 4 ++-- paddle/fluid/operators/lstm_unit_op.cc | 12 +++++------- paddle/fluid/operators/lstm_unit_op.cu | 18 ++++++++++-------- paddle/fluid/operators/lstm_unit_op.h | 4 ++-- paddle/fluid/operators/lstmp_op.cc | 10 ++++------ paddle/fluid/operators/lstmp_op.cu | 10 ++++------ paddle/fluid/operators/lstmp_op.h | 4 ++-- 18 files changed, 71 insertions(+), 81 deletions(-) diff --git a/paddle/fluid/operators/gru_op.cc b/paddle/fluid/operators/gru_op.cc index 2d58438dbf3..921076a4a14 100644 --- a/paddle/fluid/operators/gru_op.cc +++ b/paddle/fluid/operators/gru_op.cc @@ -313,11 +313,10 @@ class GRUGradOp : public framework::OperatorWithKernel { } }; -template +template class GRUCPUKernel : public framework::OpKernel { public: void BatchCompute(const framework::ExecutionContext& context) const { - using DeviceContext = phi::CPUContext; using LodTensorPtr = phi::DenseTensor*; bool is_test = context.Attr("is_test"); @@ -585,9 +584,8 @@ REGISTER_OPERATOR(gru, REGISTER_OPERATOR(gru_grad, ops::GRUGradOp, ops::GRUGradOpNoNeedBufferVarInferer); -REGISTER_OP_CPU_KERNEL(gru, - ops::GRUCPUKernel, - ops::GRUCPUKernel); -REGISTER_OP_CPU_KERNEL(gru_grad, - ops::GRUGradKernel, - ops::GRUGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + gru, CPU, ALL_LAYOUT, ops::GRUCPUKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + gru_grad, CPU, ALL_LAYOUT, ops::GRUGradKernel, float, double) {} diff --git a/paddle/fluid/operators/gru_op.cu.cc b/paddle/fluid/operators/gru_op.cu.cc index 0d3686bb495..f89400fca53 100644 --- a/paddle/fluid/operators/gru_op.cu.cc +++ b/paddle/fluid/operators/gru_op.cu.cc @@ -17,7 +17,7 @@ limitations under the License. */ namespace paddle { namespace operators { -template +template class GRUKernel : public framework::OpKernel { public: void BatchCompute(const framework::ExecutionContext& context) const { @@ -133,9 +133,8 @@ class GRUKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(gru, - ops::GRUKernel, - ops::GRUKernel); -REGISTER_OP_CUDA_KERNEL(gru_grad, - ops::GRUGradKernel, - ops::GRUGradKernel); + +PD_REGISTER_STRUCT_KERNEL(gru, GPU, ALL_LAYOUT, ops::GRUKernel, float, double) { +} +PD_REGISTER_STRUCT_KERNEL( + gru_grad, GPU, ALL_LAYOUT, ops::GRUGradKernel, float, double) {} diff --git a/paddle/fluid/operators/gru_op.h b/paddle/fluid/operators/gru_op.h index 760a33a161c..f2fc7663d97 100644 --- a/paddle/fluid/operators/gru_op.h +++ b/paddle/fluid/operators/gru_op.h @@ -36,7 +36,7 @@ inline void ReorderInitState(const DeviceContext& ctx, row_shuffle(ctx, src, index_lod, dst, indexed_src); } -template +template class GRUGradKernel : public framework::OpKernel { public: void BatchCompute(const framework::ExecutionContext& context) const { diff --git a/paddle/fluid/operators/gru_unit_op.cc b/paddle/fluid/operators/gru_unit_op.cc index 7bd104472fe..3c8b2947e5f 100644 --- a/paddle/fluid/operators/gru_unit_op.cc +++ b/paddle/fluid/operators/gru_unit_op.cc @@ -323,9 +323,7 @@ REGISTER_OPERATOR(gru_unit_grad, ops::GRUUnitGradOp, ops::GRUUnitGradOpNoNeedBufferVarInferer); -REGISTER_OP_CPU_KERNEL(gru_unit, - ops::GRUUnitKernel, - ops::GRUUnitKernel); -REGISTER_OP_CPU_KERNEL(gru_unit_grad, - ops::GRUUnitGradKernel, - ops::GRUUnitGradKernel); +PD_REGISTER_STRUCT_KERNEL( + gru_unit, CPU, ALL_LAYOUT, ops::GRUUnitKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + gru_unit_grad, CPU, ALL_LAYOUT, ops::GRUUnitGradKernel, float, double) {} diff --git a/paddle/fluid/operators/gru_unit_op.cu b/paddle/fluid/operators/gru_unit_op.cu index adaaf1d09cd..192594a09e8 100644 --- a/paddle/fluid/operators/gru_unit_op.cu +++ b/paddle/fluid/operators/gru_unit_op.cu @@ -14,9 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/gru_unit_op.h" namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(gru_unit, - ops::GRUUnitKernel, - ops::GRUUnitKernel); -REGISTER_OP_CUDA_KERNEL(gru_unit_grad, - ops::GRUUnitGradKernel, - ops::GRUUnitGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + gru_unit, GPU, ALL_LAYOUT, ops::GRUUnitKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + gru_unit_grad, GPU, ALL_LAYOUT, ops::GRUUnitGradKernel, float, double) {} diff --git a/paddle/fluid/operators/gru_unit_op.h b/paddle/fluid/operators/gru_unit_op.h index c22a82c5ae8..9309ca0417f 100644 --- a/paddle/fluid/operators/gru_unit_op.h +++ b/paddle/fluid/operators/gru_unit_op.h @@ -25,7 +25,7 @@ namespace operators { enum GRUActivationType { identity = 0, sigmoid = 1, tanh = 2, relu = 3 }; -template +template class GRUUnitKernel : public framework::OpKernel { public: template @@ -153,7 +153,7 @@ class GRUUnitKernel : public framework::OpKernel { } }; -template +template class GRUUnitGradKernel : public framework::OpKernel { public: template diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index 96d5a115991..d16b2abf471 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -400,5 +400,7 @@ REGISTER_OPERATOR(lrn, ops::LRNGradOpMaker); REGISTER_OPERATOR(lrn_grad, ops::LRNOpGrad); -REGISTER_OP_CPU_KERNEL(lrn, ops::LRNKernel); -REGISTER_OP_CPU_KERNEL(lrn_grad, ops::LRNGradKernel); + +PD_REGISTER_STRUCT_KERNEL(lrn, CPU, ALL_LAYOUT, ops::LRNKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + lrn_grad, CPU, ALL_LAYOUT, ops::LRNGradKernel, float) {} diff --git a/paddle/fluid/operators/lrn_op.cu b/paddle/fluid/operators/lrn_op.cu index 22b4f0c4618..20f56cb8f9b 100644 --- a/paddle/fluid/operators/lrn_op.cu +++ b/paddle/fluid/operators/lrn_op.cu @@ -274,5 +274,6 @@ template struct LRNGradFunctor; } // namespace paddle namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(lrn, ops::LRNKernel); -REGISTER_OP_CUDA_KERNEL(lrn_grad, ops::LRNGradKernel); +PD_REGISTER_STRUCT_KERNEL(lrn, GPU, ALL_LAYOUT, ops::LRNKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + lrn_grad, GPU, ALL_LAYOUT, ops::LRNGradKernel, float) {} diff --git a/paddle/fluid/operators/lrn_op.h b/paddle/fluid/operators/lrn_op.h index b772aa82e9d..15ebb4df74f 100644 --- a/paddle/fluid/operators/lrn_op.h +++ b/paddle/fluid/operators/lrn_op.h @@ -43,7 +43,7 @@ struct LRNFunctor { const DataLayout data_layout = DataLayout::kAnyLayout); }; -template +template class LRNKernel : public framework::OpKernel { public: // f(x) = x * ( k + alpha * SUM((x)^2) )^(-beta) @@ -136,7 +136,7 @@ struct LRNGradFunctor { * The upper and lower is the same as forward. The logic of the sum * is also the same as forward. */ -template +template class LRNGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/lstm_op.cc b/paddle/fluid/operators/lstm_op.cc index 7250cf65e48..d7734e57ee4 100644 --- a/paddle/fluid/operators/lstm_op.cc +++ b/paddle/fluid/operators/lstm_op.cc @@ -358,9 +358,8 @@ REGISTER_OPERATOR(lstm, ops::LSTMGradOpMaker, ops::LSTMGradOpMaker); REGISTER_OPERATOR(lstm_grad, ops::LSTMGradOp); -REGISTER_OP_CPU_KERNEL(lstm, - ops::LSTMKernel, - ops::LSTMKernel); -REGISTER_OP_CPU_KERNEL(lstm_grad, - ops::LSTMGradKernel, - ops::LSTMGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + lstm, CPU, ALL_LAYOUT, ops::LSTMKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + lstm_grad, CPU, ALL_LAYOUT, ops::LSTMGradKernel, float, double) {} diff --git a/paddle/fluid/operators/lstm_op.cu.cc b/paddle/fluid/operators/lstm_op.cu.cc index 13a0ded14b4..b06521088a9 100644 --- a/paddle/fluid/operators/lstm_op.cu.cc +++ b/paddle/fluid/operators/lstm_op.cu.cc @@ -15,9 +15,7 @@ limitations under the License. */ #include "paddle/fluid/operators/lstm_op.h" namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(lstm, - ops::LSTMKernel, - ops::LSTMKernel); -REGISTER_OP_CUDA_KERNEL(lstm_grad, - ops::LSTMGradKernel, - ops::LSTMGradKernel); +PD_REGISTER_STRUCT_KERNEL( + lstm, GPU, ALL_LAYOUT, ops::LSTMKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + lstm_grad, GPU, ALL_LAYOUT, ops::LSTMGradKernel, float, double) {} diff --git a/paddle/fluid/operators/lstm_op.h b/paddle/fluid/operators/lstm_op.h index cba58781565..0e068c47647 100644 --- a/paddle/fluid/operators/lstm_op.h +++ b/paddle/fluid/operators/lstm_op.h @@ -35,7 +35,7 @@ inline void ReorderInitState(const DeviceContext& ctx, row_shuffle(ctx, src, index_lod, dst, indexed_src); } -template +template class LSTMKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -197,7 +197,7 @@ class LSTMKernel : public framework::OpKernel { } }; -template +template class LSTMGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/lstm_unit_op.cc b/paddle/fluid/operators/lstm_unit_op.cc index dab7164fad1..bbe5504b98e 100644 --- a/paddle/fluid/operators/lstm_unit_op.cc +++ b/paddle/fluid/operators/lstm_unit_op.cc @@ -142,10 +142,8 @@ REGISTER_OPERATOR(lstm_unit, ops::LstmUnitGradOpMaker, ops::LstmUnitGradOpMaker); REGISTER_OPERATOR(lstm_unit_grad, ops::LstmUnitGradOp); -REGISTER_OP_CPU_KERNEL(lstm_unit, - ops::LstmUnitKernel, - ops::LstmUnitKernel); -REGISTER_OP_CPU_KERNEL( - lstm_unit_grad, - ops::LstmUnitGradKernel, - ops::LstmUnitGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + lstm_unit, CPU, ALL_LAYOUT, ops::LstmUnitKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + lstm_unit_grad, CPU, ALL_LAYOUT, ops::LstmUnitGradKernel, float, double) {} diff --git a/paddle/fluid/operators/lstm_unit_op.cu b/paddle/fluid/operators/lstm_unit_op.cu index ffc6e42587f..b1c9d035a8c 100644 --- a/paddle/fluid/operators/lstm_unit_op.cu +++ b/paddle/fluid/operators/lstm_unit_op.cu @@ -98,7 +98,7 @@ __global__ void LSTMUnitGradientKernel(const int nthreads, } } -template +template class LstmUnitOpCUDAKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -131,7 +131,7 @@ class LstmUnitOpCUDAKernel : public framework::OpKernel { } }; -template +template class LstmUnitGradOpCUDAKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -183,9 +183,11 @@ class LstmUnitGradOpCUDAKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(lstm_unit, - ops::LstmUnitOpCUDAKernel, - ops::LstmUnitOpCUDAKernel); -REGISTER_OP_CUDA_KERNEL(lstm_unit_grad, - ops::LstmUnitGradOpCUDAKernel, - ops::LstmUnitGradOpCUDAKernel); +PD_REGISTER_STRUCT_KERNEL( + lstm_unit, GPU, ALL_LAYOUT, ops::LstmUnitOpCUDAKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL(lstm_unit_grad, + GPU, + ALL_LAYOUT, + ops::LstmUnitGradOpCUDAKernel, + float, + double) {} diff --git a/paddle/fluid/operators/lstm_unit_op.h b/paddle/fluid/operators/lstm_unit_op.h index abb2eb1620d..0621741b885 100644 --- a/paddle/fluid/operators/lstm_unit_op.h +++ b/paddle/fluid/operators/lstm_unit_op.h @@ -33,7 +33,7 @@ inline T tanh(T x) { return 2. * sigmoid(2. * x) - 1.; } -template +template class LstmUnitKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -78,7 +78,7 @@ class LstmUnitKernel : public framework::OpKernel { } }; -template +template class LstmUnitGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/lstmp_op.cc b/paddle/fluid/operators/lstmp_op.cc index 63cf07e35b7..44e9a698bee 100644 --- a/paddle/fluid/operators/lstmp_op.cc +++ b/paddle/fluid/operators/lstmp_op.cc @@ -405,9 +405,7 @@ REGISTER_OPERATOR(lstmp, ops::LSTMPGradMaker, ops::LSTMPGradMaker); REGISTER_OPERATOR(lstmp_grad, ops::LSTMPGradOp); -REGISTER_OP_CPU_KERNEL(lstmp, - ops::LSTMPKernel, - ops::LSTMPKernel); -REGISTER_OP_CPU_KERNEL(lstmp_grad, - ops::LSTMPGradKernel, - ops::LSTMPGradKernel); +PD_REGISTER_STRUCT_KERNEL( + lstmp, CPU, ALL_LAYOUT, ops::LSTMPKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + lstmp_grad, CPU, ALL_LAYOUT, ops::LSTMPGradKernel, float, double) {} diff --git a/paddle/fluid/operators/lstmp_op.cu b/paddle/fluid/operators/lstmp_op.cu index 8614eaf5d49..5559d09f1b9 100644 --- a/paddle/fluid/operators/lstmp_op.cu +++ b/paddle/fluid/operators/lstmp_op.cu @@ -15,9 +15,7 @@ limitations under the License. */ #include "paddle/fluid/operators/lstmp_op.h" namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(lstmp, - ops::LSTMPKernel, - ops::LSTMPKernel); -REGISTER_OP_CUDA_KERNEL(lstmp_grad, - ops::LSTMPGradKernel, - ops::LSTMPGradKernel); +PD_REGISTER_STRUCT_KERNEL( + lstmp, GPU, ALL_LAYOUT, ops::LSTMPKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL( + lstmp_grad, GPU, ALL_LAYOUT, ops::LSTMPGradKernel, float, double) {} diff --git a/paddle/fluid/operators/lstmp_op.h b/paddle/fluid/operators/lstmp_op.h index 90e3072dbf9..fd9032c730a 100644 --- a/paddle/fluid/operators/lstmp_op.h +++ b/paddle/fluid/operators/lstmp_op.h @@ -78,7 +78,7 @@ inline void ReorderInitState(const DeviceContext& ctx, row_shuffle(ctx, src, index, dst, indexed_src); } -template +template class LSTMPKernel : public framework::OpKernel { public: template @@ -279,7 +279,7 @@ class LSTMPKernel : public framework::OpKernel { } }; -template +template class LSTMPGradKernel : public framework::OpKernel { public: template -- GitLab