Skip to content

[BugFix][CuTeDSL] Elect one grid-barrier leader per block - #3400

Merged
LeiWang1999 merged 1 commit into
tile-ai:mainfrom
adenzhou1350:codex/fix-grid-barrier-thread-leader
Oct 10, 2026
Merged

LeiWang1999 merged 1 commit into
tile-ai:mainfrom
adenzhou1350:codex/fix-grid-barrier-thread-leader

Conversation

@adenzhou1350

@adenzhou1350 adenzhou1350 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

sync_grid() currently selects every thread with tid.x == 0. With a 2D/3D block, multiple threads therefore publish the same block's arrival, allowing the grid barrier to release before another block has written its data.

Elect only physical thread (0, 0, 0) by combining all three thread coordinates. The counter/generation protocol, fences and cooperative launch remain unchanged.

The regression delays block 1 using a finite device-clock loop, then checks the cross-block result for 32, (32, 2), (32, 1, 2) and (16, 2, 2) threads, including repeated barrier reuse.

Validation on RTX 5090, Python 3.12, Torch 2.11.0+cu130 and CuTeDSL 4.7.0:

  • Actual proposed test file, native CuTeDSL compilation and cooperative GPU launch: baseline 1 passed / 1 failed with -x (2D result [1, 3] instead of [3, 3]); fixed helper 4 passed, repeated in a second fresh process.
  • Both arms used TileLang 0.1.15's native compiler/runtime; its unchanged grid_sync.py is byte-identical to main at 994b44e. The candidate selected only the changed native Python DSL helper; this is not a full current-main C++ rebuild.
  • Kernel caching was disabled for the final A/B to prevent a baseline cubin from being reused after changing the helper. The standalone test run retained two unregistered-marker warnings.
  • Repository-version Ruff 0.16.6 check/format and git diff --check pass.

With a normal source build and CuTeDSL installed:

TILELANG_DISABLE_CACHE=1 python -m pytest \
  testing/python/language/test_tilelang_language_cooperative_cutedsl.py -q

Found while investigating @dajiaohuang's #3386 report, but this is a separate multidimensional-thread bug. It does not resolve the concurrent-stream shared-state issue or make a performance claim. AI-assisted, with independent native reproduction.

Summary

  • sync_grid() now elects physical thread (0, 0, 0) as the sole grid-barrier arrival publisher for each block. The counter/generation protocol, fences, and cooperative launch remain unchanged.
  • Added a CuTeDSL regression test for four 2D and 3D thread configurations. The test delays one block, checks cross-block results, and repeats barrier use.

Validation

  • The reported test run passed all four configurations with the fix, in two fresh processes.
  • The baseline helper failed the 2D case: it produced [1, 3] instead of [3, 3].
  • Ruff check and format, and git diff --check, passed.
  • Validation used TileLang 0.1.15’s native compiler/runtime, not a full current-main C++ rebuild.
  • The test run reported two unregistered-marker warnings.
  • This change does not address the concurrent-stream shared-state issue and makes no performance claim.

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: tile-ai/tilelang/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a130257b-e294-4f29-af5b-7941b6c950ca

📥 Commits

Reviewing files that changed from the base of the PR and between 994b44e and 71bc243.

📒 Files selected for processing (2)
  • testing/python/language/test_tilelang_language_cooperative_cutedsl.py
  • tilelang/contrib/cutedsl/grid_sync.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The CuTeDSL grid synchronization barrier now uses all three thread coordinates to identify the block leader. A new CUDA test checks synchronization across two blocks for four thread configurations.

Changes

CuTeDSL grid synchronization

Layer / File(s) Summary
Multidimensional leader selection and test coverage
tilelang/contrib/cutedsl/grid_sync.py, testing/python/language/test_tilelang_language_cooperative_cutedsl.py
The barrier combines %tid.x, %tid.y, and %tid.z before checking for the block leader. The new test runs a two-block kernel with four thread configurations on supported CUDA devices and checks the results across eight executions.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 71bc2

No actionable merge-blocking issue remains from this review; the change is ready for normal merge checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: selecting one grid-barrier leader per block in CuTeDSL.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LeiWang1999

Copy link
Copy Markdown
Member

would you mind taking a look @lucifer1004 ?

@lucifer1004

Copy link
Copy Markdown
Collaborator

The PR is generally sound, but I don't know if it is the most appropriate place to put this test. What do you think @LeiWang1999

@LeiWang1999

Copy link
Copy Markdown
Member

I think testing/python/language/ is a reasonable place for this test: it exercises the runtime semantics of T.sync_grid() through the public API. merged:)

@LeiWang1999
LeiWang1999 merged commit 5a9bb1f into tile-ai:main Oct 10, 2026
3 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.

3 participants