[Mlir-commits] [mlir] 2fde26d - [mlir][Linalg][NFC] Make getReassociationMapForFoldingUnitDims a visible helper function
Nicolas Vasilache
llvmlistbot at llvm.org
Mon Jul 4 09:00:29 PDT 2022
Author: Nicolas Vasilache
Date: 2022-07-04T09:00:20-07:00
New Revision: 2fde26dfcabe6a8270d54569b970767b4773bc66
URL: https://github.com/llvm/llvm-project/commit/2fde26dfcabe6a8270d54569b970767b4773bc66
DIFF: https://github.com/llvm/llvm-project/commit/2fde26dfcabe6a8270d54569b970767b4773bc66.diff
LOG: [mlir][Linalg][NFC] Make getReassociationMapForFoldingUnitDims a visible helper function
Added:
Modified:
mlir/include/mlir/Dialect/Linalg/Utils/Utils.h
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
mlir/lib/Dialect/Linalg/Utils/Utils.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h b/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h
index 72b126e375b9..a68701b1b04a 100644
--- a/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h
+++ b/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h
@@ -143,6 +143,15 @@ GenericOp makeTransposeOp(OpBuilder &b, Location loc, Value inputTensor,
/// or vectorize.
GenericOp makeMemRefCopyOp(OpBuilder &b, Location loc, Value from, Value to);
+/// Get the reassociation maps to fold the result of a extract_slice (or source
+/// of a insert_slice) operation with given offsets, and sizes to its
+/// rank-reduced version. This is only done for the cases where the size is 1
+/// and offset is 0. Strictly speaking the offset 0 is not required in general,
+/// but non-zero offsets are not handled by SPIR-V backend at this point (and
+/// potentially cannot be handled).
+Optional<SmallVector<ReassociationIndices>>
+getReassociationMapForFoldingUnitDims(ArrayRef<OpFoldResult> mixedSizes);
+
//===----------------------------------------------------------------------===//
// Fusion / Tiling utilities
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp b/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
index e1e7ed76d23c..2ef7e074127d 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
@@ -455,34 +455,6 @@ struct ReplaceUnitExtents : public OpRewritePattern<GenericOp> {
};
} // namespace
-/// Get the reassociation maps to fold the result of a extract_slice (or source
-/// of a insert_slice) operation with given offsets, and sizes to its
-/// rank-reduced version. This is only done for the cases where the size is 1
-/// and offset is 0. Strictly speaking the offset 0 is not required in general,
-/// but non-zero offsets are not handled by SPIR-V backend at this point (and
-/// potentially cannot be handled).
-static Optional<SmallVector<ReassociationIndices>>
-getReassociationMapForFoldingUnitDims(ArrayRef<OpFoldResult> mixedSizes) {
- SmallVector<ReassociationIndices> reassociation;
- ReassociationIndices curr;
- for (const auto &it : llvm::enumerate(mixedSizes)) {
- auto dim = it.index();
- auto size = it.value();
- curr.push_back(dim);
- auto attr = size.dyn_cast<Attribute>();
- if (attr && attr.cast<IntegerAttr>().getInt() == 1)
- continue;
- reassociation.emplace_back(ReassociationIndices{});
- std::swap(reassociation.back(), curr);
- }
- // When the reassociations are not empty, then fold the remaining
- // unit-dimensions into the last dimension. If the reassociations so far is
- // empty, then leave it emtpy. This will fold everything to a rank-0 tensor.
- if (!curr.empty() && !reassociation.empty())
- reassociation.back().append(curr.begin(), curr.end());
- return reassociation;
-}
-
namespace {
/// Convert `extract_slice` operations to rank-reduced versions.
struct UseRankReducedExtractSliceOp
diff --git a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
index 86580111fe8f..a2ffc691a6f0 100644
--- a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
@@ -1008,5 +1008,33 @@ void addTileLoopIvsToIndexOpResults(OpBuilder &b, LinalgOp tiledOp,
}
}
+/// Get the reassociation maps to fold the result of a extract_slice (or source
+/// of a insert_slice) operation with given offsets, and sizes to its
+/// rank-reduced version. This is only done for the cases where the size is 1
+/// and offset is 0. Strictly speaking the offset 0 is not required in general,
+/// but non-zero offsets are not handled by SPIR-V backend at this point (and
+/// potentially cannot be handled).
+Optional<SmallVector<ReassociationIndices>>
+getReassociationMapForFoldingUnitDims(ArrayRef<OpFoldResult> mixedSizes) {
+ SmallVector<ReassociationIndices> reassociation;
+ ReassociationIndices curr;
+ for (const auto &it : llvm::enumerate(mixedSizes)) {
+ auto dim = it.index();
+ auto size = it.value();
+ curr.push_back(dim);
+ auto attr = size.dyn_cast<Attribute>();
+ if (attr && attr.cast<IntegerAttr>().getInt() == 1)
+ continue;
+ reassociation.emplace_back(ReassociationIndices{});
+ std::swap(reassociation.back(), curr);
+ }
+ // When the reassociations are not empty, then fold the remaining
+ // unit-dimensions into the last dimension. If the reassociations so far is
+ // empty, then leave it emtpy. This will fold everything to a rank-0 tensor.
+ if (!curr.empty() && !reassociation.empty())
+ reassociation.back().append(curr.begin(), curr.end());
+ return reassociation;
+}
+
} // namespace linalg
} // namespace mlir
More information about the Mlir-commits
mailing list