Skip to content

[libcu++] Backport cuda::std::constant_wrapper to C++17 - #10687

Merged
davebayer merged 6 commits into
NVIDIA:mainfrom
davebayer:constant_wrapper_cpp17
Aug 7, 2026
Merged

[libcu++] Backport cuda::std::constant_wrapper to C++17#10687
davebayer merged 6 commits into
NVIDIA:mainfrom
davebayer:constant_wrapper_cpp17

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

No description provided.

@davebayer
davebayer requested a review from a team as a code owner August 6, 2026 13:09
@davebayer
davebayer requested a review from fbusato August 6, 2026 13:09
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 6, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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

Summary by CodeRabbit

  • New Features

    • Enabled constant-wrapper functionality across configured language standards, including C++17, while retaining NVRTC limitations.
    • Expanded support for arithmetic, logical, comparison, conversion, invocation, subscript, and kernel-parameter use cases.
  • Bug Fixes

    • Improved constant-wrapper operations and type detection in pre-C++20 environments.
  • Tests

    • Expanded compatibility coverage across language standards.
    • Added validation for operator behavior, conversions, overloads, runtime interactions, and compiler-specific cases.

Walkthrough

Changes

The constant_wrapper implementation now supports configured language standards except NVRTC. Its tests support C++17 where possible, replace C++20 concepts with SFINAE traits, and guard C++20-only cases.

Constant-wrapper compatibility

Layer / File(s) Summary
Implementation guard and unary address-of
libcudacxx/include/cuda/std/__utility/constant_wrapper.h
The implementation is enabled outside NVRTC. Unary operator& uses C++17-compatible syntax.
Baseline wrapper tests
libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/{adl,assign,comma,convert,cw,general,kernel_parameter,kernel_parameter.array,mem_ptr,types.compile}.pass.cpp
Tests no longer exclude C++17 when supported. C++20-only checks remain conditionally compiled.
Operator tests
libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/{unary_ops,binary_ops,comp,pseudo_mutators}.pass.cpp
Operator concepts were replaced with SFINAE-based detection traits. Result type checks use separate decltype and same_as assertions.
Invocation and subscript tests
libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/{call,subscript}.pass.cpp
Invocation and subscript coverage separates C++17-compatible cases from C++20-only cases and uses explicit template syntax where required.

Possibly related PRs

  • NVIDIA/cccl#9702: Both changes modify constant_wrapper.h and its associated tests.
  • NVIDIA/cccl#10588: Both changes modify constant_wrapper.h and its associated tests.

Suggested reviewers: fbusato, miscco


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

🧹 Nitpick comments (2)
libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp (1)

121-185: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

suggestion: Rename the detection templates to the required naming convention. Rename T to a PascalCase name such as Type. Rename HasPlus, HasMinus, HasBitNot, HasNot, HasBitAnd, HasDeref, and the HasNoexcept* templates to snake_case names.

As per coding guidelines, use PascalCase for template parameter names and snake_case for all other symbols.

Source: Coding guidelines

libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp (1)

192-346: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

suggestion: collapse the 24 detection templates with a macro.

Each pair differs only by the operator token. One macro removes about 150 lines of copy-paste and keeps the SFINAE key and the noexcept expression in sync by construction.

+#define DEFINE_BINARY_OP_TRAITS(Name, Op)                                                                     \
+  template <class L, class R, class = void>                                                                    \
+  inline constexpr bool Has##Name = false;                                                                     \
+  template <class L, class R>                                                                                  \
+  inline constexpr bool                                                                                        \
+    Has##Name<L, R, cuda::std::void_t<decltype(cuda::std::declval<L&>() Op cuda::std::declval<R&>())>> = true;  \
+  template <class L, class R, class = void>                                                                    \
+  inline constexpr bool HasNoexcept##Name = false;                                                              \
+  template <class L, class R>                                                                                  \
+  inline constexpr bool                                                                                        \
+    HasNoexcept##Name<L, R, cuda::std::void_t<decltype(cuda::std::declval<L&>() Op cuda::std::declval<R&>())>> = \
+      noexcept(cuda::std::declval<L&>() Op cuda::std::declval<R&>())
+
+DEFINE_BINARY_OP_TRAITS(Plus, +);
+DEFINE_BINARY_OP_TRAITS(Minus, -);
+// ... remaining operators

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8e16e497-0482-4403-8cc3-71de68ee7573

📥 Commits

Reviewing files that changed from the base of the PR and between fef5a52 and 3f25828.

📒 Files selected for processing (17)
  • libcudacxx/include/cuda/std/__utility/constant_wrapper.h
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/adl.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/assign.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/call.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comma.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comp.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/convert.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/cw.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/general.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/mem_ptr.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/pseudo_mutators.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/subscript.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/types.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp
💤 Files with no reviewable changes (2)
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp

Comment thread libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/assign.pass.cpp Outdated
Comment thread libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/cw.pass.cpp Outdated
@davebayer
davebayer force-pushed the constant_wrapper_cpp17 branch from 3f25828 to 5aa6ac6 Compare August 6, 2026 13:25
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions

This comment has been minimized.

