[Mlir-commits] [mlir] [mlir] Add inferContractionDims util for indexing map inputs (PR #76081)
Quinn Dawkins
llvmlistbot at llvm.org
Thu Dec 21 05:58:06 PST 2023
================
@@ -201,11 +193,48 @@ findPermutationsIndexingOperand(LinalgOp linalgOp, OpOperand *opOperand,
return res;
}
+/// Given a `linalgOp` and one of its `opOperand`, returns the positions of the
+/// iterators of type `iter` that index the `opOperand` as a permutation.
+/// This is useful to infer various subcomputations on a given `linalgOp`.
+/// This is performed by looking up each result in the matching indexing map and
+/// determining whether:
+/// - It is a single AffineDimExpr.
+/// - It is the only result involving this AffineDimExpr.
+static llvm::SmallDenseSet<int64_t>
+findPermutationsIndexingOperand(LinalgOp linalgOp, OpOperand *opOperand,
+ utils::IteratorType iter) {
+ assert(linalgOp == opOperand->getOwner() && "expected linalgOp owner");
+ return findPermutationsIndexingOperandImpl(
+ linalgOp.getMatchingIndexingMap(opOperand),
+ linalgOp.getIteratorTypesArray(), iter);
+}
+
+static llvm::SmallDenseSet<int64_t>
+findPermutationsIndexingOperand(AffineMap indexingMap,
+ ArrayRef<utils::IteratorType> iterators,
+ utils::IteratorType iter) {
+ return findPermutationsIndexingOperandImpl(indexingMap, iterators, iter);
+}
+
namespace {
auto par = utils::IteratorType::parallel;
auto red = utils::IteratorType::reduction;
} // namespace
+/// Infer the iterator types from the init affine map. This looks at which dims
+/// are present in the map results, and returns an iterator types array with
+/// parallel types for dims that are present, and reduction types for dims that
+/// are not present.
+static ArrayRef<utils::IteratorType> inferIteratorsFromOutMap(AffineMap map) {
----------------
qedawkins wrote:
nit: Given that inferContractionDims is an API function, it might be nice to make this `FailureOr` and fail if not a projected permutation.
https://github.com/llvm/llvm-project/pull/76081
More information about the Mlir-commits
mailing list