This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][GPU] Add canonicalizer for gpu.memcpy
ClosedPublic

Authored by arnab-oss on Apr 22 2022, 6:49 AM.

Details

Summary

Erase gpu.memcpy op when only uses of dest are
the memcpy op in question, its allocation and deallocation
ops.

Diff Detail

Event Timeline

arnab-oss created this revision.Apr 22 2022, 6:49 AM
arnab-oss requested review of this revision.Apr 22 2022, 6:49 AM
bondhugula added inline comments.Apr 22 2022, 6:58 AM
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1082–1095

Can this be made or use a helper method in the mlir Analysis library to the effect:

template <typename EffectTy>
bool mlir::hasSingleEffect(Operation *op, Value value) {
 ...
}

I see numerous use cases for something like all over.

if (hasSingleEffect<MemoryEffects::Allocate>())
 ...
arnab-oss updated this revision to Diff 426016.Apr 29 2022, 4:32 AM

Added hasSingleEffect() as a part of SideEffectInterface.

arnab-oss updated this revision to Diff 426017.Apr 29 2022, 4:33 AM

Fixed linting errors.

arnab-oss updated this revision to Diff 426019.Apr 29 2022, 4:38 AM
arnab-oss marked an inline comment as done.

Addressed comments by @bondhugula.

bondhugula added inline comments.Apr 29 2022, 5:09 PM
mlir/include/mlir/Interfaces/SideEffectInterfaceBase.td
90 ↗(On Diff #426019)

This is unclearly phrased.

-> `/// Returns true if EffectTy is the only effect that this operation has on value.`

?

94–104 ↗(On Diff #426019)

We shouldn't have so much C++ code in the .td file. Please define out of line.

csigg accepted this revision.May 2 2022, 10:43 PM

Looks good from my side but please address Uday's comments.

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1094–1096

Just a suggestion, feel free to ignore.

This revision is now accepted and ready to land.May 2 2022, 10:43 PM
arnab-oss updated this revision to Diff 427613.May 6 2022, 6:09 AM
arnab-oss marked an inline comment as done.

Addressed comments by @bondhugula.

bondhugula added a comment.EditedMay 8 2022, 10:12 PM

Looking mostly good. Some minor comments and a question to under the async dep related guard.

mlir/include/mlir/Interfaces/SideEffectInterfaces.h
251 ↗(On Diff #427613)

this operation -> op (in backticks)

Nit:
only has the ... -> has only the ..

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1090

Need a code comment here to understand the rationale.

mlir/lib/Interfaces/SideEffectInterfaces.cpp
95 ↗(On Diff #427613)

You don't need llvm::.

95 ↗(On Diff #427613)

Define this small vector below the check.

102 ↗(On Diff #427613)

Need a code comment here.

arnab-oss updated this revision to Diff 428926.May 12 2022, 6:32 AM
arnab-oss marked 4 inline comments as done.

Addressed comments by @bondhugula.

bondhugula accepted this revision.May 12 2022, 7:58 PM

LGTM

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1090–1092

single -> a single
dependency, -> dependency
produce -> produces
dependency, and does -> dependency and does

Addressed comments by @bondhugula.

arnab-oss updated this revision to Diff 429168.May 13 2022, 1:38 AM
arnab-oss marked 2 inline comments as done.

Rebased on latest master.

This revision was automatically updated to reflect the committed changes.