This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Add support for 0-D vectors to vector.insert/extract
ClosedPublic

Authored by dcaballe on Jun 10 2023, 11:43 PM.

Diff Detail

Event Timeline

dcaballe created this revision.Jun 10 2023, 11:43 PM
Herald added a project: Restricted Project. · View Herald Transcript
dcaballe requested review of this revision.Jun 10 2023, 11:43 PM
dcaballe updated this revision to Diff 530289.Jun 11 2023, 1:08 AM

Add more tets, doc examples and fix bug

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
704

Since your objective is to ultimately remove insertelement/extractelement, can you comment on the symmetry breaking property of this PR ?

vector.insert can now insert either a scalar or a 0-d vector into a larger vector but vector.extract must extract a scalar and cannot extract a 0-d vector.

I don't know yet how this plays in your full design but potential lack of symmetry between insert and extract ops has always been something to think about.

Thoughts?

dcaballe added inline comments.Jun 11 2023, 11:26 PM
mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
704

That's a good point! The main problem with vector.extract is that the extracted type is inferred from the source type, to the point that is not even represented in the assembly format of the instruction (e.g., vector.extract %0[3, 3, 3]: vector<4x8x16xf32>). We could change its assembly format but that would be a massive change so I would prefer not to go there unless it's strictly necessary. Perhaps we could restrict both vector.extract/insert to only scalars and use vector.broadcast, vector.shape_cast and other shape transforming ops to convert 0-D from/to scalars?

awarzynski added inline comments.Jun 12 2023, 12:02 PM
mlir/test/Dialect/Vector/invalid.mlir
244
Matt added a subscriber: Matt.Jun 14 2023, 3:39 PM
dcaballe updated this revision to Diff 538229.Jul 7 2023, 12:25 PM
dcaballe marked an inline comment as done.

Addressed feedback.

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
704

Let's keep it as is right now and revisit if there is any problem. The broadcast/shape_cast approach described above seems reasonable to me so it's not that we won't be able to represent all the cases in one way or another.

jsetoain added inline comments.Jul 10 2023, 11:50 AM
mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
698–699

Am I right to assume that support for values as $position shall come in a different patch?

dcaballe added inline comments.Jul 10 2023, 12:13 PM
mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
698–699

Yes, I have that almost done :)

Please, let me know if there are any other comments. Otherwise, this should be ready to go.

This revision is now accepted and ready to land.Jul 11 2023, 12:59 AM
awarzynski accepted this revision.Jul 11 2023, 2:54 AM
awarzynski added inline comments.
mlir/test/Dialect/Vector/invalid.mlir
244

[nit] Could you add "expected"? For consistency with other diagnostics and also because that makes it easier for my brain to parse :)

This revision was landed with ongoing or failed builds.Jul 11 2023, 12:30 PM
This revision was automatically updated to reflect the committed changes.
dcaballe marked an inline comment as done.