Skip to content

Return owning any_resource from set_per_device_resource_ref - #2271

Merged
bdice merged 1 commit into
rapidsai:stagingfrom
bdice:fix-set-per-device-resource-ref-return
Mar 4, 2026
Merged

bdice merged 1 commit into
rapidsai:stagingfrom
bdice:fix-set-per-device-resource-ref-return

Conversation

@bdice

@bdice bdice commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator

Description

The set/reset functions returned device_async_resource_ref (non-owning) to the previous resource, but the underlying any_resource in the map was immediately overwritten, leaving the returned ref dangling. This was UB that happened to be masked by small buffer optimization for small resource types like cuda_memory_resource.

This PR returns cuda::mr::any_resource<cuda::mr::device_accessible> (owning) instead, using std::exchange to atomically swap old and new values.

Checklist

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

The set/reset functions returned device_async_resource_ref (non-owning) to the
previous resource, but the underlying any_resource in the map was immediately
overwritten, leaving the returned ref dangling. This is UB that happens to be
masked by SBO for small resource types like cuda_memory_resource.

Return cuda::mr::any_resource<cuda::mr::device_accessible> (owning) instead,
using std::exchange to atomically swap old and new values.
@bdice
bdice requested a review from a team as a code owner March 4, 2026 16:58
@bdice
bdice requested review from davidwendt and harrism and removed request for a team March 4, 2026 16:58
@bdice bdice added breaking Breaking change improvement Improvement / enhancement to an existing function labels Mar 4, 2026
@bdice bdice self-assigned this Mar 4, 2026
@bdice bdice moved this to In Progress in RMM Project Board Mar 4, 2026
@bdice

bdice commented Mar 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

This is a prerequisite for a bunch of other work targeting staging. I expected this refactoring would be necessary. I'm going to admin-merge this once CI passes so I can keep working on the other staging refactors.

@bdice
bdice merged commit ca063dc into rapidsai:staging Mar 4, 2026
132 of 139 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in RMM Project Board Mar 4, 2026
@bdice bdice mentioned this pull request Mar 10, 2026
51 tasks done
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.

3 participants