-
Notifications
You must be signed in to change notification settings - Fork 675
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
[Codegen] Fix use after erase bug in optimize-tensor-extract-slices #19460
Conversation
continue; | ||
} | ||
bool changed = true; | ||
while (changed) { |
There was a problem hiding this comment.
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)
compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/OptimizeTensorInsertExtractSlices.cpp
Outdated
Show resolved
Hide resolved
bool changed = true; | ||
while (changed) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
134d313
to
662d3cc
Compare
Can we merge this? I want it for some tests in Sharktank. |
I see it introduces a regression in the performance of SDXL. |
662d3cc
to
cb27811
Compare
Signed-off-by: Groverkss <kunwarshaanjeetsingh.grover@amd.com>
Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
cb27811
to
7d77832
Compare
Yeah, looking into it |
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.