Skip to content

Commit 4d7babc

Browse files
committed
[mlir][vector][nfc] Add clarification on "dim-1" bcast
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 3e5640b commit 4d7babc

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
@@ -2355,7 +2355,7 @@ computeBroadcastedUnitDims(ArrayRef<int64_t> srcShape,
23552355
for (auto [s1, s2] :
23562356
llvm::zip_equal(srcShape, dstShape.drop_front(rankDiff))) {
23572357
if (s1 != s2) {
2358-
assert(s1 == 1 && "expected dim-1 broadcasting");
2358+
assert(s1 == 1 && "expected \"dim-1\" broadcasting");
23592359
res.insert(dstDim);
23602360
}
23612361
++dstDim;
@@ -2374,7 +2374,7 @@ llvm::SetVector<int64_t> BroadcastOp::computeBroadcastedUnitDims() {
23742374

23752375
/// Broadcast `value` to a vector of `dstShape`, knowing that exactly the
23762376
/// `broadcastedDims` dimensions in the dstShape are broadcasted.
2377-
/// This requires (and asserts) that the broadcast is free of dim-1
2377+
/// This requires (and asserts) that the broadcast is free of "dim-1"
23782378
/// broadcasting.
23792379
/// Since vector.broadcast only allows expanding leading dimensions, an extra
23802380
/// vector.transpose may be inserted to make the broadcast possible.
@@ -2460,10 +2460,10 @@ Value BroadcastOp::createOrFoldBroadcastOp(
24602460
// 3.c. Append the srcShape.
24612461
llvm::append_range(broadcastShape, srcVectorType.getShape());
24622462

2463-
// Ensure there are no dim-1 broadcasts.
2463+
// Ensure there are no "dim-1" broadcasts.
24642464
assert(::computeBroadcastedUnitDims(srcVectorType.getShape(), broadcastShape)
24652465
.empty() &&
2466-
"unexpected dim-1 broadcast");
2466+
"unexpected \"dim-1\" broadcast");
24672467

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

0 commit comments

Comments
 (0)