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

[CINN]Fix GatherOpPattern in pd_to_cinn_pass #63972

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions paddle/cinn/hlir/dialect/operator/transforms/pd_to_cinn_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,12 @@ class SigmoidOpPattern
: public pir::OpRewritePattern<paddle::dialect::SigmoidOp> {
public:
using pir::OpRewritePattern<paddle::dialect::SigmoidOp>::OpRewritePattern;
bool Match(paddle::dialect::SigmoidOp op) const override {
return !CompatibleInfo::IsDeniedForCinn(*op.operation());
}

bool MatchAndRewrite(paddle::dialect::SigmoidOp op,
pir::PatternRewriter &rewriter) const override {
void Rewrite(paddle::dialect::SigmoidOp op,
pir::PatternRewriter &rewriter) const override {
auto input_dtype = paddle::dialect::TransToPhiDataType(
op->operand_source(0)
.type()
Expand Down Expand Up @@ -976,19 +979,23 @@ class SigmoidOpPattern
}

rewriter.ReplaceAllUsesWith(op.result(0), div);

rewriter.EraseOp(op);

return true;
}
};
class GatherOpPattern
: public pir::OpRewritePattern<paddle::dialect::GatherOp> {
public:
using pir::OpRewritePattern<paddle::dialect::GatherOp>::OpRewritePattern;

bool MatchAndRewrite(paddle::dialect::GatherOp op,
pir::PatternRewriter &rewriter) const override {
bool Match(paddle::dialect::GatherOp op) const override {
const bool is_denied = CompatibleInfo::IsDeniedForCinn(*op.operation());
auto axis_gen_op = op->operand_source(2).defining_op();
auto full_op = axis_gen_op->dyn_cast<paddle::dialect::FullOp>();
return !is_denied && full_op;
}

void Rewrite(paddle::dialect::GatherOp op,
pir::PatternRewriter &rewriter) const override {
auto gather_op = op->dyn_cast<paddle::dialect::GatherOp>();
auto x = op.operand_source(0);
auto index = op->operand_source(1);
Expand All @@ -1015,7 +1022,6 @@ class GatherOpPattern
rewriter.Build<cinn::dialect::GatherOp>(x, index, axis)->result(0);
rewriter.ReplaceAllUsesWith(op->result(0), out);
rewriter.EraseOp(op);
return true;
}
};

Expand Down