From 2f4997135c3703a8a9476af20e79c6b443517eea Mon Sep 17 00:00:00 2001 From: huangjiyi <43315610+huangjiyi@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:33:08 +0800 Subject: [PATCH] update (#52880) --- paddle/fluid/operators/hash_op.cc | 4 ++- paddle/fluid/operators/hash_op.h | 2 +- paddle/fluid/operators/hinge_loss_op.cc | 21 ++++++++------- paddle/fluid/operators/hinge_loss_op.h | 4 +-- paddle/fluid/operators/im2sequence_op.cc | 21 ++++++++------- paddle/fluid/operators/im2sequence_op.h | 4 +-- paddle/fluid/operators/inplace_abn_op.cc | 18 +++++++------ paddle/fluid/operators/inplace_abn_op.cu | 26 ++++++++++--------- .../fluid/operators/limit_by_capacity_op.cc | 11 +++++--- .../fluid/operators/limit_by_capacity_op.cu | 11 ++++---- paddle/fluid/operators/limit_by_capacity_op.h | 2 +- paddle/fluid/operators/linear_chain_crf_op.cc | 20 +++++++++----- paddle/fluid/operators/linear_chain_crf_op.h | 4 +-- paddle/fluid/operators/margin_rank_loss_op.cc | 12 ++++++--- paddle/fluid/operators/margin_rank_loss_op.cu | 11 +++++--- paddle/fluid/operators/margin_rank_loss_op.h | 4 +-- .../fluid/operators/modified_huber_loss_op.cc | 12 ++++++--- .../fluid/operators/modified_huber_loss_op.cu | 15 +++++++---- .../fluid/operators/modified_huber_loss_op.h | 4 +-- 19 files changed, 122 insertions(+), 84 deletions(-) diff --git a/paddle/fluid/operators/hash_op.cc b/paddle/fluid/operators/hash_op.cc index f111a379e16..e5fc57c6567 100644 --- a/paddle/fluid/operators/hash_op.cc +++ b/paddle/fluid/operators/hash_op.cc @@ -79,4 +79,6 @@ class HashOpMaker : public framework::OpProtoAndCheckerMaker { namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(hash, ops::HashOp, ops::HashOpMaker); -REGISTER_OP_CPU_KERNEL(hash, ops::HashKernel, ops::HashKernel); + +PD_REGISTER_STRUCT_KERNEL( + hash, CPU, ALL_LAYOUT, ops::HashKernel, int, int64_t) {} diff --git a/paddle/fluid/operators/hash_op.h b/paddle/fluid/operators/hash_op.h index 47b478025b4..700f7c1d701 100644 --- a/paddle/fluid/operators/hash_op.h +++ b/paddle/fluid/operators/hash_op.h @@ -38,7 +38,7 @@ inline void HashOutputSize(const framework::DDim& in_dims, out_dims.emplace_back(1); } -template +template class HashKernel : public framework::OpKernel { public: virtual void Compute(const framework::ExecutionContext& context) const { diff --git a/paddle/fluid/operators/hinge_loss_op.cc b/paddle/fluid/operators/hinge_loss_op.cc index 6741af76388..dea3ce3fe69 100644 --- a/paddle/fluid/operators/hinge_loss_op.cc +++ b/paddle/fluid/operators/hinge_loss_op.cc @@ -150,12 +150,15 @@ REGISTER_OPERATOR(hinge_loss, ops::HingeLossGradOpMaker, ops::HingeLossGradOpMaker); REGISTER_OPERATOR(hinge_loss_grad, ops::HingeLossGradOp); -REGISTER_OP_CPU_KERNEL(hinge_loss, - ops::HingeLossKernel); -REGISTER_OP_CPU_KERNEL(hinge_loss_grad, - ops::HingeLossGradKernel); - -REGISTER_OP_CUDA_KERNEL(hinge_loss, - ops::HingeLossKernel); -REGISTER_OP_CUDA_KERNEL(hinge_loss_grad, - ops::HingeLossGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + hinge_loss, CPU, ALL_LAYOUT, ops::HingeLossKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + hinge_loss_grad, CPU, ALL_LAYOUT, ops::HingeLossGradKernel, float) {} + +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +PD_REGISTER_STRUCT_KERNEL( + hinge_loss, GPU, ALL_LAYOUT, ops::HingeLossKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + hinge_loss_grad, GPU, ALL_LAYOUT, ops::HingeLossGradKernel, float) {} +#endif diff --git a/paddle/fluid/operators/hinge_loss_op.h b/paddle/fluid/operators/hinge_loss_op.h index 8f06154c790..968b79ea91b 100644 --- a/paddle/fluid/operators/hinge_loss_op.h +++ b/paddle/fluid/operators/hinge_loss_op.h @@ -20,7 +20,7 @@ limitations under the License. */ namespace paddle { namespace operators { -template +template class HingeLossKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { @@ -38,7 +38,7 @@ class HingeLossKernel : public framework::OpKernel { } }; -template +template class HingeLossGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { diff --git a/paddle/fluid/operators/im2sequence_op.cc b/paddle/fluid/operators/im2sequence_op.cc index b58f9a55756..8c123bb8a32 100644 --- a/paddle/fluid/operators/im2sequence_op.cc +++ b/paddle/fluid/operators/im2sequence_op.cc @@ -195,12 +195,15 @@ REGISTER_OPERATOR(im2sequence, ops::Im2SequenceGradMaker, ops::Im2SequenceGradMaker); REGISTER_OPERATOR(im2sequence_grad, ops::Im2SequenceGradOp); -REGISTER_OP_CPU_KERNEL(im2sequence, - ops::Im2SequenceKernel); -REGISTER_OP_CPU_KERNEL(im2sequence_grad, - ops::Im2SequenceGradKernel); - -REGISTER_OP_CUDA_KERNEL(im2sequence, - ops::Im2SequenceKernel); -REGISTER_OP_CUDA_KERNEL(im2sequence_grad, - ops::Im2SequenceGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + im2sequence, CPU, ALL_LAYOUT, ops::Im2SequenceKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + im2sequence_grad, CPU, ALL_LAYOUT, ops::Im2SequenceGradKernel, float) {} + +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +PD_REGISTER_STRUCT_KERNEL( + im2sequence, GPU, ALL_LAYOUT, ops::Im2SequenceKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + im2sequence_grad, GPU, ALL_LAYOUT, ops::Im2SequenceGradKernel, float) {} +#endif diff --git a/paddle/fluid/operators/im2sequence_op.h b/paddle/fluid/operators/im2sequence_op.h index 523639faddc..18e6d429f1b 100644 --- a/paddle/fluid/operators/im2sequence_op.h +++ b/paddle/fluid/operators/im2sequence_op.h @@ -33,7 +33,7 @@ inline int Im2SeqOutputSize( return output_size; } -template +template class Im2SequenceKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -153,7 +153,7 @@ class Im2SequenceKernel : public framework::OpKernel { } }; -template +template class Im2SequenceGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/inplace_abn_op.cc b/paddle/fluid/operators/inplace_abn_op.cc index 5acc9f1bd13..5deffde2b56 100644 --- a/paddle/fluid/operators/inplace_abn_op.cc +++ b/paddle/fluid/operators/inplace_abn_op.cc @@ -210,7 +210,7 @@ class InplaceABNOpGradMaker : public framework::SingleGradOpMaker { } }; -template +template class InplaceABNKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -270,7 +270,7 @@ class InplaceABNKernel : public framework::OpKernel { } }; -template +template class InplaceABNGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -373,9 +373,11 @@ REGISTER_OPERATOR(inplace_abn, InplaceAbnOpInplaceInferer) REGISTER_OPERATOR(inplace_abn_grad, ops::InplaceABNGradOp) -REGISTER_OP_CPU_KERNEL(inplace_abn, - ops::InplaceABNKernel, - ops::InplaceABNKernel); -REGISTER_OP_CPU_KERNEL(inplace_abn_grad, - ops::InplaceABNGradKernel, - ops::InplaceABNGradKernel); +PD_REGISTER_STRUCT_KERNEL( + inplace_abn, CPU, ALL_LAYOUT, ops::InplaceABNKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL(inplace_abn_grad, + CPU, + ALL_LAYOUT, + ops::InplaceABNGradKernel, + float, + double) {} diff --git a/paddle/fluid/operators/inplace_abn_op.cu b/paddle/fluid/operators/inplace_abn_op.cu index a7d5a514c58..38db9e847bf 100644 --- a/paddle/fluid/operators/inplace_abn_op.cu +++ b/paddle/fluid/operators/inplace_abn_op.cu @@ -23,7 +23,7 @@ limitations under the License. */ namespace paddle { namespace operators { -template +template class InplaceABNKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -109,7 +109,7 @@ class InplaceABNKernel : public framework::OpKernel { // Deriving the Gradient for the Backward Pass of Batch Normalization // https://kevinzakka.github.io/2016/09/14/batch_normalization/ -template +template class InplaceABNGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -221,15 +221,17 @@ namespace ops = paddle::operators; namespace plat = paddle::platform; #ifdef PADDLE_WITH_HIP // MIOPEN do not support double -REGISTER_OP_CUDA_KERNEL(inplace_abn, - ops::InplaceABNKernel); -REGISTER_OP_CUDA_KERNEL(inplace_abn_grad, - ops::InplaceABNGradKernel); +PD_REGISTER_STRUCT_KERNEL( + inplace_abn, GPU, ALL_LAYOUT, ops::InplaceABNKernel, float) {} +PD_REGISTER_STRUCT_KERNEL( + inplace_abn_grad, GPU, ALL_LAYOUT, ops::InplaceABNGradKernel, float) {} #else -REGISTER_OP_CUDA_KERNEL(inplace_abn, - ops::InplaceABNKernel, - ops::InplaceABNKernel); -REGISTER_OP_CUDA_KERNEL(inplace_abn_grad, - ops::InplaceABNGradKernel, - ops::InplaceABNGradKernel); +PD_REGISTER_STRUCT_KERNEL( + inplace_abn, GPU, ALL_LAYOUT, ops::InplaceABNKernel, float, double) {} +PD_REGISTER_STRUCT_KERNEL(inplace_abn_grad, + GPU, + ALL_LAYOUT, + ops::InplaceABNGradKernel, + float, + double) {} #endif diff --git a/paddle/fluid/operators/limit_by_capacity_op.cc b/paddle/fluid/operators/limit_by_capacity_op.cc index ffae23c7025..e4ce30d41ae 100644 --- a/paddle/fluid/operators/limit_by_capacity_op.cc +++ b/paddle/fluid/operators/limit_by_capacity_op.cc @@ -77,10 +77,13 @@ class LimitByCapacityOpMaker : public framework::OpProtoAndCheckerMaker { namespace ops = paddle::operators; namespace plat = paddle::platform; -REGISTER_OP_CPU_KERNEL(limit_by_capacity, - ops::LimitByCapacityOpCPUKernel, - ops::LimitByCapacityOpCPUKernel); - REGISTER_OP_WITHOUT_GRADIENT(limit_by_capacity, ops::LimitByCapacityOp, ops::LimitByCapacityOpMaker); + +PD_REGISTER_STRUCT_KERNEL(limit_by_capacity, + CPU, + ALL_LAYOUT, + ops::LimitByCapacityOpCPUKernel, + int, + int64_t) {} diff --git a/paddle/fluid/operators/limit_by_capacity_op.cu b/paddle/fluid/operators/limit_by_capacity_op.cu index d14e4c75425..4ddc9211448 100644 --- a/paddle/fluid/operators/limit_by_capacity_op.cu +++ b/paddle/fluid/operators/limit_by_capacity_op.cu @@ -47,7 +47,7 @@ __global__ void limit_by_capacity_impl( } } -template +template class LimitByCapacityOpCUDAKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { @@ -78,7 +78,8 @@ class LimitByCapacityOpCUDAKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -namespace plat = paddle::platform; - -REGISTER_OP_CUDA_KERNEL(limit_by_capacity, - ops::LimitByCapacityOpCUDAKernel); +PD_REGISTER_STRUCT_KERNEL(limit_by_capacity, + GPU, + ALL_LAYOUT, + ops::LimitByCapacityOpCUDAKernel, + int64_t) {} diff --git a/paddle/fluid/operators/limit_by_capacity_op.h b/paddle/fluid/operators/limit_by_capacity_op.h index c76d298f429..c08183b5f1a 100644 --- a/paddle/fluid/operators/limit_by_capacity_op.h +++ b/paddle/fluid/operators/limit_by_capacity_op.h @@ -24,7 +24,7 @@ namespace paddle { namespace operators { -template +template class LimitByCapacityOpCPUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/linear_chain_crf_op.cc b/paddle/fluid/operators/linear_chain_crf_op.cc index ebaa61416f0..46ff4c2e94a 100644 --- a/paddle/fluid/operators/linear_chain_crf_op.cc +++ b/paddle/fluid/operators/linear_chain_crf_op.cc @@ -395,10 +395,16 @@ REGISTER_OPERATOR(linear_chain_crf, REGISTER_OPERATOR(linear_chain_crf_grad, ops::LinearChainCRFGradOp, ops::LinearChainCRFGradNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL(linear_chain_crf, - ops::LinearChainCRFOpKernel, - ops::LinearChainCRFOpKernel); -REGISTER_OP_CPU_KERNEL( - linear_chain_crf_grad, - ops::LinearChainCRFGradOpKernel, - ops::LinearChainCRFGradOpKernel); + +PD_REGISTER_STRUCT_KERNEL(linear_chain_crf, + CPU, + ALL_LAYOUT, + ops::LinearChainCRFOpKernel, + float, + double) {} +PD_REGISTER_STRUCT_KERNEL(linear_chain_crf_grad, + CPU, + ALL_LAYOUT, + ops::LinearChainCRFGradOpKernel, + float, + double) {} diff --git a/paddle/fluid/operators/linear_chain_crf_op.h b/paddle/fluid/operators/linear_chain_crf_op.h index bf68c7298e7..49387240625 100644 --- a/paddle/fluid/operators/linear_chain_crf_op.h +++ b/paddle/fluid/operators/linear_chain_crf_op.h @@ -48,7 +48,7 @@ struct ScalarMul { using framework::LoD; -template +template class LinearChainCRFOpKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { @@ -245,7 +245,7 @@ class LinearChainCRFOpKernel : public framework::OpKernel { } }; -template +template class LinearChainCRFGradOpKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/margin_rank_loss_op.cc b/paddle/fluid/operators/margin_rank_loss_op.cc index 47ed77cbfb4..2aaf8f74af3 100644 --- a/paddle/fluid/operators/margin_rank_loss_op.cc +++ b/paddle/fluid/operators/margin_rank_loss_op.cc @@ -181,7 +181,11 @@ REGISTER_OPERATOR(margin_rank_loss, ops::MarginRankLossGradMaker, ops::MarginRankLossGradMaker); REGISTER_OPERATOR(margin_rank_loss_grad, ops::MarginRankLossGradOp); -REGISTER_OP_CPU_KERNEL(margin_rank_loss, - ops::MarginRankLossKernel); -REGISTER_OP_CPU_KERNEL(margin_rank_loss_grad, - ops::MarginRankLossGradKernel); + +PD_REGISTER_STRUCT_KERNEL( + margin_rank_loss, CPU, ALL_LAYOUT, ops::MarginRankLossKernel, float) {} +PD_REGISTER_STRUCT_KERNEL(margin_rank_loss_grad, + CPU, + ALL_LAYOUT, + ops::MarginRankLossGradKernel, + float) {} diff --git a/paddle/fluid/operators/margin_rank_loss_op.cu b/paddle/fluid/operators/margin_rank_loss_op.cu index f672381ed7a..8c6c2ee055f 100644 --- a/paddle/fluid/operators/margin_rank_loss_op.cu +++ b/paddle/fluid/operators/margin_rank_loss_op.cu @@ -16,7 +16,10 @@ limitations under the License. */ namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(margin_rank_loss, - ops::MarginRankLossKernel); -REGISTER_OP_CUDA_KERNEL(margin_rank_loss_grad, - ops::MarginRankLossGradKernel); +PD_REGISTER_STRUCT_KERNEL( + margin_rank_loss, GPU, ALL_LAYOUT, ops::MarginRankLossKernel, float) {} +PD_REGISTER_STRUCT_KERNEL(margin_rank_loss_grad, + GPU, + ALL_LAYOUT, + ops::MarginRankLossGradKernel, + float) {} diff --git a/paddle/fluid/operators/margin_rank_loss_op.h b/paddle/fluid/operators/margin_rank_loss_op.h index d04af331fd1..49cbb1168f1 100644 --- a/paddle/fluid/operators/margin_rank_loss_op.h +++ b/paddle/fluid/operators/margin_rank_loss_op.h @@ -34,7 +34,7 @@ struct Heaviside { } }; -template +template class MarginRankLossKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { @@ -62,7 +62,7 @@ class MarginRankLossKernel : public framework::OpKernel { } }; -template +template class MarginRankLossGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { diff --git a/paddle/fluid/operators/modified_huber_loss_op.cc b/paddle/fluid/operators/modified_huber_loss_op.cc index e0e64bb0c26..b44c795b6e5 100644 --- a/paddle/fluid/operators/modified_huber_loss_op.cc +++ b/paddle/fluid/operators/modified_huber_loss_op.cc @@ -176,7 +176,11 @@ REGISTER_OPERATOR( ops::ModifiedHuberLossGradOpMaker); REGISTER_OPERATOR(modified_huber_loss_grad, ops::ModifiedHuberLossGradOp); -REGISTER_OP_CPU_KERNEL(modified_huber_loss, - ops::ModifiedHuberLossKernel); -REGISTER_OP_CPU_KERNEL(modified_huber_loss_grad, - ops::ModifiedHuberLossGradCPUKernel); +PD_REGISTER_STRUCT_KERNEL( + modified_huber_loss, CPU, ALL_LAYOUT, ops::ModifiedHuberLossKernel, float) { +} +PD_REGISTER_STRUCT_KERNEL(modified_huber_loss_grad, + CPU, + ALL_LAYOUT, + ops::ModifiedHuberLossGradCPUKernel, + float) {} diff --git a/paddle/fluid/operators/modified_huber_loss_op.cu b/paddle/fluid/operators/modified_huber_loss_op.cu index bd4451ebda4..f811b0ad9d6 100644 --- a/paddle/fluid/operators/modified_huber_loss_op.cu +++ b/paddle/fluid/operators/modified_huber_loss_op.cu @@ -39,7 +39,7 @@ struct ModifiedHuberLossBackward { } }; -template +template class ModifiedHuberLossGradGPUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { @@ -74,7 +74,12 @@ class ModifiedHuberLossGradGPUKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -REGISTER_OP_CUDA_KERNEL(modified_huber_loss, - ops::ModifiedHuberLossKernel); -REGISTER_OP_CUDA_KERNEL(modified_huber_loss_grad, - ops::ModifiedHuberLossGradGPUKernel); + +PD_REGISTER_STRUCT_KERNEL( + modified_huber_loss, GPU, ALL_LAYOUT, ops::ModifiedHuberLossKernel, float) { +} +PD_REGISTER_STRUCT_KERNEL(modified_huber_loss_grad, + GPU, + ALL_LAYOUT, + ops::ModifiedHuberLossGradGPUKernel, + float) {} diff --git a/paddle/fluid/operators/modified_huber_loss_op.h b/paddle/fluid/operators/modified_huber_loss_op.h index 62600ed7c69..571482ce475 100644 --- a/paddle/fluid/operators/modified_huber_loss_op.h +++ b/paddle/fluid/operators/modified_huber_loss_op.h @@ -52,7 +52,7 @@ struct ModifiedHuberLossForward { } }; -template +template class ModifiedHuberLossKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { @@ -79,7 +79,7 @@ class ModifiedHuberLossKernel : public framework::OpKernel { }; // CPU backward kernel -template +template class ModifiedHuberLossGradCPUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& context) const override { -- GitLab