Skip to content

[codex] libcudacxx: relax bit_cast fallback construction check#9099

Draft
tpn wants to merge 1 commit into
NVIDIA:mainfrom
tpn:codex/bit-cast-float128-fallback
Draft

[codex] libcudacxx: relax bit_cast fallback construction check#9099
tpn wants to merge 1 commit into
NVIDIA:mainfrom
tpn:codex/bit-cast-float128-fallback

Conversation

@tpn
Copy link
Copy Markdown
Contributor

@tpn tpn commented May 21, 2026

Summary

  • replace the cuda::std::bit_cast memcpy fallback assertion from default_initializable<_To> to is_default_constructible_v<_To>
  • add __float128 / __uint128_t coverage to the existing bit_cast roundtrip test

Root Cause

The memcpy fallback only needs to default-construct a temporary destination object before copying bytes into it. default_initializable is stricter than that and can reject compiler extended floating-point types such as __float128, causing the fallback path to fail even though the destination type is default constructible.

Validation

  • g++ -std=gnu++20 -Ilibcudacxx/include -Ilibcudacxx/test/support libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp -o /tmp/cccl-bit-cast-pass-gcc && /tmp/cccl-bit-cast-pass-gcc
  • clang++ -std=gnu++20 -Ilibcudacxx/include -Ilibcudacxx/test/support libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp -o /tmp/cccl-bit-cast-pass-clang && /tmp/cccl-bit-cast-pass-clang
  • nvcc -std=c++20 -Ilibcudacxx/include -Ilibcudacxx/test/support -x cu libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp -o /tmp/cccl-bit-cast-pass-nvcc && /tmp/cccl-bit-cast-pass-nvcc
  • commit hook suite, including clang-format and codespell

@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented May 21, 2026

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 Todo to In Progress in CCCL May 21, 2026
@fbusato
Copy link
Copy Markdown
Contributor

fbusato commented May 21, 2026

It looks like a hallucination.

Tested locally with __float128 / __uint128_t on several configurations across clang, gcc, cuda-12, nvrtc, nvc++, etc. Everything passes. Also, default_initializable<_To> is the right trait, and stricter than is_default_constructible_v on purpose.
Where are you finding the failure?

The memcpy fallback in cuda::std::bit_cast only needs to default-construct a temporary destination object before copying bytes into it. Requiring default_initializable is stricter and rejects some compiler extended floating-point types, including __float128, even though they are default constructible.

Use is_default_constructible_v for the fallback assertion and add a __float128/__uint128_t regression to the bit_cast coverage.

Signed-off-by: Trent Nelson <trent@trent.me>
@tpn tpn force-pushed the codex/bit-cast-float128-fallback branch from b8c4630 to 1eb080f Compare May 21, 2026 20:06
@tpn
Copy link
Copy Markdown
Contributor Author

tpn commented May 21, 2026

Thanks for checking. The original signal came from an internal NVIDIA DVS/NVBugs report, so I do not want to paste the internal links/log URLs into a public PR.

I did reproduce the relevant condition locally on the public checkout:

  • With g++ -std=gnu++20, CCCL reports cuda::std::default_initializable<__float128> == false while cuda::std::is_default_constructible_v<__float128> == true.
  • Directly instantiating the fallback path fails on origin/main:
    cuda::std::__bit_cast_memcpy<__float128>(__uint128_t{}) hits the default_initializable static assertion in bit_cast.h.
  • The same direct fallback instantiation passes on this PR.

You are also right that ordinary bit_cast<__float128> tests can pass on compilers that use __builtin_bit_cast, because they bypass the memcpy fallback. I pushed 1eb080f4b0 to tighten the regression test so it explicitly instantiates __bit_cast_memcpy<__float128> under the existing _CCCL_HAS_FLOAT128() guard.

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