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

[Codegen] Fix use after erase bug in optimize-tensor-extract-slices #19460

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

Groverkss
Copy link
Contributor

The loop here is iterating on arguments of a dead operation. This sometimes works if the operation decided to use the same memory for it's iter arguments, but is relying on undefined behavior. This patch restarts the check each time a new loop is created.

No tests for this one, because it sometimes works, depending on how the memory allocator allocates the operation.

continue;
}
bool changed = true;
while (changed) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will review more when not on a phone, but this feels like a usecase for do { ... } while(changed)

Comment on lines 87 to 88
bool changed = true;
while (changed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we bound this loop? I think the tript count shouldn't be more than the number of users? I want to make sure this doesn't accidentally become an infinite loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this. Lets add num_iters bounded by 10 or something that should be enough.

changed = false;
// Get all subset extraction uses of this iter_arg and try to hoist them
// out of the loop.
for (Operation *op : loopLike.getRegionIterArgs()[idx].getUsers()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever need to revisit the already processed users?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially not, but for now this is a WAR and number of iter args are expected to be small. So maybe we can ignore this for now.

Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis looks fine. If we can just bound the number of iterations that would be fine. I am not sure why we need to iterate till something doesnt change.

@MaheshRavishankar MaheshRavishankar force-pushed the fix-optimize-0d-bug branch 2 times, most recently from 134d313 to 662d3cc Compare January 2, 2025 21:57
@sogartar
Copy link
Contributor

sogartar commented Jan 3, 2025

Can we merge this? I want it for some tests in Sharktank.

@sogartar
Copy link
Contributor

sogartar commented Jan 3, 2025

I see it introduces a regression in the performance of SDXL.

Groverkss and others added 3 commits January 4, 2025 19:15
Signed-off-by: Groverkss <kunwarshaanjeetsingh.grover@amd.com>
Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
@MaheshRavishankar
Copy link
Contributor

I see it introduces a regression in the performance of SDXL.

Yeah, looking into it

@MaheshRavishankar MaheshRavishankar merged commit 9cb984f into iree-org:main Jan 6, 2025
37 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.

6 participants