This is an archive of the discontinued LLVM Phabricator instance.

[mlir][TilingInterface] Add a method to generate scalar implementation of the op.
ClosedPublic

Authored by mravishankar on Jul 26 2022, 9:05 PM.

Details

Summary

While The tiling interface provides a mechanism for operations to be
tiled into tiled version of the op (or another op at the same level of
abstraction), the generateScalarImplementation method added here is
the "exit point" after all transformations have been done. Ops that
implement this method are expected to generate IR that are directly
lowerable to backend dialects like LLVM or SPIR-V dialects.

Diff Detail

Event Timeline

mravishankar created this revision.Jul 26 2022, 9:05 PM
mravishankar requested review of this revision.Jul 26 2022, 9:05 PM
ftynse added inline comments.Jul 27 2022, 5:43 AM
mlir/include/mlir/Interfaces/TilingInterface.td
177
179
mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp
33–41

Nit: makeComposedFoldedMultiResultAffineApply does this + folding (IIUC, it will avoid emitting the map if it is only a permutation), if desired.

47

ValueRange

60

Nit: I'd rather take the location of the terminator since we are emitting its equivalent.

61

Nit: it doesn't look necessary to use OpOperand, getOperands should do fine here.

mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
507

Ultra-nit.

516–518

Note that the switch of Range to use OpFoldResult has landed so you may need to materialize them here.

mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
66–78

Why this is a DAG? We should have a well-defined order for these.

mravishankar marked 4 inline comments as done.

Address comments.

mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp
33–41

I tried this, but I hit the same issue as what is being fixed by https://reviews.llvm.org/D130616 which I think has other issues. Left it as is for now. I am happy to fix this later on after your patch lands.

mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
516–518

Thanks! Btw, it would be really nice if scf.for could allow use of OpFoldResult for lb, ub, and step. I think this is one of the major switch points remaining.

ftynse accepted this revision.Jul 28 2022, 1:40 AM

LGTM as long as the CHECK-DAG is sorted out.

mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
516–518

This would require making the SCF dialect dependent on the Arithmetic dialect to materialize constants, which sounds unfortunate to me. Maybe we can have a helper function that builds the "for" separately in some util library.

This revision is now accepted and ready to land.Jul 28 2022, 1:40 AM
mravishankar added inline comments.Jul 28 2022, 9:14 AM
mlir/test/Interfaces/TilingInterface/lower-to-loops-using-interface.mlir
66–78

Force of habit. Will change to CHECK.

Use CHECK instead of CHECK-DAG.

This revision was landed with ongoing or failed builds.Jul 28 2022, 9:41 AM
This revision was automatically updated to reflect the committed changes.