[Mlir-commits] [mlir] [MLIR][Linalg] Introduce linalg.contract (PR #123618)

Andrzej Warzyński llvmlistbot at llvm.org
Wed Jan 29 00:01:13 PST 2025


================
@@ -680,6 +680,128 @@ def MatmulOp : LinalgStructuredBase_Op<"matmul", [
     }];
 }
 
+//===----------------------------------------------------------------------===//
+// Contract op.
+//===----------------------------------------------------------------------===//
+
+def ContractOp : LinalgStructuredBase_Op<"contract", [
+               AttrSizedOperandSegments,
+               LinalgContractionOpInterface]> {
+  let summary = [{
+    Perform a contraction on two inputs, accumulating into the third.
+  }];
+  let description = [{
+    The semantics of contracting inputs `A` and `B` on top of `C` to produce
+    output `D` is given by
+
+      `D[H] = (SUM_{(I ∪ J) \ H} A[I] * B[J]) + C[H]`
+
+    where `I`, `J`, and `H` are multi-indices, i.e. sequences/ordered sets of
+    dimension identifiers (meant to range over valid indices), corresponding to
----------------
banach-space wrote:

Currently, this seems to be mixing "dimension identifiers" and "indices" as one thing. I see what you meant, but it would be good to disambiguate. Here's my most basic suggestion:

```suggestion
    where `I`, `J`, and `H` are multi-dim-ids, i.e. sequences/ordered sets of
    dimension identifiers (meant to range over valid indices), corresponding to
```

How about simplifying further:

```suggestion
    where `I`, `J`, and `H` ordered sets of
    dimension identifiers (meant to range over valid indices), corresponding to
```
?

I guess, in plain Linalg terminology,  `I`, `J`, and `H`  would contain the result affine expressions from the provided indexing maps?

Now, given that there might be permutations, would these always be "ordered"?

Btw, please let me know if I am over-analysing this 😅 Sometimes less is more!

EDIT: I've just noticed some updates further down which really help clarify this. So this probably just needs making sure that consistent terminology is used.

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


More information about the Mlir-commits mailing list