[BugFix][Transform] Detect cross-thread WAW hazards - #2821
Conversation
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
📝 WalkthroughWalkthroughThreadSync conflict analysis now detects same-iteration cross-thread write/write hazards while preserving same-thread loop-carried behavior. CUDA regressions cover barrier insertion, disjoint and thread-private writes, bind-derived indices, and copy/fill ordering. ChangesThreadSync WAW analysis
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
26ce2ff to
bb4b86c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@testing/python/issue/test_tilelang_issue_2698.py`:
- Around line 16-29: Add a companion shared-copy kernel and CUDA regression test
alongside _copy_then_offset_fill and
test_copy_then_offset_fill_orders_cross_thread_writes that performs a
nonzero-offset T.clear after copying into shared memory, then copies back and
verifies the targeted slice is zero. Repeat the test across multiple executions
and compare against an expected tensor to preserve coverage of cross-thread
write ordering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f8f604aa-fe31-4302-af1e-53be6e838d8d
📒 Files selected for processing (3)
src/transform/thread_storage_sync.cctesting/python/issue/test_tilelang_issue_2698.pytesting/python/transform/test_tilelang_transform_thread_sync.py
| T.fill(a_shared[10:16], 99.0) | ||
| T.copy(a_shared, B) | ||
|
|
||
|
|
||
| @tilelang.testing.requires_cuda | ||
| def test_copy_then_offset_fill_orders_cross_thread_writes(): | ||
| a = torch.arange(16, device="cuda", dtype=torch.float32) | ||
| expected = a.clone() | ||
| expected[10:16] = 99.0 | ||
|
|
||
| for _ in range(10): | ||
| b = torch.empty_like(a) | ||
| _copy_then_offset_fill(a, b) | ||
| torch.testing.assert_close(b, expected, rtol=0, atol=0) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add the required offset-clear regression.
This reproducer covers T.fill only; Issue #2698 also requires a nonzero-offset T.clear after shared copy-in. Add a companion kernel/test that verifies the cleared slice is zero across repeated CUDA executions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@testing/python/issue/test_tilelang_issue_2698.py` around lines 16 - 29, Add a
companion shared-copy kernel and CUDA regression test alongside
_copy_then_offset_fill and test_copy_then_offset_fill_orders_cross_thread_writes
that performs a nonzero-offset T.clear after copying into shared memory, then
copies back and verifies the targeted slice is zero. Repeat the test across
multiple executions and compare against an expected tensor to preserve coverage
of cross-thread write ordering.
Model same-iteration shared-memory writes with distinct thread instances and rename per-thread constraint definitions on each side. Preserve the existing loop-carried WAW boundary while inserting barriers for offset write phases that may alias across threads. Co-authored-by: dingsg <shengge.ding@enflame-tech.com>
bb4b86c to
a3ffd44
Compare
Fixes #2698
Summary
ThreadSyncmodeled both sides of a same-iteration shared-memory WAW check with the same thread variable. That only tests same-thread overlap and misses aliases between different threads, such as one phase writingS[tx]and another writingS[tx + 10].Same-iteration WAW analysis now uses two thread instances, requires at least one thread dimension to differ, and renames each side's flat-Bind constraints independently. Barrier placement is owned by
ThreadSync, so the fix models the cross-thread conflict there without changing kernels or inserting unconditional barriers.Changes
ConstrSet::RenameFrom.Review Notes
Validation
testing/python/issue/test_tilelang_issue_thread_sync_cross_thread_waw.pypassed 10 consecutive iterations on NVIDIA A100.testing/python/issue/test_tilelang_issue_thread_sync_cross_thread_waw.pypassed 10 consecutive iterations on NVIDIA H100.clang-formatandgit diff --checkpassed.