Skip to content

Refactor pool_memory_resource to shared CCCL MR design - #2258

Merged
bdice merged 20 commits into
rapidsai:stagingfrom
bdice:refactor-pool-memory-resource
Feb 25, 2026
Merged

bdice merged 20 commits into
rapidsai:stagingfrom
bdice:refactor-pool-memory-resource

Conversation

@bdice

@bdice bdice commented Feb 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Convert pool_memory_resource from a templated, header-only class to a non-templated class using cuda::mr::shared_resource for reference-counted ownership. Implementation is now compiled into librmm.so.

This follows the same pattern established in #2246. Part of #2011.

Key changes

  • Remove template parameter (was pool_memory_resource<Upstream>)
  • Add pool_memory_resource_impl in rmm::mr::detail namespace
  • Remove Upstream* constructor overloads (use device_async_resource_ref)
  • Store upstream as any_resource for owning semantics
  • Use identity-based equality for the impl (distinct pools are never interchangeable)
  • Class is now copyable with shared ownership semantics
  • Temporarily keep device_memory_resource inheritance for Python compatibility
  • Remove POOL_MR_REF_TEST and PINNED_POOL_MR_REF_TEST (replaced by dedicated fixture-based tests)
  • Add dedicated PoolMemoryResourceTest fixture with tests for GetUpstreamResource, AllocateDeallocate, SharedOwnership, Equality, PoolSize

Breaking API changes

  1. Template removal: pool_memory_resource<Upstream> → pool_memory_resource
  2. Constructor changes: Removed Upstream* overloads, use device_async_resource_ref
  3. Equality semantics: Now identity-based (distinct pools are never equal, copies are equal)

Future changes

Once we migrate everything from using device_memory_resource to the CCCL MR design, we can drop the pieces of code labeled as legacy device_memory_resource compatibility layer.

@copy-pr-bot

copy-pr-bot Bot commented Feb 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@bdice
bdice marked this pull request as draft February 18, 2026 05:27
Extract pool_memory_resource_impl into detail header and source files,
rewrite pool_memory_resource as a non-template outer class with
private shared_resource inheritance. Update Cython bindings, tests,
and doc comment examples. Remove pool/pinned_pool mr_ref tests
(replaced by dedicated fixture-based tests in pool_mr_tests.cpp).

81/81 C++ tests pass, 1163/1163 Python tests pass.
@bdice
bdice force-pushed the refactor-pool-memory-resource branch from 7f067a6 to 64208e0 Compare February 20, 2026 21:10
@copy-pr-bot

copy-pr-bot Bot commented Feb 20, 2026

Copy link
Copy Markdown

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.

Replace the dropped mr_ref_pool_tests.cpp and mr_ref_pinned_pool_tests.cpp
with typed-test fixtures that construct resources by value and pass
device_async_resource_ref to shared helpers, eliminating the
device_memory_resource* factory indirection.

New headers cccl_mr_ref_test_basic.hpp, cccl_mr_ref_test_allocation.hpp,
and cccl_mr_ref_test_mt.hpp mirror the old mr_ref_test_*.hpp headers using
TYPED_TEST_SUITE_P so any converted adaptor can instantiate coverage with
a single fixture struct and three INSTANTIATE_TYPED_TEST_SUITE_P lines.

Extract mr_ref_test_mt.hpp helpers into mr_ref_test_mt_helpers.hpp so they
can be shared with cccl_mr_ref_test_mt.hpp without duplication. Add
#pragma once to byte_literals.hpp to prevent redefinition errors when
multiple new headers land in the same TU.
Add a new typed-test fixture CcclAdaptorTest covering all non-template,
shared_resource-based adaptors (currently logging_resource_adaptor and
pool_memory_resource) with Equality, GetUpstreamResource, AllocFree, and
SharedOwnership tests, plus CcclMrRefTest and CcclMrRefAllocationTest
instantiations.

