Skip to content

Migrate base memory resources to native CCCL resource concept#2289

Merged
bdice merged 5 commits intorapidsai:stagingfrom
bdice:cccl-base-mrs
Mar 16, 2026
Merged

Migrate base memory resources to native CCCL resource concept#2289
bdice merged 5 commits intorapidsai:stagingfrom
bdice:cccl-base-mrs

Conversation

@bdice
Copy link
Collaborator

@bdice bdice commented Mar 11, 2026

Description

Closes #2287

Migrates all 8 base (non-adaptor) memory resources to natively satisfy the CCCL cuda::mr::resource concept, so that concrete types (e.g. cuda_memory_resource&) satisfy the concept without virtual dispatch through device_memory_resource.

Stateless resources get allocate/deallocate/allocate_sync/deallocate_sync accepting cuda::stream_ref directly on the class:

  • cuda_memory_resourcedevice_accessible
  • managed_memory_resourcedevice_accessible + host_accessible
  • pinned_host_memory_resourcedevice_accessible + host_accessible
  • cuda_async_view_memory_resourcedevice_accessible
  • system_memory_resourcedevice_accessible + host_accessible

Stateful, non-copyable resources use cuda::mr::shared_resource<Impl> with _impl classes extracted to detail/ headers and .cpp source files, matching the adaptor convention from prior PRs (e.g. limiting_resource_adaptor):

  • cuda_async_memory_resourcedevice_accessible
  • cuda_async_managed_memory_resourcedevice_accessible + host_accessible
  • sam_headroom_memory_resourcedevice_accessible + host_accessible

device_memory_resource inheritance is kept for backward compatibility. do_allocate/do_deallocate delegate to the new CCCL methods. Default alignment is rmm::CUDA_ALLOCATION_ALIGNMENT (256 bytes).

Checklist

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

@copy-pr-bot
Copy link

copy-pr-bot bot commented Mar 11, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Migrate all 8 base (non-adaptor) memory resources to natively satisfy
the CCCL cuda::mr::resource concept, so that concrete types satisfy
the concept without virtual dispatch through device_memory_resource.

Stateless resources (cuda_memory_resource, managed_memory_resource,
pinned_host_memory_resource, cuda_async_view_memory_resource,
system_memory_resource) get allocate/deallocate/allocate_sync/
deallocate_sync with cuda::stream_ref directly on the class.

Stateful resources (cuda_async_memory_resource,
cuda_async_managed_memory_resource, sam_headroom_memory_resource)
use the cuda::mr::shared_resource<Impl> pattern with _impl classes
extracted to detail/ headers and .cpp source files, matching the
adaptor convention established in prior PRs.

device_memory_resource inheritance is kept for backward compatibility,
with do_allocate/do_deallocate delegating to the new CCCL methods.
@bdice bdice marked this pull request as ready for review March 12, 2026 21:15
@bdice bdice requested review from a team as code owners March 12, 2026 21:15
@bdice bdice requested review from harrism and miscco and removed request for a team March 12, 2026 21:15
@bdice bdice added breaking Breaking change improvement Improvement / enhancement to an existing function labels Mar 12, 2026
@bdice bdice self-assigned this Mar 12, 2026
@bdice bdice moved this to In Progress in RMM Project Board Mar 12, 2026
Comment on lines 66 to 73
/**
* @brief Allocates memory of size at least \p bytes.
*
* The returned pointer will have at minimum 256 byte alignment.
*
* @param bytes The size of the allocation
* @param stream Stream on which to perform allocation
* @return void* Pointer to the newly allocated memory
* @brief Enables the `cuda::mr::device_accessible` property
*/
void* do_allocate(std::size_t bytes, rmm::cuda_stream_view stream) override
RMM_CONSTEXPR_FRIEND void get_property(cuda_async_managed_memory_resource const&,
cuda::mr::device_accessible) noexcept
{
return pool_.allocate(stream, bytes);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get these properties from the impl via using shared_base::get_property?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_property is a friend free function (ADL), not a member, so using cannot pull it in. All shared_resource classes duplicate it.

@github-project-automation github-project-automation bot moved this from In Progress to Review in RMM Project Board Mar 13, 2026
bdice added 3 commits March 13, 2026 18:21
…or== shortcircuit

- Replace (void)param casts with [[maybe_unused]] on parameter declarations
  in all 5 stateless base resource headers
- Add cudaStreamSynchronize in allocate_sync for cuda_memory_resource,
  managed_memory_resource, pinned_host_memory_resource, system_memory_resource,
  and sam_headroom_memory_resource_impl
- Add this==addressof(other) shortcircuit to operator== in
  cuda_async_memory_resource_impl and cuda_async_managed_memory_resource_impl
- Add <memory> include for std::addressof in the two async impl headers
Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good AFAICT, with some small comments to address/discuss in followup

@@ -0,0 +1,90 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is a new file, is this the correct copyright line?

Copy link
Collaborator Author

@bdice bdice Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept an older copyright year because most of the file contents are being moved/copied from another file.


#include <cstddef>

namespace RMM_NAMESPACE {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder that RMM_NAMESPACE has __attribute((visibility("default"))) IIRC, so all of these impl types are, today, still in the public symbols. I think we do not fix that here, but once the dust has settled perhaps we can go round and more correctly deal with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, absolutely. I plan to do a thorough public symbol audit once I get through this migration.

Comment on lines +37 to +41
// Begin legacy device_memory_resource compatibility layer
using device_memory_resource::allocate;
using device_memory_resource::allocate_sync;
using device_memory_resource::deallocate;
using device_memory_resource::deallocate_sync;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going away soon, but remind me, why do we get the concrete implementations from device_memory_resource rather than shared_base?

See previous comments here: #2246 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being fixed in a later phase. I have a draft of it locally. I think it's fine to delay this until that later PR is ready.

Co-authored-by: Lawrence Mitchell <wence@gmx.li>
@bdice bdice merged commit c4b5236 into rapidsai:staging Mar 16, 2026
81 of 84 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in RMM Project Board Mar 16, 2026
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