Skip to content

[Enhancement] Add missing fence_barrier_init primitive after mbarrier init - #1121

Merged
LeiWang1999 merged 2 commits into
tile-ai:mainfrom
chengyupku:main
Oct 27, 2025
Merged

LeiWang1999 merged 2 commits into
tile-ai:mainfrom
chengyupku:main

Conversation

@chengyupku

@chengyupku chengyupku commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor

This pull request introduces improvements to CUDA barrier synchronization primitives and their usage in the codebase, particularly to enhance memory visibility and synchronization across warps and clusters. The most important changes are grouped below:

CUDA Barrier Synchronization Enhancements

  • Added a new device function fence_barrier_init in barrier.h to issue the fence.mbarrier_init.release.cluster PTX instruction, improving memory barrier initialization and visibility across clusters.
  • Updated the lowering pass in LowerHopperIntrin to insert a call to ptx_fence_barrier_init after initializing memory barriers, following best practices from FlashAttention for proper synchronization.

Operator Intrinsic Updates

  • Added a new tilelang intrinsic operator increase_descriptor_offset to builtin.h, supporting descriptor offset management in kernel code.

Summary by CodeRabbit

  • New Features
    • Enhanced CUDA barrier synchronization capabilities with improved initialization support for cluster operations.

@coderabbitai

coderabbitai Bot commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

These changes introduce GPU barrier initialization support for Hopper architecture. A new CUDA barrier initialization function is added to the barrier header and integrated into the lowering transformation to emit synchronization before shared memory storage operations.

Changes

Cohort / File(s) Change Summary
Barrier functionality enhancement
src/tl_templates/cuda/barrier.h, src/transform/lower_hopper_intrin.cc
Added new fence_barrier_init() function in CUDA barrier header that emits barrier init release for clusters; integrated corresponding ptx_fence_barrier_init memory fence operation into lowering transformation to synchronize before shared memory storage ops when barrier initialization is present.
Formatting
src/op/builtin.h
Added blank line before increase_descriptor_offset() declaration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

The changes consist of straightforward additions: a new utility function and a simple insertion point for synchronization. The modifications follow existing patterns and are homogeneous in nature (both related to barrier initialization).

Possibly related PRs

  • tile-ai/tilelang#744: Large barrier refactor that overlaps with these changes—both modify barrier header structure and barrier-related lowering transformations for Hopper support.

Suggested reviewers

  • LeiWang1999

Poem

🐰 A fence to bloom in clusters bright,
Barriers synced with release might,
Hopper's dance of mem and sync,
Ordered flows, just at the brink! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "[Enhancement] Add missing fence_barrier_init primitive after mbarrier init" is specific, concise, and directly aligned with the main changes in the changeset. The title accurately describes the primary enhancement: the addition of a new fence_barrier_init device function in barrier.h and its integration into the lowering pass via ptx_fence_barrier_init in lower_hopper_intrin.cc. The title clearly communicates the key functionality being added without vague terminology, and a developer scanning commit history would immediately understand this PR introduces a new CUDA barrier synchronization primitive and its integration point. While the changeset includes a minor formatting change in builtin.h, the title appropriately focuses on the substantial enhancement that represents the core purpose of this PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/op/builtin.h (1)

15-21: Relocate the misplaced documentation comment.

This documentation block describes ptx_fence_barrier_init() but is placed before the namespace declaration. It should be moved to lines 207-212, immediately before the actual function declaration.

Apply this diff to relocate the comment:

-/*!
- * \brief Create the TVM intrinsic that initializes a PTX fence barrier.
- *
- * Initializes a PTX fence-style barrier used to coordinate asynchronous memory
- * operations (for example, TMA/TMA_STORE). Returns the Op representing this
- * intrinsic for use in TIR lowering and code generation.
- *
- */
 namespace tvm {

And add it before the function declaration:

+/*!
+ * \brief Create the TVM intrinsic that initializes a PTX fence barrier.
+ *
+ * Initializes a PTX fence-style barrier used to coordinate asynchronous memory
+ * operations (for example, TMA/TMA_STORE). Returns the Op representing this
+ * intrinsic for use in TIR lowering and code generation.
+ */
 const Op &ptx_fence_barrier_init();
🧹 Nitpick comments (1)
src/transform/lower_hopper_intrin.cc (1)

86-95: Op is properly registered; comment formatting remains optional.

The verification confirms that ptx_fence_barrier_init() is correctly registered via TIR_DEFINE_TL_BUILTIN in src/op/builtin.cc and properly declared in src/op/builtin.h. The fence insertion logic is sound and follows FlashAttention best practices.

The comment formatting suggestion remains optional but valid if you prefer improved readability:

-            // Note from FlashAttention:
-            // Helps with visibility of barrier init operations across warps /
-            // cta / cluster Available as a separate function so as to batch
-            // inits across barriers and fence once Note : It must be composed
-            // with an appropriate sync instruction with the right scope to
-            // ensure visibility eg. __syncthreads() or a cluster_arrive() +
-            // cluster_wait()
+            // Note from FlashAttention:
+            // Helps with visibility of barrier init operations across warps,
+            // CTA, and cluster. Available as a separate function so as to
+            // batch inits across barriers and fence once.
+            // Note: It must be composed with an appropriate sync instruction
+            // with the right scope to ensure visibility (e.g., __syncthreads()
+            // or cluster_arrive() + cluster_wait()).
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65c4711 and 483e3c0.

📒 Files selected for processing (3)
  • src/op/builtin.h (1 hunks)
  • src/tl_templates/cuda/barrier.h (1 hunks)
  • src/transform/lower_hopper_intrin.cc (1 hunks)
🔇 Additional comments (2)
src/op/builtin.h (1)

506-507: LGTM!

The blank line improves visual separation between intrinsic declarations.

src/tl_templates/cuda/barrier.h (1)

136-138: PTX instruction syntax verified as correct.

The instruction syntax fence.mbarrier_init.release.cluster is correct for sm_90+. The code in fence_barrier_init() matches the official NVIDIA PTX ISA specification. No issues found.

@LeiWang1999

Copy link
Copy Markdown
Member

cc @cherichy

@LeiWang1999

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LeiWang1999
LeiWang1999 merged commit 17a6397 into tile-ai:main Oct 27, 2025
9 of 11 checks passed
RubiaCx pushed a commit to RubiaCx/tilelang that referenced this pull request Nov 24, 2025
…er init (tile-ai#1121)

* [Enhancement] Add missing  primitive after mbarrier init

* lint
@coderabbitai coderabbitai Bot mentioned this pull request Dec 18, 2025
1 task done
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.

2 participants