Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup ConvertToStream to accomodate llvm/llvm-project@3f136f7 #19451

Merged

Conversation

MaheshRavishankar
Copy link
Contributor

@MaheshRavishankar MaheshRavishankar commented Dec 11, 2024

The upstream change llvm/llvm-project@3f136f7 allows ConvertToStream to better handle the 1:N type conversion, specifically the type conversion of a tensor<...> to !stream.resource<*>, index. Now instead of trying to work around builtin.unrealized_conversion_casts the conversion can get the converted values directly using the OneToNAdaptor and can also replace a tensor<..> directly with multiple values using the ConversionPatternRewriter::replaceOpWithMultiple.

These changes are required to drop the revert of llvm/llvm-project#116470 in the IREE ToM. The change drops these reverts as well.

Fixes #19448

@MaheshRavishankar MaheshRavishankar force-pushed the drop_integrate_reverts branch 4 times, most recently from f6907f1 to ae6330d Compare December 12, 2024 04:01
MaheshRavishankar added a commit that referenced this pull request Dec 12, 2024
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671

First two are carry over from previous integrate. It is being fixed in
#19451 . The last one is a new
failure.

---------

Signed-off-by: MaheshRavishankar <[email protected]>
@MaheshRavishankar
Copy link
Contributor Author

MaheshRavishankar commented Dec 13, 2024

Took some debugging but I think this is pretty close to the end state that we want here. @benvanik PTAL for any red flags you see. There is still some cleanup I need to do here to remove things that might be unnecessary.

@matthias-springer overall kudos on the changes to Dialect Conversion! At least in this case the changes you have made get things aligned better.

The only thing I will say though is the use of ArrayRef<ValueRange> in replaceOpWithMultiple is a bit of a footgun/pain. Both of these are reference objects, so you need to create something explicit to hold the values. So I had to do something like this https://github.com/iree-org/iree/pull/19451/files#diff-98ccf8581ef8de4f0a02f059079dbb1dbcbe3d2d398c69360cc5facc5795f608R83

@MaheshRavishankar MaheshRavishankar force-pushed the drop_integrate_reverts branch 2 times, most recently from 1f1a8cc to bb4fe70 Compare December 13, 2024 23:22
@MaheshRavishankar MaheshRavishankar changed the title [WIP] Drop revert of https://github.com/llvm/llvm-project/pull/116470 Cleanup ConvertToStream to accomodate llvm/llvm-project@3f136f7 Dec 14, 2024
@MaheshRavishankar MaheshRavishankar marked this pull request as ready for review December 14, 2024 01:28
@MaheshRavishankar MaheshRavishankar requested review from benvanik and removed request for benvanik December 14, 2024 01:28
@raikonenfnu raikonenfnu self-requested a review December 15, 2024 01:00
@matthias-springer
Copy link
Contributor

The only thing I will say though is the use of ArrayRef<ValueRange> in replaceOpWithMultiple is a bit of a footgun/pain. Both of these are reference objects, so you need to create something explicit to hold the values. So I had to do something like this https://github.com/iree-org/iree/pull/19451/files#diff-98ccf8581ef8de4f0a02f059079dbb1dbcbe3d2d398c69360cc5facc5795f608R83

I went through a few iterations for this API. No good solution so far, I had to write similar code... Originally, I wanted to have a single replaceOp function that supports 1:1 and 1:N, but that gets tricky because Value can be implicitly converted to ValueRange and ArrayRef<Value>. I gave up on that. Let me know if you have a better idea.

@MaheshRavishankar
Copy link
Contributor Author

The only thing I will say though is the use of ArrayRef<ValueRange> in replaceOpWithMultiple is a bit of a footgun/pain. Both of these are reference objects, so you need to create something explicit to hold the values. So I had to do something like this https://github.com/iree-org/iree/pull/19451/files#diff-98ccf8581ef8de4f0a02f059079dbb1dbcbe3d2d398c69360cc5facc5795f608R83

I went through a few iterations for this API. No good solution so far, I had to write similar code... Originally, I wanted to have a single replaceOp function that supports 1:1 and 1:N, but that gets tricky because Value can be implicitly converted to ValueRange and ArrayRef<Value>. I gave up on that. Let me know if you have a better idea.

You can have the API be a ArrayRef<SmallVector<Value>> . That will avoid the reference of reference.

@matthias-springer
Copy link
Contributor

Is there a particular reason why you said ArrayRef<SmallVector<Value>> and not SmallVector<ValueRange>? Is either one of those better?

@MaheshRavishankar
Copy link
Contributor Author

MaheshRavishankar commented Dec 17, 2024

Is there a particular reason why you said ArrayRef<SmallVector<Value>> and not SmallVector<ValueRange>? Is either one of those better?

SmallVector<ValueRange> is effectively array of pointers. So to populate that I will need to build a SmallVector<SmallVector<Value>> and then take reference for each of the inner SmallVector<Value> to build a SmallVector<ValueRange> . Also using SmallVector<ValueRange> would be passing it by value which is IMO a footgun cause you are passing an SmallVector of references by value and assuming that the underlying references stay valid for as long as it is used in the callee. If the callee for whatever reason decides to copy the SmallVector<ValueRange> it is just copying references to something that might very easily not be live anymore.

ArrayRef<SmallVector<Value>> is a reference to the outer SmallVector of SmallVector<SmallVector<Value>> . You are passing a reference to the container that owns all its data. That is much better I think and you can just populate the SmallVector<SmallVector<Value>> to start with and avoid creating new intermediate SmallVectors.

raikonenfnu added a commit that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@3f136f7
(#19479)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being
fixed in
#19451 . The last one is a from the
previous integrate.
The last one is a new error being tracked in
#19498

---------

Signed-off-by: Stanley Winata <[email protected]>
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being fixed in
iree-org#19451 . The last one is a from the previous integrate.
The last one is a new error being tracked in iree-org#19498

Signed-off-by: Stanley Winata <[email protected]>
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being fixed in
iree-org#19451 . The last one is a from the previous integrate.
The last one is a new error being tracked in iree-org#19498

Signed-off-by: Stanley Winata <[email protected]>
Signed-off-by: MaheshRavishankar <[email protected]>
…rsionPattern` and make the latter use `OneToNOpAdaptor`.

Signed-off-by: MaheshRavishankar <[email protected]>
This can be obtained directly from the adaptor.

Signed-off-by: MaheshRavishankar <[email protected]>
Signed-off-by: MaheshRavishankar <[email protected]>
Signed-off-by: MaheshRavishankar <[email protected]>
@MaheshRavishankar MaheshRavishankar merged commit 3509ead into iree-org:main Dec 17, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for dropping the local revert of https://github.com/llvm/llvm-project/pull/116470
3 participants