Skip to content

Refactor fixed_size_memory_resource and binning_memory_resource to shared CCCL MR design#2264

Merged
bdice merged 3 commits intorapidsai:stagingfrom
bdice:detemplate-fixed-size-binning
Feb 26, 2026
Merged

Refactor fixed_size_memory_resource and binning_memory_resource to shared CCCL MR design#2264
bdice merged 3 commits intorapidsai:stagingfrom
bdice:detemplate-fixed-size-binning

Conversation

@bdice
Copy link
Copy Markdown
Collaborator

@bdice bdice commented Feb 25, 2026

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.hppmake_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.

…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.
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Feb 25, 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.

auto cuda_async_mr = make_cuda_async();
// Add a binning_memory_resource with fixed-size bins of sizes 256, 512, 1024, 2048 and 4096KiB
// Larger allocations will use the CUDA async resource
// Larger allocations will use the current device resource
Copy link
Copy Markdown
Collaborator Author

@bdice bdice Feb 26, 2026

Choose a reason for hiding this comment

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

We should avoid current device resource usage in these tests. Maybe we can use rmm::mr::cuda_memory_resource.

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.

This isn't going to work cleanly until we finish the CCCL migration. We can create a ref via device_memory_resource_view but that has issues with lifetimes until we use CCCL refs properly. Marking this as a TODO in #2011.

@bdice bdice self-assigned this Feb 26, 2026
@bdice bdice added breaking Breaking change improvement Improvement / enhancement to an existing function labels Feb 26, 2026
@bdice bdice moved this to In Progress in RMM Project Board Feb 26, 2026
@bdice bdice marked this pull request as ready for review February 26, 2026 13:01
@bdice bdice requested review from a team as code owners February 26, 2026 13:01
@bdice bdice requested review from PointKernel and miscco and removed request for a team February 26, 2026 13:01
@bdice
Copy link
Copy Markdown
Collaborator Author

bdice commented Feb 26, 2026

I self-reviewed this PR which was all generated code. I'm going to merge this soon, all seems aligned with my expectations from the past two migration PRs.

@bdice bdice merged commit 97c8488 into rapidsai:staging Feb 26, 2026
155 of 163 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in RMM Project Board Feb 26, 2026
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 |
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.

1 participant