Skip to content

[libcu++] Add resource_cast and dynamic_resource_cast#8272

Open
pciolkosz wants to merge 8 commits intoNVIDIA:mainfrom
pciolkosz:expose_any_casts
Open

[libcu++] Add resource_cast and dynamic_resource_cast#8272
pciolkosz wants to merge 8 commits intoNVIDIA: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
Copy link
Copy Markdown
Contributor

bdice commented Apr 2, 2026

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

@github-actions

This comment has been minimized.

@pciolkosz
Copy link
Copy Markdown
Contributor Author

pciolkosz commented Apr 3, 2026

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
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

🥳 CI Workflow Results

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

See results here.

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants