Skip to content

Migrate RMM usage to CCCL MR design - #22008

Merged
gforsyth merged 35 commits into
NVIDIA:mainfrom
bdice:rmm-cccl-migration
Apr 21, 2026
Merged

gforsyth merged 35 commits into
NVIDIA:mainfrom
bdice:rmm-cccl-migration

Conversation

@bdice

@bdice bdice commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace device_memory_resource* with device_async_resource_ref across all C++ headers, sources, benchmarks, examples, and tests.
  • In Cython .pxd declarations, change device_memory_resource *mr parameters to device_async_resource_ref mr (value type). In .pyx files, replace mr.get_mr() calls with mr.c_ref.value().
  • Remove cudf::set_current_device_resource (pointer-based) wrapper, keeping only the ref-based set_current_device_resource_ref. Update return types of set/reset_current_device_resource_ref to cuda::mr::any_resource<cuda::mr::device_accessible>.
  • In host_memory.cpp, remove device_memory_resource inheritance from pinned_pool_with_fallback_memory_resource, remove the forward declaration workaround for rmm::mr::pool_memory_resource (no longer templated), and wrap non-copyable state in shared_ptr to satisfy the any_resource copyability requirement.

Part of rapidsai/rmm#2011.
Depends on rapidsai/rmm#2361.

Replace device_memory_resource* with device_async_resource_ref across
all C++ headers, sources, benchmarks, examples, and tests. In Cython
.pxd declarations, change device_memory_resource *mr parameters to
device_async_resource_ref mr (value type). In .pyx files, replace
mr.get_mr() calls with mr.c_ref.value().

Remove cudf::set_current_device_resource (pointer-based) wrapper,
keeping only the ref-based set_current_device_resource_ref. Update
return types of set/reset_current_device_resource_ref to
cuda::mr::any_resource<cuda::mr::device_accessible>.

In host_memory.cpp, remove device_memory_resource inheritance from
pinned_pool_with_fallback_memory_resource, remove the forward
declaration workaround for rmm::mr::pool_memory_resource (no longer
templated), and wrap non-copyable state in shared_ptr to satisfy
the any_resource copyability requirement.

Part of rapidsai/rmm#2011
@copy-pr-bot

copy-pr-bot Bot commented Apr 3, 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.

@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. Python Affects Python cuDF API. pylibcudf Issues specific to the pylibcudf package labels Apr 3, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Apr 3, 2026
bdice added 3 commits April 4, 2026 17:43
- Add jni_rmm_resource.hpp with type-erased resource wrapper and
  raw_resource_map for tracking resources that can't use any_resource
- Refactor tracking_resource_adaptor to use shared_ptr pattern for
  CCCL copyability requirements
- Refactor java_event_handler_memory_resource to use impl + wrapper
  pattern with shared_ptr for non-copyable JNI handles
- Apply RMM naming conventions (upstream_ instead of upstream_mr)
- Store device_async_resource_ref in adaptors (non-owning, JNI manages
  resource lifetimes through Java)
@github-actions github-actions Bot added the Java Affects Java cuDF API. label Apr 13, 2026
bdice added 10 commits April 13, 2026 07:19
Simplify the JNI memory resource layer to align with modern C++ and
CCCL design patterns:

- Remove raw_resource_map, its mutex, and callback-based approach
- Use make_jni_resource/delete_jni_resource consistently for all resources
- Store tracking_resource_adaptor values in map (shared_ptr semantics)
- Eliminate get_*_ref callback functions in favor of direct calls
The jni_resource_wrapper class was unnecessary indirection since
any_resource already provides type-erasure. Simplified to directly
heap-allocate any_resource objects.
pool_memory_resource stores its upstream in any_resource (owning),
so there's no need for a wrapper to keep the upstream alive.
@copy-pr-bot

