@@ -696,27 +696,28 @@ def ContractOp : LinalgStructuredBase_Op<"contract", [
696696
697697 `D[H] = (SUM_{(I ∪ J) \ H} A[I] * B[J]) + C[H]`
698698
699- where `I`, `J`, and `H` are multi-indices, i.e. sequences/ordered sets of
700- dimension identifiers (meant to range over valid indices), corresponding to
701- the co-domains of the mandatory (projected permutation) `indexing_maps` of
702- `A`, `B` and `C`, respectively. `SUM_{dims}` means reduce over all valid
703- indices for the dimensions in the set `dims`.
699+ where `I`, `J`, and `H` are tuples of (pairwise distinct) dimension
700+ identifiers - meant to range over valid indices - corresponding to the
701+ results of the mandatory (projected permutation) `indexing_maps` for `A`,
702+ `B` and `C`. `SUM_{dims}` means reduce over all valid indices for the
703+ dimensions in the set `dims` (with `I`, `J`, and `K` treated as _sets_ of
704+ dim identifiers).
704705
705706 The iteration space consists of all dimensions in `I`, `J` and `H`, i.e. the
706707 domain of each of the `affine_map`s. Like for einsums, the iteration type of
707708 each dim is inferred and is either:
708709
709- - reduction: the dim occurs in (the multi- index of) `A` and `B` but not `C`.
710- Per the above semantics, these dims will be contracted, i.e. reduced over.
710+ - reduction: the dim is used to index into `A` and `B` but not `C`. Per the
711+ above semantics, these dims will be contracted, i.e. reduced over.
711712
712- - parallel: the dim occurs in `C` and at least one of `A` and `B`, and -
713- deriving from matmul terminology - is either an "M-like" dim (if in `A`
714- and `C`), an "N-like" dim (if in `B` and `C`) or a "batch"-dim (if in `A`,
715- `B`, and `C`).
713+ - parallel: the dim is used to index into `C` and at least one of `A` and
714+ `B`, and - deriving from matmul terminology - is either an "M-like" dim
715+ (if used on `A` and `C`), an "N-like" dim (if used on `B` and `C`) or a
716+ "batch"-dim (if used to index into `A`, `B`, and `C`).
716717
717718 For example, batch-matmul is given by `I = ⟨ b, m, k ⟩`, `J = ⟨ b, k, n ⟩`,
718719 `H = ⟨ b, m, n ⟩` (with `k` as a contracting reduction-dimension while `m`,
719- `n` and `b` are of parallel iteration-type) and gets represented as:
720+ `n` and `b` have parallel iteration-type) and gets represented as:
720721
721722 ```
722723 %D = linalg.contract
@@ -727,12 +728,11 @@ def ContractOp : LinalgStructuredBase_Op<"contract", [
727728 outs(%C: tensor<?x?x?xf32>) -> tensor<?x?x?xf32>
728729 ```
729730
730- Note that by permuting dims in the co-domains of the `affine_map`s arbitrary
731- transposes can be applied to the inputs and output. Similarly, arbitrary
732- broadcasts can be achieved through leaving out dims on either input operand
733- (these dims' inferred iter type will be parallel). For example, the
734- following is a variant of batch-matmul where a transposition is applied to
735- `A` while matrix `B` gets broadcasted along the batch dimension:
731+ Note that by permuting dims in the `affine_map`s' results, accesses to
732+ to the inputs and output can be arbitrarily transposed. Similarly, arbitrary
733+ broadcasts can be achieved through leaving out dims on either input operand.
734+ For example, the following is a variant of batch-matmul with a transposition
735+ applied to `A` while `B`'s 2D-matrix gets broadcasted along the batch dim:
736736
737737 ```
738738 linalg.contract
@@ -744,7 +744,7 @@ def ContractOp : LinalgStructuredBase_Op<"contract", [
744744 ```
745745
746746 Numeric casting is performed on the operands to the inner multiplication,
747- promoting them to the same data type as the accumulator/output.
747+ promoting/truncating them to the same data type as the accumulator/output.
748748
749749 TODO: Allow control over the combining/accumulating op and possibly the
750750 multiplication op.
@@ -756,6 +756,9 @@ def ContractOp : LinalgStructuredBase_Op<"contract", [
756756 AffineMapArrayAttr:$indexing_maps
757757 );
758758 let results = (outs Variadic<AnyShaped>:$result_tensors);
759+ // NB: The only reason this op has a region - and it get populated at op build
760+ // time - is that currently the LinalgOp interface exposes methods that
761+ // assume a relevant region is available to be queried at any time.
759762 let regions = (region SizedRegion<1>:$combiner);
760763
761764 let skipDefaultBuilders = 1;
0 commit comments