[Mlir-commits] [mlir] [MLIR][SCF] Add an API to fuse consumer to a producer within scf loop (PR #88712)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon May 13 00:56:15 PDT 2024
================
@@ -469,6 +469,106 @@ struct UnPackOpTiling
return failure();
return tilingResult.value();
}
+
+ LogicalResult getIterationDomainTileFromOperandTile(
+ Operation *op, OpBuilder &b, unsigned operandNumber,
+ ArrayRef<OpFoldResult> offsets, ArrayRef<OpFoldResult> sizes,
+ SmallVectorImpl<OpFoldResult> &resultOffsets,
+ SmallVectorImpl<OpFoldResult> &resultSizes) const {
+ auto unPackOp = cast<UnPackOp>(op);
+ Location loc = unPackOp.getLoc();
+
+ int64_t numTiles = unPackOp.getInnerDimsPos().size();
+ auto destOffsets = offsets.drop_back(numTiles);
+ auto destSizes = sizes.drop_back(numTiles);
+ // The tiling is applied on interchanged dimensions. We have to undo the
+ // interchange to map sizes and offsets to the original input.
+ int64_t outputRank = unPackOp.getDestRank();
+ SmallVector<OpFoldResult> origOffsets(destOffsets.begin(),
+ destOffsets.end());
+ SmallVector<OpFoldResult> origSizes(destSizes.begin(), destSizes.end());
+ applyPermToRange(origOffsets, origSizes,
+ invertPermutationVector(unPackOp.getOuterDimsPerm()));
+
+ DenseMap<int64_t, OpFoldResult> dimAndTileMapping =
+ unPackOp.getDimAndTileMapping();
+
+ for (auto dim : llvm::seq<int64_t>(0, outputRank)) {
+ using AV = affine::AffineValueExpr;
+ affine::AffineBuilder ab(b, loc);
+ AffineExpr dim0, dim1, sym;
+ bindDims(b.getContext(), dim0, dim1);
+ bindSymbols(b.getContext(), sym);
+ if (dimAndTileMapping.count(dim)) {
+ // If the data dimension is tiled, the i-th index is the product of
+ // offset_i and tile_i, and the i-th size is the product of sizes_i and
+ // tile_i.
+ auto avOffset = AV(dim0).bind(origOffsets[dim]);
+ auto avSize = AV(dim0).bind(origSizes[dim]);
+ auto avTileSize = AV(sym).bind(dimAndTileMapping[dim]);
+ resultOffsets.push_back(ab.mul(avOffset, avTileSize));
+ resultSizes.push_back(ab.mul(avSize, avTileSize));
----------------
Yun-Fly wrote:
Do we need to check that full `innerDims` of `Unpack` are not tiled just like what `packOp` did in `generateResultTileValue` [here](https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp#L231-L233) at first?
Otherwise, this logic does not make sense because `Unpack` will actually generates partial tiles.
https://github.com/llvm/llvm-project/pull/88712
More information about the Mlir-commits
mailing list