Skip to content
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
7 changes: 7 additions & 0 deletions paddle/cinn/hlir/dialect/operator/ir/manual_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ void YieldStoreOp::Build(pir::Builder& builder,

void YieldStoreOp::VerifySig() {}

bool YieldStoreOp::InferSymbolicShape(
pir::ShapeConstraintIRAnalysis* shape_analysis) {
shape_analysis->SetShapeOrDataForValue(
result(0), shape_analysis->GetShapeOrDataForValue(operand_source(0)));
return true;
}

bool ConcatOp::InferSymbolicShape(
pir::ShapeConstraintIRAnalysis* shape_analysis) {
VLOG(4) << "Infer symbolic shape for cinn_op.concat";
Expand Down
6 changes: 5 additions & 1 deletion paddle/cinn/hlir/dialect/operator/ir/manual_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class IR_API FusionOp : public pir::Op<FusionOp> {

// YieldStoreOp represents a store operation for
// seperate local variable and ouptut
class IR_API YieldStoreOp : public pir::Op<YieldStoreOp> {
class IR_API YieldStoreOp
: public pir::Op<YieldStoreOp,
paddle::dialect::InferSymbolicShapeInterface> {
public:
using Op::Op;
static const char *name() { return "cinn_op.yield_store"; }
Expand All @@ -98,6 +100,8 @@ class IR_API YieldStoreOp : public pir::Op<YieldStoreOp> {
pir::Type output_type);

void VerifySig();

bool InferSymbolicShape(pir::ShapeConstraintIRAnalysis *shape_analysis);
};

class IR_API ConcatOp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,6 @@ class AddYieldStoreInFusionOpPattern
auto& shape_analysis =
pir::ShapeAnalysisManager::Instance().Get(op->GetParentProgram());
for (auto i = 0; i < op->num_operands(); ++i) {
if (auto reshape_op = op->operand_source(i)
.defining_op()
->dyn_cast<cinn::dialect::ReshapeOp>()) {
if (reshape_op.operand_source(0).defining_op() == nullptr) {
continue;
}
auto pre_name = reshape_op.operand_source(0).defining_op()->name();

if (op->operand_source(i).use_count() > 1) {
continue;
}

if ((pre_name != "cinn_op.reduce_sum") &&
(pre_name != "cinn_op.reduce_max")) {
auto store_op = rewriter.Build<cinn::dialect::YieldStoreOp>(
op->operand_source(i).defining_op()->operand_source(0),
op->operand_source(i).type());

if (shape_analysis.HasShapeOrDataForValue(reshape_op->result(0))) {
shape_analysis.SetShapeOrDataForValue(
store_op.result(0),
shape_analysis.GetShapeOrDataForValue(reshape_op->result(0)));
}

op->operand(i).set_source(store_op.result(0));
if (reshape_op->result(0).use_count() == 0) {
rewriter.EraseOp(reshape_op);
}
continue;
}
}

if (op->operand_source(i).use_count() == 1) {
continue;
}
Expand Down