Skip to content

Commit fcbf04e

Browse files
authored
[mlir][vector][nfc] Add clarification on "dim-1" bcast (#125425)
Adds a small note to VectorOps.td on what "dim-1" broadcast is. Also updates comments to consistently use quotes, i.e. * "dim-1" broadcasting instead of dim-1 broadcasting. This way it is clear that we are referring to "stretching" one of the trailing dims rather than e.g. broadcasting a dim at idx 1.
1 parent b88b6a2 commit fcbf04e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ def Vector_BroadcastOp :
373373

374374
The source operand is duplicated over all the missing leading dimensions
375375
and stretched over the trailing dimensions where the source has a non-equal
376-
dimension of 1. These rules imply that any scalar broadcast (k=0) to any
377-
shaped vector with the same element type is always legal.
376+
dimension of 1 (stretching a trailing dimension is also referred to as
377+
"dim-1" broadcasting). These rules imply that any scalar broadcast (k=0) to
378+
any shaped vector with the same element type is always legal.
378379

379380
Example:
380381

@@ -396,7 +397,7 @@ def Vector_BroadcastOp :
396397

397398
/// Broadcast `value` to a vector of `dstShape`, knowing that exactly the
398399
/// `broadcastedDims` dimensions in the dstShape are broadcasted.
399-
/// This requires (and asserts) that the broadcast is free of dim-1
400+
/// This requires (and asserts) that the broadcast is free of "dim-1"
400401
/// broadcasting.
401402
/// Since vector.broadcast only allows expanding leading dimensions, an extra
402403
/// vector.transpose may be inserted to make the broadcast possible.

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,7 @@ computeBroadcastedUnitDims(ArrayRef<int64_t> srcShape,
23952395
for (auto [s1, s2] :
23962396
llvm::zip_equal(srcShape, dstShape.drop_front(rankDiff))) {
23972397
if (s1 != s2) {
2398-
assert(s1 == 1 && "expected dim-1 broadcasting");
2398+
assert(s1 == 1 && "expected \"dim-1\" broadcasting");
23992399
res.insert(dstDim);
24002400
}
24012401
++dstDim;
@@ -2414,7 +2414,7 @@ llvm::SetVector<int64_t> BroadcastOp::computeBroadcastedUnitDims() {
24142414

24152415
/// Broadcast `value` to a vector of `dstShape`, knowing that exactly the
24162416
/// `broadcastedDims` dimensions in the dstShape are broadcasted.
2417-
/// This requires (and asserts) that the broadcast is free of dim-1
2417+
/// This requires (and asserts) that the broadcast is free of "dim-1"
24182418
/// broadcasting.
24192419
/// Since vector.broadcast only allows expanding leading dimensions, an extra
24202420
/// vector.transpose may be inserted to make the broadcast possible.
@@ -2500,10 +2500,10 @@ Value BroadcastOp::createOrFoldBroadcastOp(
25002500
// 3.c. Append the srcShape.
25012501
llvm::append_range(broadcastShape, srcVectorType.getShape());
25022502

2503-
// Ensure there are no dim-1 broadcasts.
2503+
// Ensure there are no "dim-1" broadcasts.
25042504
assert(::computeBroadcastedUnitDims(srcVectorType.getShape(), broadcastShape)
25052505
.empty() &&
2506-
"unexpected dim-1 broadcast");
2506+
"unexpected \"dim-1\" broadcast");
25072507

25082508
VectorType broadcastType = VectorType::get(broadcastShape, elementType);
25092509
assert(vector::isBroadcastableTo(value.getType(), broadcastType) ==

0 commit comments

Comments
 (0)