[mlir] [MLIR][Linalg] Introduce transpose/broadcast semantic to linalg.batch… (PR #130944)

Andrzej Warzyński llvmlistbot at llvm.org
Thu May 1 08:08:48 PDT 2025


================
@@ -690,34 +690,32 @@ def MatmulOp : LinalgStructuredBase_Op<"matmul", [
 
     Example Transpose:
     ```mlir
-    linalg.matmul indexing_maps = [
-                   affine_map<(d0, d1, d2) -> (d2, d0)>, // transpose
-                   affine_map<(d0, d1, d2) -> (d2, d1)>,
-                   affine_map<(d0, d1, d2) -> (d0, d1)>
-                   ]
-                   ins(%arg0, %arg1 : memref<5x3xf32>,memref<5x7xf32>)
-                   outs(%arg2: memref<3x7xf32>)
+    linalg.matmul
----------------
banach-space wrote:

We should make sure that all Linalg ops that allow broadcast/tranpose maps, define the corresponding logic consistently - ideally by repeating some relevant part of the docs. For example, from https://mlir.llvm.org/docs/Dialects/Linalg/#linalgcontract-linalgcontractop
> Note that by permuting dims in the affine_maps’ results, accesses to to the inputs and output can be arbitrarily transposed. Similarly, arbitrary broadcasts can be achieved through leaving out dims on either input operand. For example, the following is a variant of batch-matmul with a transposition applied to A while B’s 2D-matrix gets broadcasted along the batch dim:

If any of the Ops diverges from this, it should be clearly documented. Does `linalg.batch_reduce_matmul` differ from `linalg.contract`?

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


More information about the Mlir-commits mailing list