Skip to content

[cudax] Implement cudax::level_synchronizer#9871

Open
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:groups_level_synchronizer
Open

[cudax] Implement cudax::level_synchronizer#9871
davebayer wants to merge 1 commit into
NVIDIA:mainfrom
davebayer:groups_level_synchronizer

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

Fixes #9870

@davebayer
davebayer requested a review from a team as a code owner July 15, 2026 08:44
@davebayer
davebayer requested a review from caugonnet July 15, 2026 08:44
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 15, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added level-based synchronization for thread, warp, block, cluster, and grid execution levels.
    • Added aligned synchronization support across group types.
    • Unified group synchronization access through a common interface.
  • Bug Fixes

    • Improved synchronization handling by incorporating hierarchy information into synchronization operations.
  • Tests

    • Added coverage for level synchronization and updated existing synchronization tests.

Walkthrough

Adds cuda::experimental::level_synchronizer, routes group synchronization through hierarchy-aware synchronizer instances, simplifies this_* group wrappers, and updates synchronizer and runtime tests.

Changes

Level Synchronizer

Layer / File(s) Summary
Level synchronization implementations
cudax/include/cuda/experimental/__group/synchronizer/level_synchronizer.cuh, cudax/include/cuda/experimental/__group/fwd.cuh, cudax/include/cuda/experimental/group.cuh
Defines level_synchronizer with synchronization implementations for thread, warp, block, cluster, and grid levels, and exposes the header through the group interface.

Group Synchronization Delegation

Layer / File(s) Summary
Group synchronization delegation
cudax/include/cuda/experimental/__group/this_group.cuh, cudax/include/cuda/experimental/__group/group.cuh
Stores hierarchy, mapping, and synchronizer state in __this_group_base; delegates sync() and sync_aligned() through level-specific instances; reduces derived groups to wrappers.

Synchronizer Interface Validation

Layer / File(s) Summary
Synchronizer interface validation
cudax/include/cuda/experimental/__group/synchronizer/barrier_synchronizer.cuh, cudax/include/cuda/experimental/__group/synchronizer/lane_synchronizer.cuh, cudax/test/group/synchronizer/*, cudax/test/group/this_group.cu, cudax/test/CMakeLists.txt
Adds hierarchy parameters to existing synchronizer methods and tests, registers level synchronizer coverage, and validates supported levels and updated group type aliases.

Assessment Against Linked Issues

Objective Addressed Explanation
Implement cudax::level_synchronizer and integrate it with experimental groups [#9870]

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

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 51b715af-9d50-4229-a812-ded9b32ee448

📥 Commits

Reviewing files that changed from the base of the PR and between f11c7b0 and 542edb8.

📒 Files selected for processing (12)
  • cudax/include/cuda/experimental/__group/fwd.cuh
  • cudax/include/cuda/experimental/__group/group.cuh
  • cudax/include/cuda/experimental/__group/synchronizer/barrier_synchronizer.cuh
  • cudax/include/cuda/experimental/__group/synchronizer/lane_synchronizer.cuh
  • cudax/include/cuda/experimental/__group/synchronizer/level_synchronizer.cuh
  • cudax/include/cuda/experimental/__group/this_group.cuh
  • cudax/include/cuda/experimental/group.cuh
  • cudax/test/CMakeLists.txt
  • cudax/test/group/synchronizer/barrier_synchronizer.cu
  • cudax/test/group/synchronizer/lane_synchronizer.cu
  • cudax/test/group/synchronizer/level_synchronizer.cu
  • cudax/test/group/this_group.cu

Comment thread cudax/test/CMakeLists.txt
@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 48m 18s: Pass: 100%/57 | Total: 15h 18m | Max: 48m 15s | Hits: 26%/128114

See results here.

Comment on lines +44 to +48
[[nodiscard]] _CCCL_DEVICE_API auto
make_instance(const _Unit&, const _ParentGroup&, const _MappingResult&) const noexcept
{
return __synchronizer_instance<typename _ParentGroup::level_type>{};
}

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.

Suggested change
[[nodiscard]] _CCCL_DEVICE_API auto
make_instance(const _Unit&, const _ParentGroup&, const _MappingResult&) const noexcept
{
return __synchronizer_instance<typename _ParentGroup::level_type>{};
}
[[nodiscard]] _CCCL_DEVICE_API constexpr __synchronizer_instance<typename _ParentGroup::level_type>
make_instance(const _Unit&, const _ParentGroup&, const _MappingResult&) const noexcept
{
return {};
}

(the constexpr is important, but feel free to reject the rest)

const auto __barrier_ptr = &__grid_workspace_ptr->__barrier_;

// Synchronize the block before synchronizing with the other blocks.
::cuda::experimental::__block_sync<_Aligned>();

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.

Hmmm you've done all this typing implementing the various level synchronizers, but you still just call the bare helper function here (and above in the cluster_level impl). Wouldn't it be cleaner to reuse those types here? Would also help to dogfood the API

Comment on lines +199 to +207
unsigned __curr_barrier_value;
do
{
# if _CCCL_HAS_NV_ATOMIC_BUILTINS()
__nv_atomic_load(__barrier_ptr, &__curr_barrier_value, __NV_ATOMIC_ACQUIRE, __NV_THREAD_SCOPE_DEVICE);
# else // ^^^ _CCCL_HAS_NV_ATOMIC_BUILTINS() ^^^ / vvv !_CCCL_HAS_NV_ATOMIC_BUILTINS() vvv
asm volatile("ld.acquire.gpu.u32 %0, [%1];" : "=r"(__curr_barrier_value) : "l"(__barrier_ptr) : "memory");
# endif // ^^^ !_CCCL_HAS_NV_ATOMIC_BUILTINS() ^^^
} while (static_cast<int>(__old_barrier_value) < 0 == static_cast<int>(__curr_barrier_value) < 0);

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.

Surely we can reuse cuda::std::atomic here no? Or cuda::std::barrier?

: __hier_{::cuda::__unpack_hierarchy_if_needed(__hier_like)}
{}

[[nodiscard]] _CCCL_DEVICE_API const hierarchy_type& hierarchy() const noexcept

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.

Suggested change
[[nodiscard]] _CCCL_DEVICE_API const hierarchy_type& hierarchy() const noexcept
[[nodiscard]] _CCCL_DEVICE_API constexpr const hierarchy_type& hierarchy() const noexcept

(and below as well)

# if _CCCL_HAS_COOPERATIVE_GROUPS()
# if _CCCL_HAS_COOPERATIVE_GROUPS()
template <class _Parent>
_CCCL_DEVICE_API this_thread(const ::cooperative_groups::thread_block_tile<1, _Parent>&) noexcept

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.

This fella could be constexpr as well (should do a pass over these APIs in a follow up PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

[FEA]: Implement cudax::level_synchronizer

2 participants