[PATCH] D80181: [mlir][spirv] Add remaining cooperative matrix instructions.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 20:44:14 PDT 2020


rriddle added inline comments.


================
Comment at: mlir/lib/Dialect/SPIRV/SPIRVOps.cpp:2746
+
+static void print(spirv::CooperativeMatrixLengthNVOp coopMatrix,
+                  OpAsmPrinter &printer) {
----------------
ThomasRaoux wrote:
> rriddle wrote:
> > This looks like it should use the declarative format:
> > 
> > https://mlir.llvm.org/docs/OpDefinitions/#declarative-assembly-format
> River, I wasn't able to get a syntax working for this instruction as the type itself is an argument and is unrelated to the destination. Do yo have any suggestion to make it work?
If the type of the result is inferrable, you don't have to specify it. Inferable types are either via traits(e.g., SameOperands) or with buildable types(i.e. statically constructible like index, i32, etc.). In this case, the result type is SPV_Int32(i.e. just an alias i32) which is a buildable type. To get the same syntax, all you really need to do it seems is something like:

```
attr-dict `:` $type
```

(You would have seen this if you read the section that I sent you : https://mlir.llvm.org/docs/OpDefinitions/#type-inference)


================
Comment at: mlir/lib/Dialect/SPIRV/SPIRVOps.cpp:2756
+static ParseResult parseCooperativeMatrixMulAddNVOp(OpAsmParser &parser,
+                                                    OperationState &state) {
+  SmallVector<OpAsmParser::OperandType, 3> ops;
----------------
ThomasRaoux wrote:
> rriddle wrote:
> > Same here and a few others.
> Here also I couldn't get the automatic print/parser to work as I have an instruction 
> r = matmuladd a, b, c : type(a), type(b) -> type(r and c)
> I wasn't able to express the fact that c and r must be the same type. Is there a way to make it work? 
In https://mlir.llvm.org/docs/OpDefinitions/#type-inference, it lists several traits that are supported for listing type equality constraints. You can do simple equality using `AllTypesMatch<["c", "r"]>` where `r` and `c` are the names of the operands/results/etc. With that types can be inferred for all as long as one can be inferred. I would expect the following to work:

```
def SPV_CooperativeMatrixMulAddNVOp : SPV_Op<..., [..., AllTypesMatch<"c", "result">]> {
  ...
  let assemblyFormat = "operands `:` type($a), type($b) -> type($c)";
}

``` 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80181/new/

https://reviews.llvm.org/D80181





More information about the llvm-commits mailing list