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

Move Abs InferShape to phi #39762

Merged
merged 2 commits into from
Feb 21, 2022
Merged
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
19 changes: 8 additions & 11 deletions paddle/fluid/operators/abs_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/unary.h"
#ifdef PADDLE_WITH_MKLDNN
#include "paddle/fluid/platform/mkldnn_helper.h"
#endif
Expand All @@ -27,16 +30,6 @@ namespace operators {
class AbsOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;

void InferShape(framework::InferShapeContext* ctx) const override {
OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "abs");
OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "abs");

auto in_dims = ctx->GetInputDim("X");

ctx->SetOutputDim("Out", in_dims);
ctx->ShareLoD("X", /*->*/ "Out");
}
};

class AbsOpMaker : public framework::OpProtoAndCheckerMaker {
Expand Down Expand Up @@ -148,11 +141,15 @@ class AbsDoubleGradOp : public framework::OperatorWithKernel {
} // namespace operators
} // namespace paddle

DELCARE_INFER_SHAPE_FUNCTOR(abs, AbsInferShapeFunctor,
PT_INFER_META(phi::UnchangedInferMeta));

namespace ops = paddle::operators;

REGISTER_OPERATOR(abs, ops::AbsOp, ops::AbsOpMaker,
ops::AbsGradMaker<paddle::framework::OpDesc>,
ops::AbsGradMaker<paddle::imperative::OpBase>);
ops::AbsGradMaker<paddle::imperative::OpBase>,
AbsInferShapeFunctor);

REGISTER_OPERATOR(abs_grad, ops::AbsGradOp,
ops::AbsDoubleGradMaker<paddle::framework::OpDesc>,
Expand Down