copy-pr-bot Bot commented Apr 14, 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 force-pushed the rmm-cccl-migration branch from 3c59fd5 to 5b82ce0 Compare April 14, 2026 19:32
bdice added 2 commits April 14, 2026 16:29
…source

pool_memory_resource inherits from cuda::mr::shared_resource which is
internally shared_ptr-based, so copies are cheap and share the same
underlying pool. No need for raw pointer indirection.
@bdice
bdice force-pushed the rmm-cccl-migration branch 2 times, most recently from 6b32863 to f23cb04 Compare April 17, 2026 21:07
@bdice
bdice force-pushed the rmm-cccl-migration branch from f23cb04 to f3ff31b Compare April 18, 2026 15:18

@revans2 revans2 left a comment

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.

I did a partial pass through it, but there is som much that changed in RmmJni.cpp that I don't feel confident without spending a lot more time in it.

*/
template <typename Upstream>
class tracking_resource_adaptor final : public base_tracking_resource_adaptor {
class tracking_resource_adaptor_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.

Could you help me understand some of the design decisions here? Like why did we have to move away from inheritance to a wrapper around an impl? Is it https://github.com/rapidsai/cudf/pull/22008/changes#r3102512850. Did we have bugs in our code from before or does the new CCCL/RMM no longer treat this as a singleton and copy things all over the place?

@bdice bdice Apr 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are two parts worth addressing here.

Why no inheritance?
CCCL defines memory resources with C++ concepts, not by inheritance. Rather than inherit from rmm::mr::device_memory_resource, memory resources must implement a specific API and we verify it with compile-time checks like static_assert(cuda::mr::resource_with<tracking_resource_adaptor_impl, cuda::mr::device_accessible>);.

Why have an impl?
RMM adaptors have historically held their upstream resource by reference. To eliminate this source of lifetime problems (which has plagued memory resource users in all libraries), we are now making all resources (and adaptors) hold any state, including upstream resources, with shared-like ownership. Furthermore, CCCL resources must be copyable as a design requirement. The combination of copyable + by-value semantics motivates the design you see for adaptors (resources which allocate through an upstream):

  • adaptor_impl classes hold all non-copyable state, including upstream memory resources.
  • adaptor classes hold a shared pointer to their impl class (through inheriting from cuda::mr::shared_resource<adaptor_impl>) and dispatch all methods to the impl. This is essentially a PImpl pattern. These are copyable and copies will share the same impl instance.

Stateless resources (those with no upstream and no internal state, like rmm::mr::cuda_memory_resource) are trivially copyable and do not have shared-like semantics because it's not necessary.

// Map to store tracking adaptors for metrics access.
// tracking_resource_adaptor is copyable (via shared_ptr to impl), so copies share state.
std::mutex tracking_adaptor_map_mutex;
std::unordered_map<jlong, tracking_resource_adaptor> tracking_adaptor_map;

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.

These really shouldn't be directly in the global scope like this, they should be encapsulated. E.g. grouped together into a class with emplace/erase defined, and an instance of this created statically & returned in a function like prior_cudf_pinned_mr().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pmattione-nvidia Would you be able to help refactor that in this PR, or a follow-up PR after this merges? I would really appreciate a hand, given the number of projects I am supporting with this migration.

bdice and others added 3 commits April 21, 2026 07:10
# Conflicts:
#	cpp/include/cudf/detail/utilities/vector_factories.hpp
#	cpp/include/cudf/io/parquet_io_utils.hpp
#	cpp/src/groupby/hash/compute_groupby.hpp
#	cpp/src/interop/from_arrow_stream.cu
#	cpp/src/io/parquet/experimental/deletion_vectors.cu
#	cpp/src/io/parquet/io_utils/parquet_io_utils.cpp
#	cpp/src/io/utilities/output_builder.cuh
#	cpp/src/rolling/detail/optimized_unbounded_window.hpp
#	cpp/src/transform/compute_column.cu
@bdice

bdice commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

This PR will fix the currently broken builds. I discussed with @gforsyth and we will admin-merge.

The failures are either expected or not related to this change.

