-
Notifications
You must be signed in to change notification settings - Fork 245
Description
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, ordo_is_equalmethods exist anywhere device_memory_resource.hppis deleted- All resources satisfy CCCL concepts via their own
allocate/deallocate/
allocate_sync/deallocate_syncmethods andget_propertyfriends - 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_resourcemanaged_memory_resourcepinned_host_memory_resourcecuda_async_view_memory_resourcesystem_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_resourcecuda_async_managed_memory_resourcesam_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.hppcpp/include/rmm/mr/managed_memory_resource.hppcpp/include/rmm/mr/pinned_host_memory_resource.hppcpp/include/rmm/mr/cuda_async_view_memory_resource.hppcpp/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_propertyfriend functions - Verify
static_assertforcuda::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 (changeprivateinheritance to
public, or addusing shared_resource_base::allocate;etc.) - Verify
operator==/operator!=andget_propertyfriends - 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_deallocatewith CCCL-compatible
allocate/deallocatesignatures (stream-first, with alignment) - Add
get_propertyfriend andoperator==if needed for the_impl
classes to satisfy CCCL concepts through this base - Update
pool_memory_resource_implandfixed_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 directlycpp/tests/device_check_resource_adaptor.hpp-- samecpp/benchmarks/utilities/simulated_memory_resource.hpp-- same- All test files that use
device_memory_resource*ordo_allocate
Validation
build-rmm-cppsucceeds- All C++ tests pass (
test-rmm-cpp) grep -r do_allocate cpp/include/returns no results (outside of
device_memory_resource.hppitself)- 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
- [FEA] Migrate base memory resources to native CCCL interface #2287 (base resource migration -- partially addresses this)
- [FEA] Support memory resources from CCCL 3.2 #2011 (parent tracking issue)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status