Repository navigation
Migrate RMM usage to CCCL MR design - #22008
Conversation
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
|
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. |
- 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)
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.
…ny_resource ownership, remove dead code
… restore comments
3c59fd5 to
5b82ce0
Compare
… type in prior_cudf_pinned_mr
…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.
6b32863 to
f23cb04
Compare
f23cb04 to
f3ff31b
Compare
revans2
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_implclasses hold all non-copyable state, including upstream memory resources.adaptorclasses hold a shared pointer to theirimplclass (through inheriting fromcuda::mr::shared_resource<adaptor_impl>) and dispatch all methods to theimpl. This is essentially a PImpl pattern. These are copyable and copies will share the sameimplinstance.
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; |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
@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.
f3ff31b to
08386ee
Compare
# 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
|
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.
|
|
Cosigned, admin merging |
## 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
## 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
## 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]>
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
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
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
## 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]>
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
…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
Summary
device_memory_resource*withdevice_async_resource_refacross all C++ headers, sources, benchmarks, examples, and tests..pxddeclarations, changedevice_memory_resource *mrparameters todevice_async_resource_ref mr(value type). In.pyxfiles, replacemr.get_mr()calls withmr.c_ref.value().cudf::set_current_device_resource(pointer-based) wrapper, keeping only the ref-basedset_current_device_resource_ref. Update return types ofset/reset_current_device_resource_reftocuda::mr::any_resource<cuda::mr::device_accessible>.host_memory.cpp, removedevice_memory_resourceinheritance frompinned_pool_with_fallback_memory_resource, remove the forward declaration workaround forrmm::mr::pool_memory_resource(no longer templated), and wrap non-copyable state inshared_ptrto satisfy theany_resourcecopyability requirement.Part of rapidsai/rmm#2011.
Depends on rapidsai/rmm#2361.