-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR][Vector] Implement transferXXPermutationLowering as MaskableOpRewritePattern #91987
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f7fc4b
[mlir][vector] Support MaskableOpRewritePattern of Op without a result.
nujaa b6a41bc
[MLIR][Vector] Implement transferXXPermutationLowering as MaskableOpR…
nujaa 1788c0c
Fixup: test less for negative tests.
nujaa c50ef19
Fixup MaskableOpRewritePattern when transfer_write has no result
nujaa 127b950
FixUp introduce #92526
nujaa c11da46
FixUp introduce #92526
nujaa 9e1536d
Fixup : fix comments.
nujaa 7c3cf86
fixup : MaskableOpRewritePattern and Value()
nujaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -90,14 +90,19 @@ namespace { | |||||
/// Note that an alternative is to transform it to linalg.transpose + | ||||||
/// vector.transfer_read to do the transpose in memory instead. | ||||||
struct TransferReadPermutationLowering | ||||||
: public OpRewritePattern<vector::TransferReadOp> { | ||||||
using OpRewritePattern::OpRewritePattern; | ||||||
: public MaskableOpRewritePattern<vector::TransferReadOp> { | ||||||
using MaskableOpRewritePattern::MaskableOpRewritePattern; | ||||||
|
||||||
LogicalResult matchAndRewrite(vector::TransferReadOp op, | ||||||
PatternRewriter &rewriter) const override { | ||||||
FailureOr<mlir::Value> | ||||||
matchAndRewriteMaskableOp(vector::TransferReadOp op, | ||||||
MaskingOpInterface maskOp, | ||||||
PatternRewriter &rewriter) const override { | ||||||
// TODO: support 0-d corner case. | ||||||
if (op.getTransferRank() == 0) | ||||||
return rewriter.notifyMatchFailure(op, "0-d corner case not supported"); | ||||||
// TODO: Support transfer_read inside MaskOp case. | ||||||
if (maskOp) | ||||||
return rewriter.notifyMatchFailure(op, "Masked case not supported"); | ||||||
|
||||||
SmallVector<unsigned> permutation; | ||||||
AffineMap map = op.getPermutationMap(); | ||||||
|
@@ -142,9 +147,9 @@ struct TransferReadPermutationLowering | |||||
|
||||||
// Transpose result of transfer_read. | ||||||
SmallVector<int64_t> transposePerm(permutation.begin(), permutation.end()); | ||||||
rewriter.replaceOpWithNewOp<vector::TransposeOp>(op, newRead, | ||||||
transposePerm); | ||||||
return success(); | ||||||
return rewriter | ||||||
.create<vector::TransposeOp>(op.getLoc(), newRead, transposePerm) | ||||||
.getResult(); | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -165,14 +170,19 @@ struct TransferReadPermutationLowering | |||||
/// %v = vector.transfer_write %tmp ... | ||||||
/// permutation_map: (d0, d1, d2, d3) -> (d2, d3) | ||||||
struct TransferWritePermutationLowering | ||||||
: public OpRewritePattern<vector::TransferWriteOp> { | ||||||
using OpRewritePattern::OpRewritePattern; | ||||||
: public MaskableOpRewritePattern<vector::TransferWriteOp> { | ||||||
using MaskableOpRewritePattern::MaskableOpRewritePattern; | ||||||
|
||||||
LogicalResult matchAndRewrite(vector::TransferWriteOp op, | ||||||
PatternRewriter &rewriter) const override { | ||||||
FailureOr<mlir::Value> | ||||||
matchAndRewriteMaskableOp(vector::TransferWriteOp op, | ||||||
MaskingOpInterface maskOp, | ||||||
PatternRewriter &rewriter) const override { | ||||||
// TODO: support 0-d corner case. | ||||||
if (op.getTransferRank() == 0) | ||||||
return rewriter.notifyMatchFailure(op, "0-d corner case not supported"); | ||||||
// TODO: Support transfer_write inside MaskOp case. | ||||||
if (maskOp) | ||||||
return rewriter.notifyMatchFailure(op, "Masked case not supported"); | ||||||
|
||||||
SmallVector<unsigned> permutation; | ||||||
AffineMap map = op.getPermutationMap(); | ||||||
|
@@ -207,11 +217,13 @@ struct TransferWritePermutationLowering | |||||
op.getLoc(), op.getVector(), indices); | ||||||
auto newMap = AffineMap::getMinorIdentityMap( | ||||||
map.getNumDims(), map.getNumResults(), rewriter.getContext()); | ||||||
rewriter.replaceOpWithNewOp<vector::TransferWriteOp>( | ||||||
op, newVec, op.getSource(), op.getIndices(), AffineMapAttr::get(newMap), | ||||||
op.getMask(), newInBoundsAttr); | ||||||
|
||||||
return success(); | ||||||
auto newWrite = rewriter.create<vector::TransferWriteOp>( | ||||||
op.getLoc(), newVec, op.getSource(), op.getIndices(), | ||||||
AffineMapAttr::get(newMap), op.getMask(), newInBoundsAttr); | ||||||
if (newWrite.hasPureTensorSemantics()) | ||||||
return newWrite.getResult(); | ||||||
// In memref case, MaskableOpRewritePattern cannot replaceOp with result. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return Value(); | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -231,14 +243,19 @@ struct TransferWritePermutationLowering | |||||
/// vector<1x8x16xf32> | ||||||
/// ``` | ||||||
struct TransferWriteNonPermutationLowering | ||||||
: public OpRewritePattern<vector::TransferWriteOp> { | ||||||
using OpRewritePattern::OpRewritePattern; | ||||||
: public MaskableOpRewritePattern<vector::TransferWriteOp> { | ||||||
using MaskableOpRewritePattern::MaskableOpRewritePattern; | ||||||
|
||||||
LogicalResult matchAndRewrite(vector::TransferWriteOp op, | ||||||
PatternRewriter &rewriter) const override { | ||||||
FailureOr<mlir::Value> | ||||||
matchAndRewriteMaskableOp(vector::TransferWriteOp op, | ||||||
MaskingOpInterface maskOp, | ||||||
PatternRewriter &rewriter) const override { | ||||||
// TODO: support 0-d corner case. | ||||||
if (op.getTransferRank() == 0) | ||||||
return rewriter.notifyMatchFailure(op, "0-d corner case not supported"); | ||||||
// TODO: Support transfer_write inside MaskOp case. | ||||||
if (maskOp) | ||||||
return rewriter.notifyMatchFailure(op, "Masked case not supported"); | ||||||
|
||||||
SmallVector<unsigned> permutation; | ||||||
AffineMap map = op.getPermutationMap(); | ||||||
|
@@ -285,10 +302,13 @@ struct TransferWriteNonPermutationLowering | |||||
newInBoundsValues.push_back(op.isDimInBounds(i)); | ||||||
} | ||||||
ArrayAttr newInBoundsAttr = rewriter.getBoolArrayAttr(newInBoundsValues); | ||||||
rewriter.replaceOpWithNewOp<vector::TransferWriteOp>( | ||||||
op, newVec, op.getSource(), op.getIndices(), AffineMapAttr::get(newMap), | ||||||
newMask, newInBoundsAttr); | ||||||
return success(); | ||||||
auto newWrite = rewriter.create<vector::TransferWriteOp>( | ||||||
op.getLoc(), newVec, op.getSource(), op.getIndices(), | ||||||
AffineMapAttr::get(newMap), newMask, newInBoundsAttr); | ||||||
if (newWrite.hasPureTensorSemantics()) | ||||||
return newWrite.getResult(); | ||||||
// In memref case, MaskableOpRewritePattern cannot replaceOp with result. | ||||||
nujaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return Value(); | ||||||
} | ||||||
}; | ||||||
|
||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IIUC, the only case that we are testing now is when "there's no return value" and "newOp is Value()". Hence I'm suggesting to replace
||
with&&
.Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry for late answer, I have been thinking about it while implementing and did not come up with a solution I liked. With the weekend fresh mind, Here is my point returning
Value()
means it did NOT fail. aka code updates happened but no value to give e.g. memref case.if we split cases :
Which can then be reduced to
As an additionnal point, technically,
matchAndRewriteMaskableOp
could return a ValueRange as replaceOp takes a ValueRange as input. replaceOp will assertrootOp->getNumResults() != newOp.size()
. And will allow to handle cases where ops have multiple results. But I suggest as part of a separate patch.