  • There is a segfault in C++ tests on benchmark teardown -- this needs to be diagnosed, and I've asked the team for help
  • Python tests appear to be failing with a dictionary ordering difference, possibly due to pyarrow 24 released this morning? This seems like not a blocker for us to fix builds.
=========================== short test summary info ============================
FAILED reshape/test_concat.py::test_concat_struct_column - AssertionError: 
Items are not equal:
 ACTUAL: StructDtype({'a': dtype('int64'), 'c': dtype('O'), 'b': dtype('int64')})
 DESIRED: StructDtype({'a': dtype('int64'), 'b': dtype('int64'), 'c': dtype('O')})
=== 1 failed, 78438 passed, 19508 skipped, 1144 xfailed in 267.52s (0:04:27) ===
  • Spark builds will require updates to Spark-RAPIDS
  • rapidsmpf tests will require rebuilds of rapidsmpf

@gforsyth

Copy link
Copy Markdown
Contributor

Cosigned, admin merging

@gforsyth
gforsyth merged commit 24217de into NVIDIA:main Apr 21, 2026
29 of 30 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Apr 21, 2026
rapids-bot Bot pushed a commit to rapidsai/rapidsmpf that referenced this pull request Apr 21, 2026
## Summary

- Rewrite `RmmResourceAdaptor` as a thin shell inheriting `cuda::mr::shared_resource<detail::RmmResourceAdaptorImpl>`, with all mutable state in the impl class for copyable shared ownership.
- Replace `device_memory_resource*` with `rmm::device_async_resource_ref` for non-owning references and `cuda::mr::any_resource` for owning storage.
- Remove `rmm::mr::owning_wrapper` usage (removed in RMM 26.06).
- Update `pool_memory_resource` usage (no longer a template; upstream passed as `device_async_resource_ref`).
- Replace `set_current_device_resource(ptr)` with `set_current_device_resource_ref(ref)`.
- Update test resources to satisfy CCCL resource concept (`allocate_sync`, `deallocate_sync`, `operator==`, `get_property`).
- Update Cython bindings (`.pxd`/`.pyx`) to use `device_async_resource_ref` instead of `device_memory_resource`.
- Point `get_cucascade.cmake` to local cuCascade source directory (companion cuCascade PR: NVIDIA/cuCascade#98).

Depends on rapidsai/rmm#2361.
Depends on rapidsai/ucxx#636.
Depends on NVIDIA/cudf#22008.

## Notes

- Depends on cuCascade migration: NVIDIA/cuCascade#98
- The `get_cucascade.cmake` change to use `SOURCE_DIR` is a development convenience and should be updated to point to the merged cuCascade commit before this PR is finalized.

Authors:
  - Bradley Dice (https://github.com/bdice)
  - Niranda Perera (https://github.com/nirandaperera)

Approvers:
  - Niranda Perera (https://github.com/nirandaperera)
  - Peter Andreas Entschev (https://github.com/pentschev)

URL: #940
rapids-bot Bot pushed a commit to NVIDIA/cuCascade that referenced this pull request Apr 22, 2026
## Summary

- Migrate all cuCascade memory resource classes from `rmm::mr::device_memory_resource` virtual inheritance to the CCCL-native resource concept (`allocate`/`deallocate` with `cuda::stream_ref`, `allocate_sync`/`deallocate_sync`, `operator==`, `get_property`).
- Replace `unique_ptr<device_memory_resource>` owning storage with `cuda::mr::any_resource<cuda::mr::device_accessible>`.
- Update `memory_space::get_default_allocator()` to return `device_async_resource_ref` from the `any_resource`.
- Update `pool_memory_resource` usage (no longer a template in RMM 26.06; upstream passed as `device_async_resource_ref`).
- Move `memory_reservation.hpp` template bodies (`get_memory_resource_as<T>()`, `get_memory_resource_of<Tier>()`) to `memory_space.hpp` to avoid incomplete-type errors.
- Remove allocator null-checks in GPU and HOST `memory_space` constructors — `any_resource` is a value type and cannot be null.
- Update internal converter helpers in `representation_converter.cpp` to accept `rmm::device_async_resource_ref` instead of raw `rmm::mr::device_memory_resource*`.
- Update test utilities (`shared_device_resource`, `logging_device_resource`, `make_mock_memory_space`) for the new resource concept.
- Pre-commit formatting pass on files touched by the merge with upstream/main.

Depends on NVIDIA/cudf#22008.

## Affected classes

- `null_device_memory_resource`
- `numa_region_pinned_host_allocator`
- `fixed_size_host_memory_resource`
- `reservation_aware_resource_adaptor`
- `small_pinned_host_memory_resource`
- `memory_space`

## Notes

- Companion to the rapidsmpf migration PR.
- `cuda::stream_ref{cudaStream_t{nullptr}}` in `allocate_sync`/`deallocate_sync` implementations may produce deprecation warnings. These do not break the build because the `WARNINGS_AS_ERRORS` CMake guard on line 80 checks the wrong variable name (`WARNINGS_AS_ERRORS` vs the option `CUCASCADE_WARNINGS_AS_ERRORS`), so `-Werror` is currently not enabled.
- Pre-commit reformatted several files that were untouched by the migration but modified by the upstream merge (`cuda_utils.hpp`, `test_data_batch.cpp`, `test_data_representation.cpp`, `benchmark_representation_converter.cpp`, `data_batch.hpp`). These are whitespace/include-order changes only.

Authors:
  - Bradley Dice (https://github.com/bdice)
  - Niranda Perera (https://github.com/nirandaperera)

Approvers:
  - Niranda Perera (https://github.com/nirandaperera)
  - Matthijs Brobbel (https://github.com/mbrobbel)

URL: #98
pxLi pushed a commit to NVIDIA/cudf-spark-jni that referenced this pull request Apr 28, 2026
## Summary

This PR migrates spark-rapids-jni's usage of RMM memory resources to
align with the new design from CCCL.

This will remain a draft until all RAPIDS libraries (particularly cuDF)
are updated. The changes will be API breaking, so both cuDF and RMM will
need to be updated in parallel.

There are also JNI changes in
NVIDIA/cudf#22008 that are needed here.

Note: This change also includes a switch to the build scripts to use
`gcc-toolset-13` instead of `gcc-toolset-14`. This is to work around the
crashes in `nvcc-12.9` when coupled with `gcc-14`. This will need to be
switched back to `14` after CUDA Toolkit 12.9 is fixed.

Part of rapidsai/rmm#2011.
Depends on NVIDIA/cudf#22008.

---------

Signed-off-by: MithunR <[email protected]>
Co-authored-by: MithunR <[email protected]>
rapids-bot Bot pushed a commit that referenced this pull request Apr 29, 2026
After #22008, `cudf::set_current_device_resource()` returns the previous resource as an owning `any_resource`. `memory_stats_logger` discarded that return value and held a non-owning `device_async_resource_ref` to the now-destroyed pool, causing a segfault on the next allocation (e.g. `GROUPBY_NVBENCH -b 4` crashed on iteration 2).

### Follow-up

Mark RMM's `set_*/reset_*_device_resource` `[[nodiscard]]` so this misuse fails at compile time.

Authors:
  - Yunsong Wang (https://github.com/PointKernel)
  - https://github.com/apps/pre-commit-ci

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Muhammad Haseeb (https://github.com/mhaseeb123)
  - David Wendt (https://github.com/davidwendt)

URL: #22333
vyasr pushed a commit to vyasr/cudf that referenced this pull request May 4, 2026
After NVIDIA#22008, `cudf::set_current_device_resource()` returns the previous resource as an owning `any_resource`. `memory_stats_logger` discarded that return value and held a non-owning `device_async_resource_ref` to the now-destroyed pool, causing a segfault on the next allocation (e.g. `GROUPBY_NVBENCH -b 4` crashed on iteration 2).

### Follow-up

Mark RMM's `set_*/reset_*_device_resource` `[[nodiscard]]` so this misuse fails at compile time.

Authors:
  - Yunsong Wang (https://github.com/PointKernel)
  - https://github.com/apps/pre-commit-ci

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Muhammad Haseeb (https://github.com/mhaseeb123)
  - David Wendt (https://github.com/davidwendt)

URL: NVIDIA#22333
meta-codesync Bot pushed a commit to facebookincubator/velox that referenced this pull request May 6, 2026
Summary:
This PR migrates Velox's usage of RMM memory resources to align with the new design from CCCL.

Part of rapidsai/rmm#2011.
Depends on NVIDIA/cudf#22008.

Pull Request resolved: #17178

Reviewed By: peterenescu

Differential Revision: D104066468

Pulled By: kgpai

fbshipit-source-id: 0724c5599807e4c145f4498595b2d4c6cbab2bf9
shrshi pushed a commit to shrshi/cudf that referenced this pull request May 12, 2026
## Summary

- Replace `device_memory_resource*` with `device_async_resource_ref`
across all C++ headers, sources, benchmarks, examples, and tests.
- In Cython `.pxd` declarations, change `device_memory_resource *mr`
parameters to `device_async_resource_ref mr` (value type). In `.pyx`
files, replace `mr.get_mr()` calls with `mr.c_ref.value()`.
- Remove `cudf::set_current_device_resource` (pointer-based) wrapper,
keeping only the ref-based `set_current_device_resource_ref`. Update
return types of `set/reset_current_device_resource_ref` to
`cuda::mr::any_resource<cuda::mr::device_accessible>`.
- In `host_memory.cpp`, remove `device_memory_resource` inheritance from
`pinned_pool_with_fallback_memory_resource`, remove the forward
declaration workaround for `rmm::mr::pool_memory_resource` (no longer
templated), and wrap non-copyable state in `shared_ptr` to satisfy the
`any_resource` copyability requirement.

Part of rapidsai/rmm#2011.
Depends on rapidsai/rmm#2361.

---------

Co-authored-by: Gil Forsyth <[email protected]>
shrshi pushed a commit to shrshi/cudf that referenced this pull request May 12, 2026
After NVIDIA#22008, `cudf::set_current_device_resource()` returns the previous resource as an owning `any_resource`. `memory_stats_logger` discarded that return value and held a non-owning `device_async_resource_ref` to the now-destroyed pool, causing a segfault on the next allocation (e.g. `GROUPBY_NVBENCH -b 4` crashed on iteration 2).

### Follow-up

Mark RMM's `set_*/reset_*_device_resource` `[[nodiscard]]` so this misuse fails at compile time.

Authors:
  - Yunsong Wang (https://github.com/PointKernel)
  - https://github.com/apps/pre-commit-ci

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Muhammad Haseeb (https://github.com/mhaseeb123)
  - David Wendt (https://github.com/davidwendt)

URL: NVIDIA#22333
Alan-S-Andrade pushed a commit to Alan-S-Andrade/velox that referenced this pull request Jun 2, 2026
…7178)

Summary:
This PR migrates Velox's usage of RMM memory resources to align with the new design from CCCL.

Part of rapidsai/rmm#2011.
Depends on NVIDIA/cudf#22008.

Pull Request resolved: facebookincubator#17178

Reviewed By: peterenescu

Differential Revision: D104066468

Pulled By: kgpai

fbshipit-source-id: 0724c5599807e4c145f4498595b2d4c6cbab2bf9
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 Java Affects Java cuDF API. libcudf Affects libcudf (C++/CUDA) code. pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants