Skip to content

[FEA] Remove device_memory_resource inheritance from all C++ memory resources #2295

@bdice

Description

@bdice

Remove device_memory_resource inheritance from all C++ memory resources

Part of #2011. Depends on Python migration (see linked issue).

Problem

Every memory resource in RMM inherits from device_memory_resource and
implements do_allocate / do_deallocate / do_is_equal virtual overrides.
This virtual base class was the original polymorphism mechanism but is now
redundant: all resources satisfy the CCCL memory resource concepts natively
(verified by static_assert), and all consumers (device_buffer,
device_uvector, per-device resource APIs) already use device_async_resource_ref
/ any_resource.

The device_memory_resource inheritance exists solely as a backward-compatibility
layer. Once the Python bindings no longer depend on it (see linked issue), there
are no remaining consumers of the virtual dispatch path.

Goal

After this work:

  • No resource class inherits from device_memory_resource
  • No do_allocate, do_deallocate, or do_is_equal methods exist anywhere
  • device_memory_resource.hpp is deleted
  • All resources satisfy CCCL concepts via their own allocate / deallocate /
    allocate_sync / deallocate_sync methods and get_property friends
  • Test and benchmark mock resources use CCCL concepts directly

Current Architecture

Resources fall into two categories:

Stateless base resources (direct CCCL methods + thin do_allocate delegates)

  • cuda_memory_resource
  • managed_memory_resource
  • pinned_host_memory_resource
  • cuda_async_view_memory_resource
  • system_memory_resource

These already have public CCCL allocate(cuda::stream_ref, ...) methods
containing the real implementation. The do_allocate overrides are one-line
delegates. Removing the DMR leg is mechanical.

Dual-inheritance resources (device_memory_resource + cuda::mr::shared_resource<Impl>)

  • cuda_async_memory_resource
  • cuda_async_managed_memory_resource
  • sam_headroom_memory_resource
  • All 13 adaptor resources (pool, arena, fixed_size, binning, logging,
    statistics, tracking, limiting, failure_callback, aligned, thread_safe,
    prefetch, callback)

These use shared_resource<detail::*_impl> for the CCCL interface. The
device_memory_resource leg provides using declarations and do_* overrides
labeled "legacy compatibility layer". Removing the DMR leg requires exposing
the shared_resource methods publicly.

Tasks

1. Remove DMR inheritance from stateless base resources

Files:

  • cpp/include/rmm/mr/cuda_memory_resource.hpp
  • cpp/include/rmm/mr/managed_memory_resource.hpp
  • cpp/include/rmm/mr/pinned_host_memory_resource.hpp
  • cpp/include/rmm/mr/cuda_async_view_memory_resource.hpp
  • cpp/include/rmm/mr/system_memory_resource.hpp

Per file:

  • Remove : public device_memory_resource
  • Remove #include <rmm/mr/device_memory_resource.hpp>
  • Remove do_allocate, do_deallocate, do_is_equal
  • Verify operator== / operator!= on the concrete type
  • Verify get_property friend functions
  • Verify static_assert for cuda::mr::resource_with<...> and
    cuda::mr::synchronous_resource_with<...>

Must be completed before task 2 because stateful resources delegate to
stateless ones (cuda_async_memory_resource -> cuda_async_view_memory_resource,
sam_headroom_memory_resource -> system_memory_resource).

2. Remove DMR inheritance from stateful base resources

Files:

  • cpp/include/rmm/mr/cuda_async_memory_resource.hpp
    (+ detail/cuda_async_memory_resource_impl.hpp)
  • cpp/include/rmm/mr/cuda_async_managed_memory_resource.hpp (+ impl)
  • cpp/include/rmm/mr/sam_headroom_memory_resource.hpp (+ impl)

Per file:

  • Remove : public device_memory_resource
  • Remove using device_memory_resource::allocate; etc.
  • Remove do_allocate, do_deallocate, do_is_equal
  • Expose shared_resource<Impl> methods (change private inheritance to
    public, or add using shared_resource_base::allocate; etc.)
  • Verify operator== / operator!= and get_property friends
  • Verify static_assert

3. Remove DMR inheritance from all adaptors

Files: All 13 adaptor resource headers under cpp/include/rmm/mr/.

Same pattern as task 2. Each adaptor currently has a section labeled
// Begin legacy device_memory_resource compatibility layer -- remove that
entire section and expose the shared_resource<Impl> interface.

4. Remove DMR inheritance from stream_ordered_memory_resource

File: cpp/include/rmm/mr/detail/stream_ordered_memory_resource.hpp

This CRTP base inherits from both crtp<PoolResource> and
device_memory_resource. It provides the stream-ordering machinery (per-stream
free lists, CUDA event management, cross-stream synchronization) used by
pool_memory_resource_impl and fixed_size_memory_resource_impl.

The class itself must be kept -- it is actively inherited by both _impl classes.
The change is to remove its : public device_memory_resource inheritance and its
do_allocate / do_deallocate overrides. Its allocation logic currently lives in
those do_allocate / do_deallocate methods, so the implementation must be moved
into CCCL-compatible allocate(cuda::stream_ref, ...) /
deallocate(cuda::stream_ref, ...) methods (or renamed equivalents that the
_impl classes can call).

Per file:

  • Remove : public device_memory_resource
  • Remove #include <rmm/mr/device_memory_resource.hpp>
  • Rename/replace do_allocate / do_deallocate with CCCL-compatible
    allocate / deallocate signatures (stream-first, with alignment)
  • Add get_property friend and operator== if needed for the _impl
    classes to satisfy CCCL concepts through this base
  • Update pool_memory_resource_impl and fixed_size_memory_resource_impl
    if their relationship to this base changes

5. Update tests and benchmarks

Files:

  • cpp/tests/mock_resource.hpp -- rewrite to satisfy CCCL concepts directly
  • cpp/tests/device_check_resource_adaptor.hpp -- same
  • cpp/benchmarks/utilities/simulated_memory_resource.hpp -- same
  • All test files that use device_memory_resource* or do_allocate

Validation

  • build-rmm-cpp succeeds
  • All C++ tests pass (test-rmm-cpp)
  • grep -r do_allocate cpp/include/ returns no results (outside of
    device_memory_resource.hpp itself)
  • No resource class inherits from device_memory_resource

Note: device_memory_resource.hpp still exists at this point -- it is deleted in
the bridge infrastructure removal phase, after device_memory_resource_view (which
depends on it) is also removed.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    To-do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions