Use any_resource<device_accessible> for upstream constructor parameters - #2354
Merged
Merged
Conversation
bdice
requested review from
TomAugspurger,
lamarrr and
vyasr
and removed request for
a team
April 9, 2026 19:22
wence-
reviewed
Apr 10, 2026
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
force-pushed
the
any-resource-upstream-params
branch
from
April 11, 2026 20:04
84f8bb0 to
211be88
Compare
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.
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.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Change all resource/adaptor constructors from
device_async_resource_reftocuda::mr::any_resource<cuda::mr::device_accessible>taken by value, withstd::moveinto member storage. This follows the sink-parameter idiom (likestd::shared_ptr), enabling move semantics for rvalue arguments and making ownership transfer explicit.The central motivation is that
device_async_resource_refis a non-owning reference that cannot bind to temporaries (rvalues/xvalues). Code likepool_memory_resource(cuda_memory_resource(), size)is impossible withdevice_async_resource_refbecause the temporarycuda_memory_resourceis 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_resourcetoupstreamfor consistency across all adaptors.Cython bindings use a
make_any_device_resourceinline helper to work around a CCCL template deduction issue whereany_resourcecannot be constructed from Cython's__Pyx_FakeReferenceproxy type wrappingresource_ref(NVIDIA/cccl#8320). This workaround should be removed once CCCL merges the upstream fix.Testing:
Checklist