-
Notifications
You must be signed in to change notification settings - Fork 438
[ThreadSync] Use Z3 for constraint equivalence checking #1760
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
Changes from all commits
98bba23
60caa43
e29f549
16cbb64
7428b80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,8 +31,15 @@ def test_kernel(a: T.Tensor[(m,), dtype], b: T.Tensor[(m,), dtype]): | |||||||||||||
| def test_issue_1106(): | ||||||||||||||
| m = 200 | ||||||||||||||
| kernel = get_kernel(m) | ||||||||||||||
| assert "__syncthreads" not in kernel.get_kernel_source() | ||||||||||||||
| source = kernel.get_kernel_source() | ||||||||||||||
| # Ensure __syncthreads is not inside the for loop | ||||||||||||||
| for_start = source.find("for (int i = 0;") | ||||||||||||||
| for_end = source.find("__syncthreads") | ||||||||||||||
| assert for_end > for_start, "__syncthreads should be after the for loop, not inside it" | ||||||||||||||
| # Check that __syncthreads appears after the closing brace of the outer for loop | ||||||||||||||
| assert source[for_end - 4 : for_end - 2] == "}\n", "__syncthreads should not be inside any for loop" | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| if __name__ == "__main__": | ||||||||||||||
| tilelang.testing.main() | ||||||||||||||
| # tilelang.testing.main() | ||||||||||||||
| test_issue_1106() | ||||||||||||||
|
Comment on lines
43
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test harness is commented out. Commenting out If this is intentional for debugging, consider restoring the harness before merging. 🔧 Suggested fix if __name__ == "__main__":
- # tilelang.testing.main()
- test_issue_1106()
+ tilelang.testing.main()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
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.
String-based validation is fragile and lacks robustness checks.
Several concerns with the validation logic:
Missing not-found handling:
find()returns-1when the pattern isn't found. Iffor_startis-1andfor_endis a positive index, the assertionfor_end > for_startpasses incorrectly.Misleading variable name:
for_endactually stores the position of__syncthreads, not the end of the for loop.Brittle slice check:
source[for_end - 4 : for_end - 2] == "}\n"depends on exact whitespace/formatting and could break if code generation changes indentation or spacing.🛠️ Proposed fix with explicit validation
def test_issue_1106(): m = 200 kernel = get_kernel(m) source = kernel.get_kernel_source() # Ensure __syncthreads is not inside the for loop for_start = source.find("for (int i = 0;") - for_end = source.find("__syncthreads") - assert for_end > for_start, "__syncthreads should be after the for loop, not inside it" - # Check that __syncthreads appears after the closing brace of the outer for loop - assert source[for_end - 4 : for_end - 2] == "}\n", "__syncthreads should not be inside any for loop" + syncthreads_pos = source.find("__syncthreads") + assert for_start != -1, "Expected for loop not found in generated source" + assert syncthreads_pos != -1, "__syncthreads not found in generated source" + assert syncthreads_pos > for_start, "__syncthreads should be after the for loop, not inside it" + # Check that __syncthreads appears after the closing brace of the outer for loop + preceding_content = source[:syncthreads_pos].rstrip() + assert preceding_content.endswith("}"), "__syncthreads should not be inside any for loop"📝 Committable suggestion
🤖 Prompt for AI Agents