-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Bug] SplitHostDevice generates free var when var only exists in T.thread_binding of device function #16237
Comments
#16236 is a temporal fix that enforces free var in device function to have the same pointer as that in host function, but a formal fix requires the pass to eliminate the ill-formed output that contains free var |
cc @Lunderberg . I think we need to revisit #14918 Specifically, we should follow a principle that any stage should contain functions that are self-contained. One approach could be SplitHostDevice generate the function call with those extra information (of launch) and you then eliminate them when detecting it is a device only function. Right now the dependency on a function contains symbols that is in another function body can be quite frigile |
@jinhongyii The test case does not reproduce the error describe on the Also, the failure mode does not require
This is both the intention and current design of
Agreed. Depending on symbols defined in a different function body sounds incredibly fragile, and is certainly not the intended behavior. |
I've tracked down the root cause, it looks like the main cause is the use of
The solution is to remove the |
The buf reported in apache#16237 can be resolved by tracking variable usage in a thread extent.
And confirmed, when we visit the In the process of investigating, I also ran into a few additional limitations:
I've put together draft PR #16250 with a fix. Can you test it and verify that it resolves the error observed in LLVM codegen. |
The fix works for me. Thanks @Lunderberg |
The buf reported in apache#16237 can be resolved by tracking variable usage in a thread extent.
@jinhongyii Thank you for testing, and I've cleaned up the PR and marked it ready for review. |
* [TIR] In SplitHostDevice, check for variables in thread extents Otherwise, they would be undefined after being de-duplicated by `ConvertSSA`. * Revert #16236 The buf reported in #16237 can be resolved by tracking variable usage in a thread extent. * lint fixes * Update TIR well-formed checker for env thread SSA requirements Environment threads must reuse the same `tir::Var` across all `AttrStmt` instances in a `PrimFunc`, but must not reuse across separate `PrimFunc`s in an `IRModule`. * Update ConvertSSA to handle environment threads' SSA requirements * lint fix * Updated docstrings for VerifyWellFormed * Rely on script.Complete for read/writes Avoids issue in cortexm unit tests resulting from read/write annotations being present in the root block, followed by application of BindParams. * Typo fix * Added structural equal comparison in unit test
The long-term fix #16250 has landed, and so I believe this issue can be closed. |
…he#16250) * [TIR] In SplitHostDevice, check for variables in thread extents Otherwise, they would be undefined after being de-duplicated by `ConvertSSA`. * Revert apache#16236 The buf reported in apache#16237 can be resolved by tracking variable usage in a thread extent. * lint fixes * Update TIR well-formed checker for env thread SSA requirements Environment threads must reuse the same `tir::Var` across all `AttrStmt` instances in a `PrimFunc`, but must not reuse across separate `PrimFunc`s in an `IRModule`. * Update ConvertSSA to handle environment threads' SSA requirements * lint fix * Updated docstrings for VerifyWellFormed * Rely on script.Complete for read/writes Avoids issue in cortexm unit tests resulting from read/write annotations being present in the root block, followed by application of BindParams. * Typo fix * Added structural equal comparison in unit test
Expected behavior
SplitHostDevice generates no free var.
Actual behavior
SplitHostDevice generates free var cse_var_3 using the script below
Environment
TVM Unity branch
Steps to reproduce
cc: @Lunderberg
The text was updated successfully, but these errors were encountered: