This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][LinAlg] Detensoring CF cost-model: look forward.
ClosedPublic

Authored by ergawy on Apr 14 2021, 2:13 AM.

Details

Summary

This patch extends the control-flow cost-model for detensoring by
implementing a forward-looking pass on block arguments that should be
detensored. This makes sure that if a (to-be-detensored) block argument
"escapes" its block through the terminator, then the successor arguments
are also detensored.

Diff Detail

Event Timeline

ergawy created this revision.Apr 14 2021, 2:13 AM
ergawy requested review of this revision.Apr 14 2021, 2:13 AM
ergawy added inline comments.Apr 14 2021, 2:15 AM
mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
495

For now, I ignored this part since it might complicate the algorithm by quite a bit. I prefer to integrate detensoring in IREE after patch first and derive further changes to the cost-model on a need-by-need basis. WDYT?

silvas added inline comments.Apr 14 2021, 11:32 AM
mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
474

You should be able to fold this into the worklist traversal above.

silvas added inline comments.Apr 14 2021, 11:39 AM
mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
474

To elaborate on that, think of this as finding connected components on the undirected graph where Value's are nodes, and an *undirected edge* exists between Value's (v1, v2) when:

  1. v2 is an operand of the defining op of v1 (or vice versa), and the defining op is a detensorable op
  2. v2 is a block argument and v1 is a successor arg that corresponds to it in a predecessor (or vice versa).

You only need one worklist traversal (which is a DFS) to discover this. The only thing that is slightly custom is that when you traverse enumerate the edges incident to a node, you need to check both situations 1. and 2. Note that the edge is undirected, but the IR data structures have a directedness (mathematically, the above definition is the same if we omit "or vice versa", but I kept it for clarity).

silvas added inline comments.Apr 14 2021, 11:42 AM
mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
495

I would prioritize integrating this into IREE.

If you structure the code as a DFS over the graph I described above, none of these additions should be much code or very complicated.

ergawy updated this revision to Diff 338010.Apr 16 2021, 12:35 AM

Handle review comments:

  • Fold the 2 phases of the cost-mode into one.
ergawy marked 3 inline comments as done.Apr 16 2021, 12:37 AM
ergawy added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
474

That's awesome. Thanks a lot! Folded the 2 phases into 1.

ergawy marked an inline comment as done.Apr 16 2021, 12:37 AM
silvas accepted this revision.Apr 19 2021, 2:21 PM

Awesome. Looks great!

mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
347

could you elaborate a bit more on 2.1 and 2.2? I liked the level of detail you had for 1.1 and 1.2

425

typo: FromElemntsOp

This revision is now accepted and ready to land.Apr 19 2021, 2:21 PM
ergawy updated this revision to Diff 338730.Apr 20 2021, 12:00 AM
ergawy marked 2 inline comments as done.

Add more detailed docs.

This revision was landed with ongoing or failed builds.Apr 20 2021, 12:02 AM
This revision was automatically updated to reflect the committed changes.