@davebayer
davebayer force-pushed the constant_wrapper_cpp17 branch from 5aa6ac6 to 31a7623 Compare August 6, 2026 13:27

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7d3e900f-fcd1-4f15-a0ad-5fff3e3fd565

📥 Commits

Reviewing files that changed from the base of the PR and between fef5a52 and 5aa6ac6.

📒 Files selected for processing (17)
  • libcudacxx/include/cuda/std/__utility/constant_wrapper.h
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/adl.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/assign.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/call.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comma.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comp.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/convert.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/cw.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/general.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/mem_ptr.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/pseudo_mutators.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/subscript.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/types.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp
💤 Files with no reviewable changes (2)
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp
🚧 Files skipped from review as they are similar to previous changes (13)
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/adl.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/mem_ptr.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comma.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/convert.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/types.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/cw.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/call.pass.cpp
  • libcudacxx/include/cuda/std/__utility/constant_wrapper.h
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comp.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/general.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/subscript.pass.cpp

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@davebayer
davebayer force-pushed the constant_wrapper_cpp17 branch from 31a7623 to 216af9c Compare August 6, 2026 13:32
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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: 777000c5-7fb0-486e-bb49-80e7b851eb0a

📥 Commits

Reviewing files that changed from the base of the PR and between fef5a52 and 216af9c.

📒 Files selected for processing (17)
  • libcudacxx/include/cuda/std/__utility/constant_wrapper.h
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/adl.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/assign.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/call.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comma.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comp.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/convert.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/cw.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/general.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/mem_ptr.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/pseudo_mutators.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/subscript.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/types.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp
💤 Files with no reviewable changes (2)
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.array.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/kernel_parameter.pass.cpp
🚧 Files skipped from review as they are similar to previous changes (11)
  • libcudacxx/include/cuda/std/__utility/constant_wrapper.h
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/types.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/mem_ptr.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/adl.compile.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/general.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/unary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/binary_ops.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/call.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/comma.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/convert.pass.cpp
  • libcudacxx/test/libcudacxx/std/utilities/const.wrap.class/subscript.pass.cpp

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⏱️ CCCL compile-time benchmark comparison: Public headers compile-time bench

Result: 2 regression row(s), 12 improvement row(s) above threshold.

Run Value
Config public-headers-gcc13
Baseline origin/main
Preset all-dev
Targets cub.headers.base, thrust.cpp.cuda.headers.base, libcudacxx.test.public_headers
GPU / launch args rtx2080 / --cuda 13.3 --host gcc13

Artifacts: reports and traces

TU total compilation

-f total-compilation inclusive --sort total

🔴 TU total compilation — Regressions
Rank Regression impact Selected Δ Baseline Current Event Matched traces
1 4.639144 4.639144 13.415309 18.054453 Total Compilation Time: thrust/shuffle.h 1
2 3.155232 3.155232 14.370129 17.525361 Total Compilation Time: thrust/transform_reduce.h 1
🟢 TU total compilation — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 4.359860 -4.359860 20.227235 15.867375 Total Compilation Time: cuda/execution 1
2 3.738350 -3.738350 10.380363 6.642013 Total Compilation Time: cub/agent/agent_merge_sort.cuh 1
3 3.727775 -3.727775 20.328296 16.600521 Total Compilation Time: cuda/std/execution 1
4 3.252869 -3.252869 14.525175 11.272306 Total Compilation Time: cub/device/device_copy.cuh 1

Direct file processing

-f file-processing exclusive --sort total

🟢 Direct file processing — Improvements
Rank Improvement impact Selected Δ Baseline Current Event Matched traces
1 1.583696 -1.583696 23.816642 22.232946 Processing Header File: libcudacxx/include/cuda/__device/physical_device.h 94
2 1.468507 -1.468507 10.432210 8.963703 Processing Header File: libcudacxx/include/cuda/std/__cccl/prologue.h 550
3 0.479162 -0.479162 3.690283 3.211121 Processing Header File: libcudacxx/include/cuda/std/__cccl/epilogue.h 550
4 0.466628 -0.466628 6.291381 5.824753 Processing Header File: libcudacxx/include/cuda/std/__iterator/iterator_traits.h 464
5 0.450448 -0.450448 12.747601 12.297153 Processing Header File: libcudacxx/include/cuda/std/__type_traits/type_list.h 477
6 0.427840 -0.427840 12.115479 11.687639 Processing Header File: libcudacxx/include/cuda/std/__iterator/concepts.h 437
7 0.226635 -0.226635 1.888419 1.661784 Processing Header File: libcudacxx/include/cuda/std/__limits/numeric_limits_ext.h 409
8 0.202125 -0.202125 2.336037 2.133912 Processing Header File: cub/cub/device/dispatch/tuning/tuning_scan.cuh 68

@davebayer
davebayer enabled auto-merge (squash) August 7, 2026 08:44
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 12m: Pass: 100%/115 | Total: 1d 01h | Max: 1h 11m | Hits: 99%/327444

See results here.

@davebayer
davebayer merged commit 5200422 into NVIDIA:main Aug 7, 2026
142 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Aug 7, 2026
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