Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register fluid kerenls to phi [part 10] #53034

Merged
merged 6 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ void DataTranferHelper::RunAndConstructOpFuncNode(
*(op_with_kernel->PhiKernelSignature()),
runtime_context,
*dev_ctx);
} else if (new_op_func_node.phi_kernel_->GetKernelRegisteredType() ==
phi::KernelRegisteredType::STRUCTURE) {
(*new_op_func_node.phi_kernel_)(&exec_ctx);
} else {
phi::KernelContext phi_kernel_context;
op_with_kernel->BuildPhiKernelContext(
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,7 @@ Scope* OperatorWithKernel::PrepareData(
expected_kernel_key.layout(),
expected_kernel_key.dtype());
}
} else if (in_def != nullptr &&
} else if (in_def != nullptr && // KernelRegisteredType is Function
in_def->backend != phi::Backend::ALL_BACKEND) {
auto tensor_backend = phi::TransToPhiBackend(tensor_in->place());
if ((in_def->backend != tensor_backend &&
Expand Down
18 changes: 12 additions & 6 deletions paddle/fluid/operators/sequence_ops/sequence_softmax_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ REGISTER_OPERATOR(
REGISTER_OPERATOR(sequence_softmax_grad,
ops::SequenceSoftmaxGradOp,
ops::SequenceSoftmaxGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL(sequence_softmax,
ops::SequenceSoftmaxKernel<phi::CPUContext, float>,
ops::SequenceSoftmaxKernel<phi::CPUContext, double>);
REGISTER_OP_CPU_KERNEL(sequence_softmax_grad,
ops::SequenceSoftmaxGradKernel<phi::CPUContext, float>,
ops::SequenceSoftmaxGradKernel<phi::CPUContext, double>);
PD_REGISTER_STRUCT_KERNEL(sequence_softmax,
CPU,
ALL_LAYOUT,
ops::SequenceSoftmaxKernel,
float,
double) {}
PD_REGISTER_STRUCT_KERNEL(sequence_softmax_grad,
CPU,
ALL_LAYOUT,
ops::SequenceSoftmaxGradKernel,
float,
double) {}
19 changes: 12 additions & 7 deletions paddle/fluid/operators/sequence_ops/sequence_softmax_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,15 @@ struct SequenceSoftmaxGradFunctor<phi::GPUContext, T> {
} // namespace paddle

namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(sequence_softmax,
ops::SequenceSoftmaxKernel<phi::GPUContext, float>,
ops::SequenceSoftmaxKernel<phi::GPUContext, double>);
REGISTER_OP_CUDA_KERNEL(
sequence_softmax_grad,
ops::SequenceSoftmaxGradKernel<phi::GPUContext, float>,
ops::SequenceSoftmaxGradKernel<phi::GPUContext, double>);
PD_REGISTER_STRUCT_KERNEL(sequence_softmax,
GPU,
ALL_LAYOUT,
ops::SequenceSoftmaxKernel,
float,
double) {}
PD_REGISTER_STRUCT_KERNEL(sequence_softmax_grad,
GPU,
ALL_LAYOUT,
ops::SequenceSoftmaxGradKernel,
float,
double) {}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/sequence_ops/sequence_softmax_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct SequenceSoftmaxGradFunctor<phi::CPUContext, T> {
}
};

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceSoftmaxKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
Expand Down Expand Up @@ -130,7 +130,7 @@ class SequenceSoftmaxKernel : public framework::OpKernel<T> {
}
};

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceSoftmaxGradKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ REGISTER_OPERATOR(
ops::SequenceTopkAvgPoolGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_topk_avg_pooling_grad,
ops::SequenceTopkAvgPoolingGradOp);
REGISTER_OP_CPU_KERNEL(
sequence_topk_avg_pooling,
ops::SequenceTopkAvgPoolingKernel<phi::CPUContext, float>);
REGISTER_OP_CPU_KERNEL(
sequence_topk_avg_pooling_grad,
ops::SequenceTopkAvgPoolingGradKernel<phi::CPUContext, float>);
PD_REGISTER_STRUCT_KERNEL(sequence_topk_avg_pooling,
CPU,
ALL_LAYOUT,
ops::SequenceTopkAvgPoolingKernel,
float) {}
PD_REGISTER_STRUCT_KERNEL(sequence_topk_avg_pooling_grad,
CPU,
ALL_LAYOUT,
ops::SequenceTopkAvgPoolingGradKernel,
float) {}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void get_topk_pos(const T* data, int length, int k, int* pos) {
}
} // namespace details

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceTopkAvgPoolingKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& context) const override {
Expand Down Expand Up @@ -178,7 +178,7 @@ class SequenceTopkAvgPoolingKernel : public framework::OpKernel<T> {
}
};

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceTopkAvgPoolingGradKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& context) const override {
Expand Down
27 changes: 16 additions & 11 deletions paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@ REGISTER_OPERATOR(sequence_unpad,
REGISTER_OPERATOR(sequence_unpad_grad,
ops::SequenceUnpadGradOp,
ops::SequenceUnpadGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL(sequence_unpad,
ops::SequenceUnpadOpKernel<phi::CPUContext, float>,
ops::SequenceUnpadOpKernel<phi::CPUContext, double>,
ops::SequenceUnpadOpKernel<phi::CPUContext, int>,
ops::SequenceUnpadOpKernel<phi::CPUContext, int64_t>);
REGISTER_OP_CPU_KERNEL(
sequence_unpad_grad,
ops::SequenceUnpadGradOpKernel<phi::CPUContext, float>,
ops::SequenceUnpadGradOpKernel<phi::CPUContext, double>,
ops::SequenceUnpadGradOpKernel<phi::CPUContext, int>,
ops::SequenceUnpadGradOpKernel<phi::CPUContext, int64_t>);
PD_REGISTER_STRUCT_KERNEL(sequence_unpad,
CPU,
ALL_LAYOUT,
ops::SequenceUnpadOpKernel,
float,
double,
int,
int64_t) {}
PD_REGISTER_STRUCT_KERNEL(sequence_unpad_grad,
CPU,
ALL_LAYOUT,
ops::SequenceUnpadGradOpKernel,
float,
double,
int,
int64_t) {}
27 changes: 16 additions & 11 deletions paddle/fluid/operators/sequence_ops/sequence_unpad_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ limitations under the License. */
#include "paddle/fluid/operators/sequence_ops/sequence_unpad_op.h"

namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(sequence_unpad,
ops::SequenceUnpadOpKernel<phi::GPUContext, float>,
ops::SequenceUnpadOpKernel<phi::GPUContext, double>,
ops::SequenceUnpadOpKernel<phi::GPUContext, int>,
ops::SequenceUnpadOpKernel<phi::GPUContext, int64_t>);
REGISTER_OP_CUDA_KERNEL(
sequence_unpad_grad,
ops::SequenceUnpadGradOpKernel<phi::GPUContext, float>,
ops::SequenceUnpadGradOpKernel<phi::GPUContext, double>,
ops::SequenceUnpadGradOpKernel<phi::GPUContext, int>,
ops::SequenceUnpadGradOpKernel<phi::GPUContext, int64_t>);
PD_REGISTER_STRUCT_KERNEL(sequence_unpad,
GPU,
ALL_LAYOUT,
ops::SequenceUnpadOpKernel,
float,
double,
int,
int64_t) {}
PD_REGISTER_STRUCT_KERNEL(sequence_unpad_grad,
GPU,
ALL_LAYOUT,
ops::SequenceUnpadGradOpKernel,
float,
double,
int,
int64_t) {}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/sequence_ops/sequence_unpad_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace operators {
using LoDTensor = phi::DenseTensor;
using LoD = framework::LoD;

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceUnpadOpKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
Expand Down Expand Up @@ -81,7 +81,7 @@ class SequenceUnpadOpKernel : public framework::OpKernel<T> {
}
};

template <typename DeviceContext, typename T>
template <typename T, typename DeviceContext>
class SequenceUnpadGradOpKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ limitations under the License. */

namespace ops = paddle::operators;
REGISTER_OP_XPU_KERNEL(sequence_unpad,
ops::SequenceUnpadOpKernel<phi::XPUContext, float>);
ops::SequenceUnpadOpKernel<float, phi::XPUContext>);

#endif
22 changes: 13 additions & 9 deletions paddle/fluid/operators/share_data_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ Return a tensor $Out$ that shares data with the input tensor $X$ and without ten
} // namespace paddle

namespace ops = paddle::operators;
namespace plat = paddle::platform;
REGISTER_OPERATOR(
share_data,
ops::ShareDataOp,
ops::ShareDataOpMaker,
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>,
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OP_CPU_KERNEL(share_data,
ops::ShareDataKernel<bool>,
ops::ShareDataKernel<int>,
ops::ShareDataKernel<int8_t>,
ops::ShareDataKernel<uint8_t>,
ops::ShareDataKernel<paddle::platform::float16>,
ops::ShareDataKernel<int64_t>,
ops::ShareDataKernel<float>,
ops::ShareDataKernel<double>)
PD_REGISTER_STRUCT_KERNEL(share_data,
CPU,
ALL_LAYOUT,
ops::ShareDataKernel,
bool,
int,
int8_t,
uint8_t,
int64_t,
float,
double,
plat::float16) {}
24 changes: 14 additions & 10 deletions paddle/fluid/operators/share_data_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ limitations under the License. */

#include "paddle/fluid/operators/share_data_op.h"

REGISTER_OP_CUDA_KERNEL(
share_data,
paddle::operators::ShareDataKernel<bool>,
paddle::operators::ShareDataKernel<int>,
paddle::operators::ShareDataKernel<int8_t>,
paddle::operators::ShareDataKernel<uint8_t>,
paddle::operators::ShareDataKernel<paddle::platform::float16>,
paddle::operators::ShareDataKernel<int64_t>,
paddle::operators::ShareDataKernel<float>,
paddle::operators::ShareDataKernel<double>);
namespace ops = paddle::operators;
namespace plat = paddle::platform;
PD_REGISTER_STRUCT_KERNEL(share_data,
GPU,
ALL_LAYOUT,
ops::ShareDataKernel,
bool,
int,
int8_t,
uint8_t,
int64_t,
float,
double,
plat::float16) {}
2 changes: 1 addition & 1 deletion paddle/fluid/operators/share_data_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License. */
namespace paddle {
namespace operators {

template <typename T>
template <typename T, typename DeviceContext>
class ShareDataKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
Expand Down
27 changes: 16 additions & 11 deletions paddle/fluid/operators/shuffle_batch_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,19 @@ REGISTER_OPERATOR(shuffle_batch,
ops::ShuffleBatchGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(shuffle_batch_grad, ops::ShuffleBatchOpGrad);

REGISTER_OP_CPU_KERNEL(shuffle_batch,
ops::ShuffleBatchKernel<float>,
ops::ShuffleBatchKernel<double>,
ops::ShuffleBatchKernel<int32_t>,
ops::ShuffleBatchKernel<int64_t>);

REGISTER_OP_CPU_KERNEL(shuffle_batch_grad,
ops::ShuffleBatchGradKernel<float>,
ops::ShuffleBatchGradKernel<double>,
ops::ShuffleBatchGradKernel<int32_t>,
ops::ShuffleBatchGradKernel<int64_t>);
PD_REGISTER_STRUCT_KERNEL(shuffle_batch,
CPU,
ALL_LAYOUT,
ops::ShuffleBatchKernel,
float,
double,
int32_t,
int64_t) {}
PD_REGISTER_STRUCT_KERNEL(shuffle_batch_grad,
CPU,
ALL_LAYOUT,
ops::ShuffleBatchGradKernel,
float,
double,
int32_t,
int64_t) {}
32 changes: 19 additions & 13 deletions paddle/fluid/operators/shuffle_batch_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct ReorderFunctor {
int64_t stride_;
};

template <typename T>
template <typename T, typename DeviceContext>
class ShuffleBatchCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
Expand Down Expand Up @@ -149,7 +149,7 @@ class ShuffleBatchCUDAKernel : public framework::OpKernel<T> {
}
};

template <typename T>
template <typename T, typename DeviceContext>
class ShuffleBatchGradCUDAKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &ctx) const override {
Expand Down Expand Up @@ -180,15 +180,21 @@ class ShuffleBatchGradCUDAKernel : public framework::OpKernel<T> {
} // namespace paddle

namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL(shuffle_batch,
ops::ShuffleBatchCUDAKernel<float>,
ops::ShuffleBatchCUDAKernel<double>,
ops::ShuffleBatchCUDAKernel<int32_t>,
ops::ShuffleBatchCUDAKernel<int64_t>);

REGISTER_OP_CUDA_KERNEL(shuffle_batch_grad,
ops::ShuffleBatchGradCUDAKernel<float>,
ops::ShuffleBatchGradCUDAKernel<double>,
ops::ShuffleBatchGradCUDAKernel<int32_t>,
ops::ShuffleBatchGradCUDAKernel<int64_t>);

PD_REGISTER_STRUCT_KERNEL(shuffle_batch,
GPU,
ALL_LAYOUT,
ops::ShuffleBatchCUDAKernel,
float,
double,
int32_t,
int64_t) {}
PD_REGISTER_STRUCT_KERNEL(shuffle_batch_grad,
GPU,
ALL_LAYOUT,
ops::ShuffleBatchGradCUDAKernel,
float,
double,
int32_t,
int64_t) {}
#endif
4 changes: 2 additions & 2 deletions paddle/fluid/operators/shuffle_batch_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace operators {
template <typename T>
using Vector = phi::Vector<T>;

template <typename T>
template <typename T, typename DeviceContext>
class ShuffleBatchKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &context) const override {
Expand Down Expand Up @@ -122,7 +122,7 @@ class ShuffleBatchKernel : public framework::OpKernel<T> {
}
};

template <typename T>
template <typename T, typename DeviceContext>
class ShuffleBatchGradKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext &context) const override {
Expand Down
Loading