Remove the bespoke LoggingAdaptorTest and LoggingMRFixture from
adaptor_tests.cpp, which is now strictly old-style (template) adaptors.
Remove the duplicated CcclMrRefTest and CcclMrRefAllocationTest
instantiations from pool_mr_tests.cpp, which retains only the
pool-specific tests and CcclMrRefTestMT.
@bdice
bdice marked this pull request as ready for review February 23, 2026 17:34
@bdice bdice moved this to In Progress in RMM Project Board Feb 23, 2026
Comment thread cpp/tests/CMakeLists.txt Resolved
@KyleFromNVIDIA KyleFromNVIDIA added breaking Breaking change improvement Improvement / enhancement to an existing function labels Feb 23, 2026
Move CcclMrRefTest/CcclMrRefAllocationTest/CcclMrRefTestMT instantiations
for pool_memory_resource into mr_ref_pool_tests.cpp and
CcclMrRefTest/CcclMrRefAllocationTest for pinned pool into
mr_ref_pinned_pool_tests.cpp, mirroring the structure of the old
string-parameterized pool ref test files they replace.

Remove pool ref-test instantiations from cccl_adaptor_tests.cpp (which now
owns only CcclAdaptorTest) and from pool_mr_tests.cpp and
pinned_host_pool_mr_tests.cpp. Restore POOL_MR_REF_TEST and
PINNED_POOL_MR_REF_TEST targets in CMakeLists.txt.
#endif

private:
cuda::mr::any_resource<cuda::mr::device_accessible> upstream_mr_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noting (as before), we should figure out a way for these objects to inherit the accessibility from the passed upstream mr. That way this pool could be used as an allocator for host memory if wanted (for example).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For example, CCCL provides a CTRP-friendly "forward_property" object

template <typename... Props>
struct my_pool_impl : cuda::forward_property<my_pool_impl<Props...>,
                                             cuda::mr::any_resource<Props...>> {
  using upstream_t = cuda::mr::any_resource<Props...>;

  my_pool_impl(cuda::mr::resource_ref<Props...> up) : upstream_{up} {}
  upstream_t &upstream_resource() { return upstream_; }
  upstream_t upstream_;
};

I was trying to think how you could make this and still have the public facing pool_memory_resource compiled into librmm.so. But I think that is not possible because the accessibility (and other) properties of a resource are compile time things.

So you can make pool_memory_resource generic over the accessibility of the upstream, but that genericity is part of the type.

@bdice bdice Feb 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm punting on this for now and noted it in #2011. All the adaptors will be hardcoded to be only device_accessible for now. I will refactor this to broaden the usability in a future refactoring.

This is not an immediate problem, as the pool is primarily used today for only device memory pools and pinned (host) pools, both of which are device_accessible.

// Each adaptor type must provide:
// - Value construction (no raw pointer upstream)
// - operator== with shared ownership semantics
// - get_upstream_resource()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As noted, the CCCL forward_property impl requires Upstream& upstream_resource() noexcept Perhaps we should standardise on that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As above, punting on this for now and noted it as a task in #2011.

