Skip to content

Distribute std::tuple_(size|element) specializations to implementation files#9123

Merged
davebayer merged 2 commits into
NVIDIA:mainfrom
davebayer:distribute_tuple_protocol
May 26, 2026
Merged

Distribute std::tuple_(size|element) specializations to implementation files#9123
davebayer merged 2 commits into
NVIDIA:mainfrom
davebayer:distribute_tuple_protocol

Conversation

@davebayer
Copy link
Copy Markdown
Contributor

I want to implement tuple protocol for integer_sequence, but there is a non-trivial circular dependency, because we specialize all relevant std:: traits in one file, which includes make_index_sequence.

So, I decided to decentralize the specializations and move them to the places where we specialize the cuda::std:: traits.

Note that we already specialize for example std::formatter inside the implementation files without any problems.

@davebayer davebayer requested review from a team as code owners May 25, 2026 06:40
@davebayer davebayer requested a review from ericniebler May 25, 2026 06:40
@github-project-automation github-project-automation Bot moved this to Todo in CCCL May 25, 2026
@davebayer davebayer requested review from NaderAlAwar and elstehle May 25, 2026 06:40
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL May 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

important: Remove centralized structured_bindings.h; distribute tuple_size/tuple_element specializations into core tuple trait headers and per-type headers, add std ↔ cuda::std interoperability, and update includes and tests.

Changes

Tuple Protocol Refactoring

