[Mlir-commits] [mlir] [mlir][linalg] Introduce transpose semantic to 'linalg.matmul' ops. (PR #104783)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 24 15:14:10 PDT 2024


================
@@ -1177,13 +1220,48 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
              << " dim(s) to match the number of loops";
 
     int64_t rank = linalgOp.getRank(&opOperand);
-    if (indexingMap.getNumResults() != rank)
+    // Check if matmulOp need broadcast.
+    if (matmulOp)
+      hasBroadcast = matmulOp.hasBroadcastSemantic(opIndex);
+
+    if (!hasBroadcast && indexingMap.getNumResults() != rank)
       return op->emitOpError("expected operand rank (")
              << rank << ") to match the result rank of indexing_map #"
              << opOperand.getOperandNumber() << " ("
              << indexingMap.getNumResults() << ")";
-  }
 
+    // For verification of broadcast/transpose, create a temporary broadcasted
+    // type and try to verify the constructed type from the provided types and
+    // indexing maps.
+    if (hasBroadcast) {
+      llvm::SmallVector<AffineMap, 3> defaultIndexingMaps;
+      matmulOp.getDefaultIndexingMaps(defaultIndexingMaps);
+
+      // Check for valid broadcast request.
+      SmallVector<AffineMap, 3> opIndexingMaps =
+          matmulOp.getIndexingMapsArray();
+      for (unsigned dim = 0; dim < opIndexingMaps[opIndex].getNumResults();
+           dim++) {
+        AffineExpr exp = opIndexingMaps[opIndex].getResult(dim);
+        // Invalid map if dim expr 'd2' not found.
+        if (!exp.isFunctionOfDim(2)) {
----------------
MaheshRavishankar wrote:

This isnt a general check. This needs to move out of this method.

https://github.com/llvm/llvm-project/pull/104783


More information about the Mlir-commits mailing list