-
Notifications
You must be signed in to change notification settings - Fork 30
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
[AMDAIEFusePackIntoLoop] Handle case where there is no extract_slice #983
Conversation
fff5f23
to
ad87490
Compare
/// A utility function specific to this pass which, given a value, would | ||
/// traverse the def-chain till it either finds a tensor.extract_slice op or a | ||
/// BlockArgument. | ||
FailureOr<Operation *> getParentBeforeLoop(BlockArgument blkArg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explanations for this utility function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've inlined the function
FailureOr<Operation *> getParentBeforeLoop(BlockArgument blkArg) { | ||
Operation *parent = blkArg.getOwner()->getParentOp(); | ||
LoopLikeOpInterface loop = dyn_cast<LoopLikeOpInterface>(parent); | ||
if (!loop) return failure(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emit error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No failure here isn't necessary
operand = defOp->getOperand(0); | ||
// roll back through all the packs immediately preceding `operand`. | ||
while (operand.getDefiningOp() && | ||
isa<tensor::PackOp>(operand.getDefiningOp())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use while (isa_and_present<tensor::PackOp>(operand.getDefiningOp()))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Operation *defOp = operand.getDefiningOp(); | ||
if (!defOp) return failure(); | ||
tensor::ExtractSliceOp sliceOp = dyn_cast<tensor::ExtractSliceOp>(defOp); | ||
if (!sliceOp) return failure(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like commented above, you can simply check dyn_cast_if_present<tensor::ExtractSliceOp>(operand.getDefiningOp())
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
else { | ||
if (auto parent = | ||
dyn_cast_if_present<tensor::PackOp>(operand.getDefiningOp())) { | ||
Block *genericBlock = genericOp->getBlock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here you need to use else if
, and then add another else
in which adding some debug message and return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change to else-if, but the logic is correct I think so won't return and don't think debug print message is useful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically the else condition is not needed, but I was thinking it may good to add some debug message so people know why the pack is not fused into the loop in some specific situation. You can decide whether to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operand might not even come from a pack though, it could be anything...
ad87490
to
7aacd04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Just one more comment.
} | ||
|
||
// Case 2 outlined above. | ||
else if (auto blkArg = dyn_cast<BlockArgument>(sliceOp.getSource())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use if
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want it to enter both statements which might happen if this is if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would it enter both statements? After it enters the first it will return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it doesn't?
This is very similar to #976
When the AIE grid we're using is
m x n
where one or both ofm
andn
is1
, for a matmul we get pack ops that produce operands for matmuls directly. i.e. as opposed topack->extract_slice->matmul
we havepack->matmul
.TODO(newling) add a test and see if the pass can be simplified further.