Layer / File(s) Summary
Core tuple trait infrastructure
libcudacxx/include/cuda/std/__tuple_dir/tuple.h, libcudacxx/include/cuda/std/__tuple_dir/tuple_element.h, libcudacxx/include/cuda/std/__tuple_dir/tuple_size.h, libcudacxx/include/cuda/std/__tuple_dir/tuple_types.h
Core tuple trait headers updated with internal cstddef/type-trait includes, cv-qualified forwarding, std-namespace forwarding specializations, and __tuple_types size/element mappings.
cuda::complex tuple protocol
libcudacxx/include/cuda/__complex/complex.h, libcudacxx/include/cuda/std/__complex/complex.h, libcudacxx/include/cuda/std/__complex/tuple.h
Added tuple_size/tuple_element specializations for cuda::complex<_Tp> and host std::complex<_Tp> (guarded), removed duplicate specializations from complex tuple helper header.
cuda::std::pair tuple protocol
libcudacxx/include/cuda/std/__utility/pair.h
Reworked includes and added cuda::std tuple_size/tuple_element for ::std::pair (host-guarded) and cuda::std::pair, plus std::tuple_size/std::tuple_element specializations for ::cuda::std::pair.
cuda::std::array tuple protocol
libcudacxx/include/cuda/std/array
Replaced prior array trait layout with enable_if(_Ip < _Np)-constrained tuple_element, added host ::std::array support, and added std-namespace specializations for ::cuda::std::array.
cuda::std::tuple tuple protocol
libcudacxx/include/cuda/std/__tuple_dir/tuple.h
Added tuple_size/tuple_element specializations for cuda::std::tuple and conditional support for ::std::tuple, and provided std-namespace mappings for cuda::std::tuple.
ranges::subrange tuple protocol
libcudacxx/include/cuda/std/__ranges/subrange.h
Rewrote ranges::subrange tuple protocol to use integral_constant, enable_if, and conditional_t for element selection and added std interoperability.
Cleanup and include updates
cub/cub/detail/warpspeed/resource/smem_stage.cuh, libcudacxx/include/cuda/std/__tuple_dir/vector_types.h, libcudacxx/include/cuda/std/tuple, thrust/thrust/iterator/detail/tuple_of_iterator_references.h
Removed structured_bindings.h includes, added explicit tuple_element.h/tuple_size.h where required, and adjusted qualification for integral_constant in thrust support.
Tests and test includes
libcudacxx/test/libcudacxx/*
Expanded test includes to cover cuda::std::array, cuda::std::complex, and cuda::std::utility; preserved negative-test diagnostics with [[maybe_unused]].

suggested labels: libcu++

suggested reviewers:

  • elstehle
  • NaderAlAwar

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
libcudacxx/include/cuda/std/__ranges/subrange.h (1)

496-504: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: Same inheritance bug as the cuda::std versions—needs type_identity wrapper.

 template <::cuda::std::size_t _Idx, class _Ip, class _Sp, ::cuda::std::ranges::subrange_kind _Kp>
 struct tuple_element<_Idx, ::cuda::std::ranges::subrange<_Ip, _Sp, _Kp>>
-    : ::cuda::std::enable_if_t<(_Idx < 2), ::cuda::std::conditional_t<(_Idx == 0), _Ip, _Sp>>
+    : ::cuda::std::enable_if_t<(_Idx < 2), ::cuda::std::type_identity<::cuda::std::conditional_t<(_Idx == 0), _Ip, _Sp>>>
 {};

 template <::cuda::std::size_t _Idx, class _Ip, class _Sp, ::cuda::std::ranges::subrange_kind _Kp>
 struct tuple_element<_Idx, const ::cuda::std::ranges::subrange<_Ip, _Sp, _Kp>>
-    : ::cuda::std::enable_if_t<(_Idx < 2), ::cuda::std::conditional_t<(_Idx == 0), _Ip, _Sp>>
+    : ::cuda::std::enable_if_t<(_Idx < 2), ::cuda::std::type_identity<::cuda::std::conditional_t<(_Idx == 0), _Ip, _Sp>>>
 {};

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6eb35ad0-cca1-45fc-a35d-855ab6081716

📥 Commits

Reviewing files that changed from the base of the PR and between e6af9a9 and 2b10101.

📒 Files selected for processing (15)
  • cub/cub/detail/warpspeed/resource/smem_stage.cuh
  • libcudacxx/include/cuda/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/tuple.h
  • libcudacxx/include/cuda/std/__ranges/subrange.h
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_element.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_size.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_types.h
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/include/cuda/std/array
  • libcudacxx/include/cuda/std/tuple
  • thrust/thrust/iterator/detail/tuple_of_iterator_references.h
💤 Files with no reviewable changes (4)
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/tuple
  • libcudacxx/include/cuda/std/__complex/tuple.h

Comment thread libcudacxx/include/cuda/std/__ranges/subrange.h Outdated
@davebayer davebayer force-pushed the distribute_tuple_protocol branch 3 times, most recently from e29e5e9 to 41f3cca Compare May 25, 2026 11:39
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: af568c0e-a7ad-4440-aa0e-87981093659f

📥 Commits

Reviewing files that changed from the base of the PR and between e29e5e9 and 41f3cca.

📒 Files selected for processing (18)
  • cub/cub/detail/warpspeed/resource/smem_stage.cuh
  • libcudacxx/include/cuda/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/tuple.h
  • libcudacxx/include/cuda/std/__ranges/subrange.h
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_element.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_size.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_types.h
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/include/cuda/std/array
  • libcudacxx/include/cuda/std/tuple
  • libcudacxx/test/libcudacxx/cuda/utilities/tuple/std_types_tuple_element.pass.cpp
  • libcudacxx/test/libcudacxx/cuda/utilities/tuple/std_types_tuple_size.pass.cpp
  • libcudacxx/test/libcudacxx/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
  • thrust/thrust/iterator/detail/tuple_of_iterator_references.h
💤 Files with no reviewable changes (4)
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/tuple
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__complex/tuple.h
✅ Files skipped from review due to trivial changes (1)
  • libcudacxx/test/libcudacxx/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp

Comment thread libcudacxx/include/cuda/std/array
Comment thread libcudacxx/include/cuda/std/array
Comment thread libcudacxx/include/cuda/std/array
@davebayer davebayer force-pushed the distribute_tuple_protocol branch from 41f3cca to 91c17e9 Compare May 25, 2026 11:50
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5c25d0eb-118b-4488-be2d-4a6744c8b6b7

📥 Commits

Reviewing files that changed from the base of the PR and between 41f3cca and 91c17e9.

📒 Files selected for processing (18)
  • cub/cub/detail/warpspeed/resource/smem_stage.cuh
  • libcudacxx/include/cuda/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/complex.h
  • libcudacxx/include/cuda/std/__complex/tuple.h
  • libcudacxx/include/cuda/std/__ranges/subrange.h
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_element.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_size.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_types.h
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/__utility/pair.h
  • libcudacxx/include/cuda/std/array
  • libcudacxx/include/cuda/std/tuple
  • libcudacxx/test/libcudacxx/cuda/utilities/tuple/std_types_tuple_element.pass.cpp
  • libcudacxx/test/libcudacxx/cuda/utilities/tuple/std_types_tuple_size.pass.cpp
  • libcudacxx/test/libcudacxx/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
  • thrust/thrust/iterator/detail/tuple_of_iterator_references.h
💤 Files with no reviewable changes (4)
  • libcudacxx/include/cuda/std/tuple
  • libcudacxx/include/cuda/std/__tuple_dir/structured_bindings.h
  • libcudacxx/include/cuda/std/__tuple_dir/vector_types.h
  • libcudacxx/include/cuda/std/__complex/tuple.h
✅ Files skipped from review due to trivial changes (1)
  • cub/cub/detail/warpspeed/resource/smem_stage.cuh

Comment thread libcudacxx/include/cuda/std/__utility/pair.h Outdated
@davebayer davebayer force-pushed the distribute_tuple_protocol branch from 91c17e9 to 862ae56 Compare May 25, 2026 12:49
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 10m: Pass: 100%/398 | Total: 19d 22h | Max: 3h 09m | Hits: 24%/4225373

See results here.

Copy link
Copy Markdown
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

Looks good, I believe with the added forward declarations this is now the better approach

@davebayer davebayer merged commit a6a5665 into NVIDIA:main May 26, 2026
416 of 419 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants