This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add support for CallOp bufferization (10/n)
ClosedPublic

Authored by nicolasvasilache on Jun 24 2021, 1:48 PM.

Details

Summary

Cross function boundary bufferization support is added.
This is enabled by cross-function boundary alias analysis, for which the bufferization process is extended: it can now modify the BufferizationAliasInfo as new ops are introduced.

A number of simplifying assumptions are made:

  1. by default we bufferize to the most dynamic strided memref type, further memref::CastOp canonicalizations are expected to clean up the IR.
  2. in the current implementation, the stride information is always erased at function boundaries. A subsequent pass will be required to analyze the meet of all call ops to a function and decide whether more static buffer types can be used. This will potentially clone functions when it is deemed profitable to do so (e.g. when the stride-1 dimension may vary).
  3. external function always bufferize to the most dynamic strided memref version. This may require special annotations for specifying that particular operands of top-level functions have contiguous buffer layout.

An alternative to point 3. would be to support tensor layout annotations, which is currently not supported in MLIR.

Diff Detail

Event Timeline

nicolasvasilache requested review of this revision.Jun 24 2021, 1:48 PM

Just putting this here for people to poke at while I a away for a few days.

nicolasvasilache retitled this revision from [mlir][Linalg] WIP - Add support for CallOp bufferization (10/n) to [mlir][Linalg] Add support for CallOp bufferization (10/n).Jun 29 2021, 5:06 AM
nicolasvasilache edited the summary of this revision. (Show Details)

Finish the impl.

nicolasvasilache edited the summary of this revision. (Show Details)Jun 29 2021, 5:52 AM
nicolasvasilache edited the summary of this revision. (Show Details)
ftynse accepted this revision.Jun 30 2021, 7:31 AM
ftynse added inline comments.
mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp
778

Could you document this behavior? It special-cases memref cast, but there may be other operations that create transitive aliases such as subview.

1250

Nit: do we even need this function? We could construct the type on the fly every time, it's not that expensive IMO.

1261

Nit: it only fails if the key is already in the map, which is checked above.

1429

Should this be failure?

1453
1502

This doesn't look necessary since we are on the exit fasttrack anyway.

This revision is now accepted and ready to land.Jun 30 2021, 7:31 AM
ftynse added inline comments.Jun 30 2021, 9:39 AM
mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp
1437

I suppose we want tests for user-visible error messages.

2190

Drop llvm::

2191–2192

This still doesn't guarantee funcOp is non-null, maybe add an assert.

2302

No need to continue here, there's nothing else in the loop.

nicolasvasilache marked 10 inline comments as done.

Address and rebase.

mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp
778

that's actually a remnant from before I made const BufferizationAliasInfo non-const in bufferize functions.
Dropped it, thanks for catching.

1250

will try to drop as part of the followup refactoring which only keeps the module pass.

1437

Added tests for some of these errors, will add more after step 12/n which refactors the passes and makes some changes that would affect additional tests.

1502

This gets hardened in step 12/n, leaving as is for now.

This revision was landed with ongoing or failed builds.Jul 1 2021, 3:41 AM
This revision was automatically updated to reflect the committed changes.