Skip to content

Require primitive types in cub::NumericTraits to be trivially copyable - #12346

Draft
bernhardmgruber wants to merge 1 commit into
NVIDIA:mainfrom
bernhardmgruber:numeric-traits-primitive-trivially-copyable
Draft

bernhardmgruber wants to merge 1 commit into
NVIDIA:mainfrom
bernhardmgruber:numeric-traits-primitive-trivially-copyable

Conversation

@bernhardmgruber

@bernhardmgruber bernhardmgruber commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Declaring a type primitive via cub::BaseTraits<..., true, ...> now static_asserts that cuda::is_trivially_copyable_v<T> holds. This prepares for replacing is_primitive with cuda::is_trivially_copyable.

This may be a breaking change for downstream projects, so it has to wait for CCCL 4.0.

🤖 Generated with Claude Code

@bernhardmgruber
bernhardmgruber requested a review from a team as a code owner October 29, 2026 23:25
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Oct 29, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Oct 29, 2026
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved compile-time validation for primitive numeric types. Types that are not recognized as trivially copyable now trigger a diagnostic explaining how to provide the required trait specialization. This helps identify unsupported types earlier, before runtime.

Primitive CUB numeric traits now require trivially-copyable types. The checks provide compile-time diagnostics that direct users to specialize cuda::is_trivially_copyable_v.

Changes: Primitive Numeric Trait Constraints

Layer / File(s) Summary
Add trivially-copyable requirements
cub/cub/detail/numeric_traits.cuh
The base trait and unsigned-integer, signed-integer, and floating-point specializations check that primitive types are trivially copyable. Diagnostics direct users to specialize cuda::is_trivially_copyable_v.

Possibly related issues

  • The issue tracking P3247R2 concerns deprecation of trivial-type classification and replacement of is_primitive with cuda::is_trivially_copyable_v. This change adds trivially-copyable requirements to primitive CUB traits.

Possibly related PRs

  • NVIDIA/cccl#12049: Its vectorized-load eligibility checks use cub::is_primitive or cuda::is_trivially_copyable_v; this change affects the type requirements behind cub::is_primitive.

Suggested reviewers: miscco, fbusato, jacobfaib

Priority: Low

Change: Bug fix

Merge Risk: Minimal · up to 58ed5

The change adds compile-time validation without an established regression in supported primitive numeric traits.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 34m: Pass: 100%/210 | Total: 10d 05h | Max: 3h 34m | Hits: 22%/1253780

See results here.

@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

I searched GitHub for downstream projects that specialize cub::NumericTraits / cub::BaseTraits. None of them should need a cuda::is_trivially_copyable specialization: cuda::is_trivially_copyable_v falls back to cuda::std::is_trivially_copyable_v, which all of these types already satisfy. The table only covers code GitHub code search can see (default branches, capped result counts), not private code.

Project Specialized types Needs specialization? Why
TensorFlow Eigen::half, Eigen::bfloat16 No No user-declared copy/move constructor, copy assignment or destructor; half derives from __half_raw (a plain unsigned short). static_assert(cuda::is_trivially_copyable_v<…>) compiles with nvcc 13.4 and Eigen master.
DeepRec Eigen::half No Same type as TensorFlow.
Paddle (also argsort, argsort_grad) phi::float16, phi::bfloat16 No Copy constructor, copy assignment and destructor are all = default (checked by reading the source, not compiled).
PaddleCustomDevice (also iluvatar, metax impl) phi::dtype::float16, phi::dtype::bfloat16 No Same types as Paddle.
AITemplate (also argmax) __nv_bfloat16, empty ThrowAwayType No __nv_bfloat16 is trivially copyable (and libcu++ also specializes it); an empty struct is too.
dash-infer hie::bfloat16 (passes __nv_bfloat16 as T) No The assert checks T = __nv_bfloat16.
swiftrt bfloat16, Complex<float>, Complex<float16> No (likely) Complex has only a user default constructor, no user copy operations or destructor; a stand-in with the same shape passes. Inactive since 2021.
thrustshift custom BaseTraits partial specializations No Uses primitive = false, so the assert does not apply.
PyTorch c10::BFloat16 No Only compiled for hipCUB on ROCm, never with CCCL.
CuPy none No Removed its complex NumericTraits specializations.

🤖 Generated with Claude Code

@bernhardmgruber
bernhardmgruber marked this pull request as draft October 30, 2026 14:38
@copy-pr-bot

copy-pr-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Review to In Progress in CCCL Oct 30, 2026
@bernhardmgruber

Copy link
Copy Markdown
Contributor Author

I just realized this is a breaking change :D So sadly we have to wait for CCCL 4.0.

This branch has not been deployed

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants