Skip to content

Use any_resource<device_accessible> for upstream constructor parameters - #2354

Merged
bdice merged 4 commits into
rapidsai:stagingfrom
bdice:any-resource-upstream-params
Apr 12, 2026
Merged

bdice merged 4 commits into
rapidsai:stagingfrom
bdice:any-resource-upstream-params

Conversation

@bdice

@bdice bdice commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Change all resource/adaptor constructors from device_async_resource_ref to cuda::mr::any_resource<cuda::mr::device_accessible> taken by value, with std::move into member storage. This follows the sink-parameter idiom (like std::shared_ptr), enabling move semantics for rvalue arguments and making ownership transfer explicit.

The central motivation is that device_async_resource_ref is a non-owning reference that cannot bind to temporaries (rvalues/xvalues). Code like pool_memory_resource(cuda_memory_resource(), size) is impossible with device_async_resource_ref because the temporary cuda_memory_resource is destroyed before the adaptor can use it. any_resource<device_accessible> by value solves this: callers pass a resource that gets moved into type-erased owned storage, so the adaptor owns its upstream and no external lifetime management is needed.

Also renames upstream_mr / upstream_resource to upstream for consistency across all adaptors.

Cython bindings use a make_any_device_resource inline helper to work around a CCCL template deduction issue where any_resource cannot be constructed from Cython's __Pyx_FakeReference proxy type wrapping resource_ref (NVIDIA/cccl#8320). This workaround should be removed once CCCL merges the upstream fix.

Testing:

  • C++ build: 178/178 targets
  • C++ tests: 103/103 passed
  • Python tests: 1785 passed, 1 skipped
  • All against stock (unpatched) CCCL

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@bdice
bdice requested review from a team as code owners April 9, 2026 19:22
@bdice
bdice requested review from TomAugspurger, lamarrr and vyasr and removed request for a team April 9, 2026 19:22
@bdice bdice moved this to In Progress in RMM Project Board Apr 9, 2026
@bdice bdice added breaking Breaking change improvement Improvement / enhancement to an existing function labels Apr 9, 2026
@bdice bdice self-assigned this Apr 9, 2026
Comment thread cpp/include/rmm/mr/detail/arena.hpp Outdated
Change all resource/adaptor constructors from device_async_resource_ref
to cuda::mr::any_resource<cuda::mr::device_accessible> taken by value,
with std::move into member storage. This follows the sink-parameter
idiom (like shared_ptr), enabling move semantics for rvalue arguments
and making ownership transfer explicit.

Rename upstream_mr/upstream_resource to upstream for consistency.

Cython bindings use a make_any_device_resource inline helper to work
around CCCL template deduction issue with Cython's FakeReference proxy.

Ref: NVIDIA/cccl#8320
@bdice
bdice force-pushed the any-resource-upstream-params branch from 84f8bb0 to 211be88 Compare April 11, 2026 20:04
bdice added 3 commits April 11, 2026 22:18
Extend the by-value any_resource parameter pattern to device_buffer,
device_uvector, device_scalar, exec_policy, and thrust_allocator.
These previously took device_async_resource_ref and stored into
any_resource members; now they take any_resource by value with
std::move, matching the sink-parameter idiom used by the adaptors.

Update Cython device_buffer.pxd declarations and .pyx call sites
to use make_any_device_resource workaround.
Change polymorphic_allocator constructor from device_async_resource_ref
to any_resource by value with std::move, matching the sink-parameter
idiom used elsewhere. Update test to construct any_resource explicitly
since two implicit user-defined conversions are not allowed.
Keep @copydoc targets on a single line with clang-format off guards
so doxygen 1.9.1 can resolve them. Multi-line @copydoc targets with
template types fail to match.
@bdice
bdice merged commit 98b0581 into rapidsai:staging Apr 12, 2026
84 of 85 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in RMM Project Board Apr 12, 2026
bdice added a commit that referenced this pull request Apr 13, 2026
…y_resource by value (#2356)

## Summary

- Add `set_per_device_resource` and `set_current_device_resource`
functions that take
`cuda::mr::any_resource<cuda::mr::device_accessible>` by value
(ownership-transferring), following the same sink-parameter pattern
established in #2354
- Refactor `set_per_device_resource_ref` and
`set_current_device_resource_ref` to delegate to the new functions
- Update Cython bindings to call the new owning-resource setters via
`make_any_device_resource` workaround

The `_ref` variants remain for callers that have a non-owning
`device_async_resource_ref`, but the implementation now routes through
the owning `any_resource` path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change improvement Improvement / enhancement to an existing function

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants