This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Make patterns for folding tensor.empty optional.
ClosedPublic

Authored by pifon2a on Dec 5 2022, 4:32 AM.

Details

Summary

At the moment, they are a part of EmptyOp::getCanonicalizationPatterns. When
extract_slice(tensor.empty) is rewritten as a new tensor.empty, it could
happen that we end up with two tensor.empty ops, since the original
tensor.empty can have two users. After bufferization such cases result in two
allocations.

Diff Detail

Event Timeline

pifon2a created this revision.Dec 5 2022, 4:32 AM
pifon2a requested review of this revision.Dec 5 2022, 4:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2022, 4:32 AM
pifon2a updated this revision to Diff 480053.Dec 5 2022, 4:35 AM

Update cmake build.

springerm accepted this revision.Dec 5 2022, 4:51 AM
This revision is now accepted and ready to land.Dec 5 2022, 4:51 AM

This looks good to me. Do you mind holding off landing it till I can fix downstream users?

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
623

You shouldnt need this pattern also actually (just FYI, no need to do it here). This happens as part of handling dims using InferRankedShapedTypeResultDims interface.

Thanks @mravishankar. Sure, it can wait.

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
623

I'll clean it up later then.

Sorry for the delay and thanks for your patience. https://github.com/iree-org/iree/pull/11452 should see if there are any IREE issues. If that passes, I will stamp it here.

Sorry for the delay and thanks for your patience. https://github.com/iree-org/iree/pull/11452 should see if there are any IREE issues. If that passes, I will stamp it here.

Sorry, wrong link. This is the PR that tests this patch in IREE https://github.com/iree-org/iree/pull/11454

There are some failures downstream.... I will have to look into this, Ill try to take a look soon, but do you mind waiting till I resolve the issues first?

mravishankar requested changes to this revision.Dec 6 2022, 10:53 PM

Looking through this I think maybe some patterns are indeed canonicalization. The empty -> slice folding pattern indeed isnt a canonicalization. Same is true for the empty -> reshape patterns maybe (though it could go either way I think). Marking as request changes since I think the empty -> cast pattern is a legit canonicalization.

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
707

Does this need to be moved out... seems like a legitimate canonicalization to me (similar to other cast folding canonicalizations).

This revision now requires changes to proceed.Dec 6 2022, 10:53 PM
pifon2a marked an inline comment as done.Dec 6 2022, 11:03 PM

There are some failures downstream.... I will have to look into this, Ill try to take a look soon, but do you mind waiting till I resolve the issues first?

No worries, i can wait.

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
707

Agreed, will move it back in a couple of hours. Thanks!

pifon2a updated this revision to Diff 480953.Dec 7 2022, 9:29 AM
pifon2a marked an inline comment as done.

address the comments.

pifon2a updated this revision to Diff 480955.Dec 7 2022, 9:31 AM

remove dump-input.

hanchung added a comment.EditedDec 7 2022, 11:11 AM

Sorry for the delay and thanks for your patience. https://github.com/iree-org/iree/pull/11452 should see if there are any IREE issues. If that passes, I will stamp it here.

The PR has too many LLVM commit, so it could be broken by other commits. Let me create a PR that only contain this commit..

EDIT: https://github.com/iree-org/iree/pull/11460 tests the patch in IREE

Sorry for the delay and thanks for your patience. https://github.com/iree-org/iree/pull/11452 should see if there are any IREE issues. If that passes, I will stamp it here.

The PR has too many LLVM commit, so it could be broken by other commits. Let me create a PR that only contain this commit..

EDIT: https://github.com/iree-org/iree/pull/11460 tests the patch in IREE

@hanchung you are looking at the wrong PR ( I posted the wrong one by mistake). Here is the right one https://github.com/iree-org/iree/pull/11454 . That has only one commit

mravishankar accepted this revision.Dec 7 2022, 12:14 PM

Got this worked out in IREE (https://github.com/iree-org/iree/pull/11454/). Thanks for your patience. Looks good to me now!

This revision is now accepted and ready to land.Dec 7 2022, 12:14 PM
This revision was landed with ongoing or failed builds.Dec 7 2022, 2:02 PM
This revision was automatically updated to reflect the committed changes.