-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][vector] Restrict vector.insert/vector.extract to disallow 0-d vectors #121458
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
Changes from 1 commit
efc29a7
c15e7dd
c62abf4
f1babc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1294,6 +1294,10 @@ struct UnrollTransferReadConversion | |
|
|
||
| /// Rewrite the op: Unpack one dimension. Can handle masks, out-of-bounds | ||
| /// accesses, and broadcasts and transposes in permutation maps. | ||
| /// | ||
| /// When unpacking rank-1 vectors (i.e. when the target rank is 0), replaces | ||
| /// `vector.transfer_read` with either `memref.load` or `tensor.extract` (for | ||
| /// MemRef and Tensor source, respectively). | ||
| LogicalResult matchAndRewrite(TransferReadOp xferOp, | ||
| PatternRewriter &rewriter) const override { | ||
| if (xferOp.getVectorType().getRank() <= options.targetRank) | ||
|
|
@@ -1324,6 +1328,8 @@ struct UnrollTransferReadConversion | |
| for (int64_t i = 0; i < dimSize; ++i) { | ||
| Value iv = rewriter.create<arith::ConstantIndexOp>(loc, i); | ||
|
|
||
| // FIXME: Rename this lambda - it does much more than just | ||
| // in-bounds-check generation. | ||
| vec = generateInBoundsCheck( | ||
| rewriter, xferOp, iv, unpackedDim(xferOp), TypeRange(vecType), | ||
| /*inBoundsCase=*/ | ||
|
|
@@ -1338,12 +1344,33 @@ struct UnrollTransferReadConversion | |
| insertionIndices.push_back(rewriter.getIndexAttr(i)); | ||
|
|
||
| auto inBoundsAttr = dropFirstElem(b, xferOp.getInBoundsAttr()); | ||
| auto newXferOp = b.create<vector::TransferReadOp>( | ||
| loc, newXferVecType, xferOp.getBase(), xferIndices, | ||
| AffineMapAttr::get(unpackedPermutationMap(b, xferOp)), | ||
| xferOp.getPadding(), Value(), inBoundsAttr); | ||
| maybeAssignMask(b, xferOp, newXferOp, i); | ||
| return b.create<vector::InsertOp>(loc, newXferOp, vec, | ||
|
|
||
| // A value that's read after rank-reducing the original | ||
| // vector.transfer_read Op. | ||
| Value unpackedReadRes; | ||
| if (newXferVecType.getRank() != 0) { | ||
| // Unpacking Vector that's rank > 2 | ||
| // (use vector.transfer_read to load a rank-reduced vector) | ||
| unpackedReadRes = b.create<vector::TransferReadOp>( | ||
| loc, newXferVecType, xferOp.getBase(), xferIndices, | ||
| AffineMapAttr::get(unpackedPermutationMap(b, xferOp)), | ||
| xferOp.getPadding(), Value(), inBoundsAttr); | ||
| maybeAssignMask(b, xferOp, | ||
| dyn_cast<vector::TransferReadOp>( | ||
| unpackedReadRes.getDefiningOp()), | ||
| i); | ||
| } else { | ||
| // Unpacking Vector that's rank == 1 | ||
| // (use memref.load/tensor.extract to load a scalar) | ||
| unpackedReadRes = dyn_cast<MemRefType>(xferOp.getBase().getType()) | ||
| ? b.create<memref::LoadOp>( | ||
| loc, xferOp.getBase(), xferIndices) | ||
| .getResult() | ||
| : b.create<tensor::ExtractOp>( | ||
| loc, xferOp.getBase(), xferIndices) | ||
| .getResult(); | ||
| } | ||
| return b.create<vector::InsertOp>(loc, unpackedReadRes, vec, | ||
|
||
| insertionIndices); | ||
| }, | ||
| /*outOfBoundsCase=*/ | ||
|
|
||
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.
It's a bit confusing when i read it together with vector.extract docs.
Can we do
n-D vector base vector (source for vector.extract, dest for vector.insert)
k-D position
(n-k)-D subvector, degenerates to scalar if k = n
it's a bit easier to follow then
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.
Sure. But let me use the naming scheme from #131602, so:
valueToStore+destforvector.insert,sourceforvector.extract.Let me know what you think!
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 don't think this was addressed, what i meant was to use same rank for same class of operands:
n-D vector --> source/dest
k-D position
(n-k)-D subvector (valueToStore, result vector), degenerates to a scalar if k = n.
I don't mind the naming scheme, but having consistent rank documentation is easier to read.
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 for clarifying, now I see what you meant. Could you check the latest revision?
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, that was a Git failure on my part 🤦🏻
Could you check this commit that I've just pushed?