Skip to content

Commit 7151b93

Browse files
committed
fixup! fixup! [mlir][linalg] Enable scalable vectorization of linalg.unpack (WIP)
Fix pre-condition calculation
1 parent 4133218 commit 7151b93

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,24 +2114,45 @@ vectorizeDynamicLinalgOpPrecondition(linalg::LinalgOp op,
21142114
return success();
21152115
}
21162116

2117-
/// Need to check if the inner-tiles are static/constant.
2117+
//// This hook considers two cases:
2118+
/// (1) If the input-vector-sizes are empty, then the vector sizes will be
2119+
/// infered. This is only possible when all shapes are static.
2120+
/// (2) If the input-vector-sizes are non-empty (i.e. user provided), then
2121+
/// carry out basic sanity-checking.
21182122
static LogicalResult
21192123
vectorizeUnPackOpPrecondition(linalg::UnPackOp unpackOp,
21202124
ArrayRef<int64_t> inputVectorSizes) {
2125+
// If there are no input vector sizes and all shapes are static, there is
2126+
// nothing left to check.
2127+
if (inputVectorSizes.empty() && unpackOp.getDestType().hasStaticShape() &&
2128+
unpackOp.getSourceType().hasStaticShape())
2129+
return success();
21212130

2122-
if (llvm::any_of(unpackOp.getInnerTiles(), [](OpFoldResult res) {
2123-
return !getConstantIntValue(res).has_value();
2124-
})) {
2125-
LDBG("Inner-tiles must be constant: " << unpackOp << "\n");
2131+
// The input vector sizes must be equal to:
2132+
// * read-vector-rank + write-vector-rank
2133+
if (!inputVectorSizes.empty()) {
2134+
if (inputVectorSizes.size() !=
2135+
unpackOp.getDestRank() + unpackOp.getSourceRank()) {
2136+
LDBG("Incorrect number of input vector sizes");
2137+
return failure();
2138+
}
2139+
}
2140+
2141+
// Check the vector sizes for the write operation.
2142+
if (failed(vector::isValidMaskedInputVector(
2143+
unpackOp.getDestType().getShape(),
2144+
inputVectorSizes.take_back(unpackOp.getDestRank())))) {
2145+
LDBG("Incorrect number of input vector sizes");
21262146
return failure();
21272147
}
2128-
ArrayRef<int64_t> resultShape = unpackOp.getDestType().getShape();
2129-
bool satisfyEmptyCond = inputVectorSizes.empty() &&
2130-
unpackOp.getDestType().hasStaticShape() &&
2131-
unpackOp.getSourceType().hasStaticShape();
2132-
if (!satisfyEmptyCond &&
2133-
failed(vector::isValidMaskedInputVector(resultShape, inputVectorSizes)))
2148+
2149+
// Check the vector sizes for the read operation.
2150+
if (failed(vector::isValidMaskedInputVector(
2151+
unpackOp.getSourceType().getShape(),
2152+
inputVectorSizes.take_front(unpackOp.getSourceRank())))) {
2153+
LDBG("Incorrect number of input vector sizes");
21342154
return failure();
2155+
}
21352156

21362157
return success();
21372158
}

0 commit comments

Comments
 (0)