This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add pattern to handle trivial shape_cast in SPIR-V
ClosedPublic

Authored by pzread on Jun 25 2023, 1:26 AM.

Details

Summary

Handle the trivial case of size-1 vector.shape_cast. The shape_cast is created when we drop the unit dims of 1 element vector.

Diff Detail

Event Timeline

pzread created this revision.Jun 25 2023, 1:26 AM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: kuhar. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
pzread updated this revision to Diff 534319.Jun 25 2023, 1:29 AM

Add more tests

pzread updated this revision to Diff 534320.Jun 25 2023, 1:35 AM

Refactor

pzread edited the summary of this revision. (Show Details)Jun 25 2023, 1:42 AM
pzread published this revision for review.Jun 26 2023, 10:25 AM
kuhar accepted this revision.Jun 26 2023, 1:28 PM

LGTM but I'm not very familiar with how the unrealized conversion casts are handled in the pipeline, so you may want to wait for a second review before submitting.

This revision is now accepted and ready to land.Jun 26 2023, 1:28 PM
dcaballe added inline comments.Jun 26 2023, 2:10 PM
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
63–64

Shouldn't this case have been handled by a canonicalization/folding patterns before the lowering to SPIRV? e.g., by vector::populateVectorShapeCastLoweringPatterns?

pzread added inline comments.Jun 26 2023, 2:24 PM
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
63–64

Currently IREE SPIRV pipeline doesn't have vector::populateVectorShapeCastLoweringPatterns to handle shape_cast. We can add that and it will also solve the problem.

I don't know which one is preferable. I'll let @antiagainst decide.

pzread marked an inline comment as not done.Jun 26 2023, 2:27 PM
antiagainst accepted this revision.Jun 26 2023, 2:39 PM
antiagainst added inline comments.
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
63–64

populateVectorShapeCastLoweringPatterns is more involved and can potentially generate quite a lot of data movement vector ops. It need more patterns to clean up everything for SPIR-V. It's hard to properly sequence it with all other vector patterns. So I'm fine to handle this special case directly when lowering to SPIR-V--it's pretty straightforward here.

(Some day we might need to take another look of how all those vector patterns are used in spirv https://github.com/openxla/iree/issues/11110; but that's a large effort to take on..)

66

We don't need this check anymore with dstType == srcType?

66

Actually ignore this. Misread it..

This revision was landed with ongoing or failed builds.Jun 26 2023, 4:10 PM
This revision was automatically updated to reflect the committed changes.

Oh, I didn't notice the windows build failed... But it seems to be due to an unrelated reason. I'll monitor the build status and revert if required.