Repository navigation
Refactor pool_memory_resource to shared CCCL MR design - #2258
Conversation
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.
7f067a6 to
64208e0
Compare
|
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.
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_; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
As noted, the CCCL forward_property impl requires Upstream& upstream_resource() noexcept Perhaps we should standardise on that?
There was a problem hiding this comment.
As above, punting on this for now and noted it as a task in #2011.
…g MRs" This reverts commit 29274ec.
2913146 to
e590fe1
Compare
| 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>; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
We don't have any MRs that aren't device_accessible. We removed host MRs a few releases ago.
| * @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. | ||
| * |
There was a problem hiding this comment.
Did we deliberately remove the allocation_alignment slot?
There was a problem hiding this comment.
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.
…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.
…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.
## 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 |
Summary
Convert
pool_memory_resourcefrom a templated, header-only class to a non-templated class usingcuda::mr::shared_resourcefor reference-counted ownership. Implementation is now compiled intolibrmm.so.This follows the same pattern established in #2246. Part of #2011.
Key changes
pool_memory_resource<Upstream>)pool_memory_resource_implinrmm::mr::detailnamespaceUpstream*constructor overloads (usedevice_async_resource_ref)any_resourcefor owning semanticsdevice_memory_resourceinheritance for Python compatibilityPOOL_MR_REF_TESTandPINNED_POOL_MR_REF_TEST(replaced by dedicated fixture-based tests)PoolMemoryResourceTestfixture with tests forGetUpstreamResource,AllocateDeallocate,SharedOwnership,Equality,PoolSizeBreaking API changes
pool_memory_resource<Upstream>→pool_memory_resourceUpstream*overloads, usedevice_async_resource_refFuture changes
Once we migrate everything from using
device_memory_resourceto the CCCL MR design, we can drop the pieces of code labeled aslegacy device_memory_resource compatibility layer.