Skip to content

[libcu++] Add resource_cast and dynamic_resource_cast - #8272

Merged
pciolkosz merged 8 commits into
NVIDIA:mainfrom
pciolkosz:expose_any_casts
Apr 13, 2026
Merged

[libcu++] Add resource_cast and dynamic_resource_cast#8272
pciolkosz merged 8 commits into
NVIDIA:mainfrom
pciolkosz:expose_any_casts

Conversation

@pciolkosz

Copy link
Copy Markdown
Contributor

This PR adds resource_cast and dynamic_resource_cast wrapper for internal __any_cast and __dynamic_any_cast specialized for resource wrappers.

I also added validation to __dynamic_any_cast implementation, which was right now succeeding regardless of what the destination interface was. Now it confirms destination interface is a subset of the original vtable. Tests were added to __basic_any testing to confirm this behavior

@pciolkosz
pciolkosz requested a review from a team as a code owner April 2, 2026 00:03
@pciolkosz
pciolkosz requested a review from davebayer April 2, 2026 00:03
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Apr 2, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Apr 2, 2026
@pciolkosz
pciolkosz requested review from ericniebler and miscco April 2, 2026 00:50
@bdice

bdice commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

I did a bit of comparison between #8269 and this PR.

@github-actions

This comment has been minimized.

@pciolkosz

pciolkosz commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

Concept constraints. #8269 constrains every overload with resource_with / synchronous_resource_with. This PR's resource_cast is unconstrained, any _Tp is accepted. I wonder if this should be a compile-time error for types that don't satisfy the resource concept.

I added static_asserts inside

Does this PR have enough Doxygen? #8269 has a bit more, I'm not sure what is expected.

I think its fine

Test gaps compared to #8269:
nullptr input (covered by __any_cast internally, but seems untested in the public API)
moved-from wrapper returns nullptr
I'd like explicit tests that succeed or fail for derived-to-base casts, we have lots of MR inheritance in RMM

Added test cases

Naming. cuda::mr::any_cast mirrors std::any_cast. Does this function have similar semantics to std::any_cast?

I think because we also have the dynamic_resource_cast that has no equivalent in stl and the interface is restricted only to specifically resource wrappers I would stay with cuda::mr::resource_cast and cuda::mr::dynamic_resource_cast

@github-actions

This comment has been minimized.

- resource_cast: explicitly static_cast to __basic_any base before
  calling __any_cast, working around GCC < 11 inability to deduce
  template arguments from derived-to-base class conversions.
- basic_any test: change test_iset_dynamic_cast from _CCCL_HOST to
  _CCCL_HOST_DEVICE so NVRTC can compile the file.
ClangCUDA compiles _CCCL_HOST_DEVICE functions for both host and
device. The try/catch code behind _CCCL_HAS_EXCEPTIONS() was included
on device, causing a compilation failure. Wrap with NV_IF_TARGET to
restrict it to the host path.
Replace the NV_IF_TARGET approach (which used #if inside a macro
argument, breaking MSVC) with #if \!_CCCL_COMPILER(NVRTC) guards
around the _CCCL_HOST function and its call site.
The _CCCL_HOST function was called from main outside NV_IF_TARGET,
causing a host function call from the device path under nvcc.
Move #if outside NV_IF_TARGET by using a separate NV_IF_TARGET call
for test_iset_dynamic_cast, guarded by #if \!_CCCL_COMPILER(NVRTC).
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 20m: Pass: 100%/108 | Total: 1d 01h | Max: 57m 36s | Hits: 99%/281525

See results here.

@pciolkosz
pciolkosz merged commit fcfbc1a into NVIDIA:main Apr 13, 2026
126 of 128 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Apr 13, 2026
jainishmehta pushed a commit to jainishmehta/cccl that referenced this pull request Apr 19, 2026
* Add resource_cast and dynamic_resource_cast

* Fix format

* Review feedback

* Fix GCC < 11 and NVRTC build failures

- resource_cast: explicitly static_cast to __basic_any base before
  calling __any_cast, working around GCC < 11 inability to deduce
  template arguments from derived-to-base class conversions.
- basic_any test: change test_iset_dynamic_cast from _CCCL_HOST to
  _CCCL_HOST_DEVICE so NVRTC can compile the file.

* Fix ClangCUDA: guard try/catch with NV_IF_TARGET

ClangCUDA compiles _CCCL_HOST_DEVICE functions for both host and
device. The try/catch code behind _CCCL_HAS_EXCEPTIONS() was included
on device, causing a compilation failure. Wrap with NV_IF_TARGET to
restrict it to the host path.

* Fix MSVC: guard test_iset_dynamic_cast with NVRTC check

Replace the NV_IF_TARGET approach (which used #if inside a macro
argument, breaking MSVC) with #if \!_CCCL_COMPILER(NVRTC) guards
around the _CCCL_HOST function and its call site.

* Fix: move test_iset_dynamic_cast call inside NV_IF_TARGET

The _CCCL_HOST function was called from main outside NV_IF_TARGET,
causing a host function call from the device path under nvcc.

* Fix MSVC: no preprocessor directives inside macro arguments

Move #if outside NV_IF_TARGET by using a separate NV_IF_TARGET call
for test_iset_dynamic_cast, guarded by #if \!_CCCL_COMPILER(NVRTC).
rapids-bot Bot pushed a commit to rapidsai/rapids-cmake that referenced this pull request Apr 29, 2026
This PR updates CCCL to the latest 3.4.0 pre-release commit.

Comparison of CCCL commits: NVIDIA/cccl@c5594eb...c936ad8

We specifically need these features/fixes for RAPIDS projects:
- NVIDIA/cccl#8353
- NVIDIA/cccl#8272
- NVIDIA/cccl#8320
- NVIDIA/cccl#8486

Authors:
  - Niranda Perera (https://github.com/nirandaperera)
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #1008
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.

3 participants