[PATCH] D77067: [mlir][Linalg] Create a tool to generate named Linalg ops from a Tensor Comprehensions-like specification.
Alex Zinenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 11:59:51 PDT 2020
ftynse added inline comments.
================
Comment at: mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc:5
+
+// RUN: mlir-linalg-ods-gen %s -gen-ods-decl=1 -o %t \
+// RUN: && cat %S/../../include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td %t \
----------------
silvas wrote:
> ftynse wrote:
> > silvas wrote:
> > > silvas wrote:
> > > > nicolasvasilache wrote:
> > > > > ftynse wrote:
> > > > > > nicolasvasilache wrote:
> > > > > > > silvas wrote:
> > > > > > > > layering-wise would prefer to not test this here. If needed, we can add a separate test elsewhere that does this .td -> .inc file check. Strictly speaking what ends up in the .inc file is not really the concern of this component, only the contents of the .td file.
> > > > > > > >
> > > > > > > This was suggested by @ftynse to show the ODS is valid and how it connects to tblgen by mirroring this test: https://github.com/llvm/llvm-project/blob/master/mlir/test/mlir-tblgen/llvm-intrinsics.td#L11.
> > > > > > >
> > > > > > > I am fine either way, would just like consensus on this before reverting back to the previous state.
> > > > > > > Please reopen if you feel strongly about this.
> > > > > > > @ftynse any strong opinion?
> > > > > > I'm not sure I understand what is the concern here? The `ODS` check verifies the content of the produced .td file, _not_ the result of feeding that .td file to `mlir-tblgen -gen-op-defs`, which is indeed a separate concern. The `IMPL` check verifies the implementations of methods that are declared in the `.td` file and there is simply no other place where we can verify them.
> > > > > >
> > > > > > The staging here is:
> > > > > > 1a. mlir-linalg-ods-gen -gen-ods-decl %this_file% > ods.td
> > > > > > 1b. mlir-linalg-ods-gen -gen-impl %this_file% > impl.cc
> > > > > > 2a. mlir-tblgen -gen-op-decl ods.td > ods.h
> > > > > > 2b. mlir-tblgen -gen-op-decl ods.td > ods.cc
> > > > > > 3. include impl.cc and ods.cc into the implementation file; and ods.h into the header file.
> > > > > >
> > > > > > @nicolasvasilache the test you referenced also has `RUN` lines making sure `mlir-tblgen` can consume what the first stage produces. Consider adding them here as well. This could help detect cases of ODS syntax change (the simple syntactic test passes, but not the piping check). That's why there is only a trivial check to make sure FileCheck eats something.
> > > > > ```
> > > > > I'm not sure I understand what is the concern here?
> > > > > ...
> > > > > Consider adding them here as well.
> > > > > ```
> > > > >
> > > > > That's precisely what the concern was IIUC, piping through mlir-tblgen (see previous snapshot that I updated improperly https://reviews.llvm.org/D77067?id=254251).
> > > > >
> > > > > Restored that part of the test.
> > > > >
> > > > >
> > > > Ah, okay. Sorry for the confusion! When I saw C++ code I was assuming it was emitted by mlir-tblgen gen-op-def. But I see now that there is a mlir-linalg-tblgen -gen-impl that emits C++ as well. Sorry for the noise!!!
> > > Actually, when rereading I see that we do indeed invoke `mlir-tblgen -gen-op-decls`. I specifically object to the `TBLGEN` check prefixes here. I consider it a bug to do that (although i see the precendent in llvm-intrinsics.td, but I would have raised the same objection there), since it violates the layering: somebody updating mlir-tblgen shouldn't be able to break this test.
> > >
> > > Consider the implications of what is being checked now in this test...
> > >
> > > ```
> > > // TBLGEN-LABEL: linalg::batchmatmulOp declarations
> > > ^ could be broken by a change in a *comment* in the generated file :x
> > > // TBLGEN: class batchmatmulOpOperandAdaptor {
> > > ^ could be broken by adding a common base class to the operand adaptor classes, or a change in naming convention for the adaptor classes
> > > // TBLGEN: class batchmatmulOp : public Op<
> > > ^ could be changed by a change in base classes or naming convention.
> > > ```
> > >
> > > Note that none of those changes I've indicated would actually break any actual use of this code. So this test is just artificially constraining the implementation of mlir-tblgen for no real value. And even if you strip it down, all you would really be testing is `def batchmatmulOp` results in a `class batchmatmulOp` in the output, which is already tested in many places, such as, say, https://github.com/llvm/llvm-project/blob/master/mlir/test/mlir-tblgen/op-decl.td
> > >
> > > We need to be courteous to the maintainers of other components and give them the flexibility to adjust the implementations of their components.
> > I agree that this specific test is over-constraining for mlir-tblgen implementation. What I intended to test in intrinsicgen, and what I would like to see replicated here, is that the tablegen input produced by intrinsicgen, or my mlir-linalg-ods-gen, can be consumed by mlir-tblgen at all. Basically, we don't need to check for any output if we can find a way to check that mlir-tblgen exited with code 0 on the produced file. FileChecking the class name is just a workaround.
> >
> > If we don't do this check, we risk ending up in a situation where all of the existing tests pass (mlir-tblgen still generates expected C++ from ODS, and mlir-linalg-ods-gen still generates the strings expected by its test, just those strings are no longer valid ODS), but the pipeline fails. And given mlir-tblgen's tendency to assert or crash on improperly structured yet valid TableGen, it would be annoying to debug.
> Ah, ok. Then you can just remove the `| FileCheck`. The RUN line checks that the program has exit code 0, which won't be the case if mlir-tblgen runs into a syntax or processing error.
Perfect, let's do this!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77067/new/
https://reviews.llvm.org/D77067
More information about the llvm-commits
mailing list