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

Add logical objectFifo hoisting pass #679

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

jtuyls
Copy link
Collaborator

@jtuyls jtuyls commented Aug 15, 2024

Follow-up on #676, which blocks subsumption when operands are in the same scope. Hoists amdaie.logicalobjectfifo.from_memref ops as much as possible, which enables more subsumption opportunities.

@@ -213,6 +213,11 @@ def AMDAIEHoistForLoopAffineApply : Pass<"iree-amdaie-hoist-for-affine-apply"> {
let constructor = "mlir::iree_compiler::AMDAIE::createAMDAIEHoistForLoopAffineApplyPass()";
}

def AMDAIEHoistLogicalObjFifo : Pass<"iree-amdaie-hoist-logical-objectfifo"> {
let summary = "Hoist logical objectFifo operations to the scope of its operands.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let summary = "Hoist logical objectFifo operations to the scope of its operands.";
let summary = "Hoist logical objectFifo operations to the scope of a most nested operand, without hoisting through workgroup, controlcode, or func ops.";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it makes sense to not hoist through these ops because they're isolated from above (could you check that instead?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scrap that idea, they're not isolated from above

AMDAIE::LogicalObjectFifoFromMemrefOp op) {
Operation *parentOp = op;
while (parentOp) {
Operation *newParentOp = parentOp->getParentOp();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpret this as
"If the new parent is a proper ancestor of any operand, keep hoisting"
which seems like not what you want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If the new parent is a proper ancestor of any operand, keep hoisting"

No, then it breaks,

Operation *parentOp = getOperation();
IRRewriter rewriter(parentOp->getContext());
parentOp->walk([&](AMDAIE::LogicalObjectFifoFromMemrefOp op) {
(void)hoistLogicalObjFifoOp(rewriter, op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if walk enumerates all the ops it will visit before hand, I don't think so, so I think you actually visit all the hoisted ops twice (once after hoisting) here.

FWIW I find code that

  1. walk to find targets
  2. process targets

easier to grok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I think you actually visit all the hoisted ops twice (once after hoisting)

The hoisted ops will be inserted before the ancestor op, so should not be visited again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, you're right.

@jtuyls jtuyls force-pushed the hoist-logical-obj-fifo branch from 907b52a to 1e82b7d Compare August 26, 2024 14:41
@jtuyls jtuyls force-pushed the hoist-logical-obj-fifo branch from 1e82b7d to 53e7b1e Compare August 26, 2024 19:58
@jtuyls
Copy link
Collaborator Author

jtuyls commented Aug 26, 2024

@newling Could you help check the PR again?

Copy link
Contributor

@newling newling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Apologies for inserting noise with invalid concerns last time

Operation *parentOp = getOperation();
IRRewriter rewriter(parentOp->getContext());
parentOp->walk([&](AMDAIE::LogicalObjectFifoFromMemrefOp op) {
(void)hoistLogicalObjFifoOp(rewriter, op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, you're right.

@jtuyls jtuyls merged commit e68cbd2 into nod-ai:main Aug 27, 2024
6 checks passed
@jtuyls jtuyls deleted the hoist-logical-obj-fifo branch August 27, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants