Skip to content

fix: account for dynamic sizes while tiling #2

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 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,10 +1188,32 @@ mlir::scf::tileAndFuseProducerOfSlice(
clonedProducerOp->getResult(resultNumber));
if (failed(tileAndFuseResult))
return std::nullopt;
// Note: Do not delete the candidateSliceOp, since its passed in from the
// caller.
rewriter.replaceAllUsesWith(candidateSliceOp,
tileAndFuseResult->tiledValues[0]);

// Check if the types are the same. If possible insert a cast. Fail otherwise.
if (tileAndFuseResult->tiledValues[0].getType() !=
candidateSliceOp.getResult().getType()) {
auto tileAndFuseResultType =
cast<RankedTensorType>(tileAndFuseResult->tiledValues[0].getType());
auto candidateSliceOpType =
cast<RankedTensorType>(candidateSliceOp.getResult().getType());
// We can only cast if the tileAndFuseResultType has a static shape and
// canidateSliceOp has a dynamic shape. Might be expanded in the future.
if (!tileAndFuseResultType.hasStaticShape() ||
candidateSliceOpType.hasStaticShape()) {
return std::nullopt;
}

auto castOp = rewriter.create<tensor::CastOp>(
candidateSliceOp->getLoc(), candidateSliceOpType, tileAndFuseResult->tiledValues[0]);
// Note: Do not delete the candidateSliceOp, since its passed in from the
// caller.
rewriter.replaceAllUsesWith(candidateSliceOp, castOp);
} else {
// Note: Do not delete the candidateSliceOp, since its passed in from the
// caller.
rewriter.replaceAllUsesWith(candidateSliceOp,
tileAndFuseResult->tiledValues[0]);
}
rewriter.eraseOp(clonedCandidateSliceOp);
rewriter.eraseOp(clonedProducerOp);

Expand Down