Comment thread cpp/tests/mr/mr_ref_test_mt_helpers.hpp Resolved
Comment thread cpp/tests/mr/cccl_mr_ref_test_mt.hpp Resolved
@bdice bdice self-assigned this Feb 24, 2026
@bdice
bdice force-pushed the refactor-pool-memory-resource branch from 2913146 to e590fe1 Compare February 25, 2026 02:07
Comment on lines -85 to +39
template <typename Upstream>
class pool_memory_resource final
: public detail::
maybe_remove_property<pool_memory_resource<Upstream>, Upstream, cuda::mr::device_accessible>,
public detail::stream_ordered_memory_resource<pool_memory_resource<Upstream>,
detail::coalescing_free_list>,
public cuda::forward_property<pool_memory_resource<Upstream>, Upstream> {
class RMM_EXPORT pool_memory_resource
: public device_memory_resource,
private cuda::mr::shared_resource<detail::pool_memory_resource_impl> {
using shared_base = cuda::mr::shared_resource<detail::pool_memory_resource_impl>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, just to note, previously the pool was usable with an MR that was not device_accessible. Now that is no longer the case. But, as discussed, I think we can punt on this for now...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We don't have any MRs that aren't device_accessible. We removed host MRs a few releases ago.

Comment on lines -155 to 88
* @throws rmm::logic_error if `upstream_mr == nullptr`
* @throws rmm::logic_error if `initial_pool_size` is not aligned to a multiple of
* pool_memory_resource::allocation_alignment bytes.
* @throws rmm::logic_error if `initial_pool_size` is not aligned to a multiple of 256 bytes.
* @throws rmm::logic_error if `maximum_pool_size` is neither the default nor aligned to a
* multiple of pool_memory_resource::allocation_alignment bytes.
* multiple of 256 bytes.
*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did we deliberately remove the allocation_alignment slot?

@bdice bdice Feb 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we're requiring the pool to be aligned to CUDA_ALLOCATION_ALIGNMENT (256). The CCCL MR implementations require this alignment as well. https://github.com/NVIDIA/cccl/blob/5ba1022032c6eb90cd9838cc80f7813dad5e7011/libcudacxx/include/cuda/__memory_resource/properties.h#L35

If some use case needs to relax this later, we can. We just don't have any testing in place for other alignments and only need to support CUDA-friendly allocations right now.

@bdice
bdice merged commit 2d9955d into rapidsai:staging Feb 25, 2026
76 of 77 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in RMM Project Board Feb 25, 2026
bdice added a commit that referenced this pull request Feb 25, 2026
bdice added a commit to bdice/rmm that referenced this pull request Feb 25, 2026
…ared CCCL MR design

Converts both resources from header-only class templates to non-template
classes backed by detail::*_impl held via cuda::mr::shared_resource, following
the pattern established by logging_resource_adaptor (rapidsai#2246) and
pool_memory_resource (rapidsai#2258).

Part of rapidsai#2011.
bdice added a commit that referenced this pull request Feb 26, 2026
…ared CCCL MR design (#2264)

## Summary

Converts `fixed_size_memory_resource` and `binning_memory_resource` from
header-only class templates to non-template classes backed by a
`detail::*_impl` held via `cuda::mr::shared_resource`. Follows the
pattern established by `logging_resource_adaptor` (#2246) and
`pool_memory_resource` (#2258). Part of #2011.

## Changes

**New files (6)**
- `cpp/include/rmm/mr/detail/fixed_size_memory_resource_impl.hpp` — impl
class declaration; inherits `stream_ordered_memory_resource<impl,
fixed_size_free_list>` (same CRTP pattern as pool)
- `cpp/src/mr/detail/fixed_size_memory_resource_impl.cpp` — impl member
definitions
- `cpp/src/mr/fixed_size_memory_resource.cpp` — outer class constructor
and delegating methods
- `cpp/include/rmm/mr/detail/binning_memory_resource_impl.hpp` — impl
class declaration; includes `fixed_size_memory_resource.hpp` for
`unique_ptr` member
- `cpp/src/mr/detail/binning_memory_resource_impl.cpp` — impl member
definitions
- `cpp/src/mr/binning_memory_resource.cpp` — outer class constructor and
delegating methods

**Modified files (11)**
- `cpp/include/rmm/mr/fixed_size_memory_resource.hpp` — de-templated;
`shared_resource` inheritance; `device_async_resource_ref` constructor
only; `static_assert` for concept
- `cpp/include/rmm/mr/binning_memory_resource.hpp` — de-templated; same
pattern; `Upstream*` constructors removed
- `cpp/CMakeLists.txt` — four new `.cpp` files added to library sources
- `python/rmm/rmm/librmm/memory_resource.pxd` — template parameters
removed from both declarations
- `python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx` —
template instantiation syntax removed from `new` expressions
- `cpp/tests/mr/mr_ref_fixed_size_tests.cpp` — replaced string-factory
suite with typed `FixedSizeMRFixture` + `CcclMrRefTest`
- `cpp/tests/mr/mr_ref_binning_tests.cpp` — replaced string-factory
suites with typed `BinningMRFixture` + all three `CcclMrRef*` suites
- `cpp/tests/mr/mr_ref_test.hpp` — `make_fixed_size`/`make_binning`
factory helpers rewritten without `owning_wrapper`; type aliases
de-templated
- `cpp/tests/mr/binning_mr_tests.cpp` — removed explicit template
instantiation and `ThrowOnNullUpstream` (null pointer constructor no
longer exists); updated `ExplicitBinMR` to use
`device_async_resource_ref`
- `cpp/tests/mr/cccl_adaptor_tests.cpp` — added
`fixed_size_memory_resource` and `binning_memory_resource` to the
shared-ownership typed test suite
- `cpp/tests/mr/thrust_allocator_tests.cu` — removed `"Binning"` from
the string-dispatch parameterization (coverage moved to
`BINNING_MR_REF_*` typed suites; the old dispatch path caused a dangling
ref crash — the exact bug this PR fixes)

## Breaking changes

- `fixed_size_memory_resource<Upstream>` → `fixed_size_memory_resource`
(template parameter removed)
- `binning_memory_resource<Upstream>` → `binning_memory_resource`
(template parameter removed)
- `Upstream*` constructor overloads removed; use
`device_async_resource_ref`
- Both classes become copyable with shared ownership semantics

## Testing

`build-rmm-cpp -j0 && test-rmm-cpp`: 89/89 tests pass.
bdice added a commit that referenced this pull request Mar 6, 2026
## Summary

- De-template `arena_memory_resource` by removing the `Upstream`
template parameter
- Split implementation into `detail::arena_memory_resource_impl` held
via `cuda::mr::shared_resource` for reference-counted, copyable
ownership
- Retain the `device_memory_resource` legacy compatibility layer
(`do_allocate`, `do_deallocate`, `do_is_equal`)
- Update benchmarks, C++ tests, and Python (Cython) bindings to use the
non-template `arena_memory_resource`

This follows the same pattern established in #2246, #2258, #2264, and
#2265 for the other memory resources.

### New files

| File | Contents |
|------|----------|
| `cpp/include/rmm/mr/detail/arena_memory_resource_impl.hpp` |
`detail::arena_memory_resource_impl` class declaration |
| `cpp/src/mr/detail/arena_memory_resource_impl.cpp` | Impl member
function definitions |
| `cpp/src/mr/arena_memory_resource.cpp` | Outer class constructor +
delegating method definitions |

### Modified files

| File | Change |
|------|--------|
| `cpp/include/rmm/mr/arena_memory_resource.hpp` | De-template,
`shared_resource` wrapping |
| `cpp/CMakeLists.txt` | Add new `.cpp` source files |
| `cpp/tests/mr/arena_mr_tests.cpp` |
`arena_memory_resource<device_memory_resource>` →
`arena_memory_resource` |
| `cpp/tests/mr/mr_ref_arena_tests.cpp` | Add `ArenaMRFixture` +
`CcclMrRefTest`/`CcclMrRefAllocationTest`/`CcclMrRefTestMT`
instantiations |
| `cpp/tests/mr/mr_ref_test.hpp` | Update `make_arena()` and `arena_mr`
type alias |
| `cpp/tests/mr/cccl_adaptor_tests.cpp` | Add arena `static_assert` +
`ArenaMRAdaptorTest` |
|
`cpp/benchmarks/multi_stream_allocations/multi_stream_allocations_bench.cu`
| Update `make_arena()` |
| `cpp/benchmarks/random_allocations/random_allocations.cpp` | Update
`make_arena()` |
| `cpp/benchmarks/replay/replay.cpp` | Update `make_arena()` |
| `python/rmm/rmm/librmm/memory_resource.pxd` | Remove `[Upstream]`
template from `arena_memory_resource` |
| `python/rmm/rmm/pylibrmm/memory_resource/_memory_resource.pyx` |
Remove template instantiation syntax for arena |
@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.

4 participants