rmm_resource_adaptor.hpp
1 
6 #pragma once
7 
8 #include <cstddef>
9 #include <cstdint>
10 #include <optional>
11 
12 #include <cuda/memory_resource>
13 
14 #include <rmm/resource_ref.hpp>
15 
16 #include <rapidsmpf/detail/rmm_resource_adaptor_impl.hpp>
17 #include <rapidsmpf/memory/scoped_memory_record.hpp>
18 
19 namespace rapidsmpf {
20 
32  : public cuda::mr::shared_resource<detail::RmmResourceAdaptorImpl<
33  cuda::mr::any_resource<cuda::mr::device_accessible>>> {
34  using any_device_resource = cuda::mr::any_resource<cuda::mr::device_accessible>;
35  using shared_base =
36  cuda::mr::shared_resource<detail::RmmResourceAdaptorImpl<any_device_resource>>;
37 
38  public:
40  friend void get_property(
41  RmmResourceAdaptor const&, cuda::mr::device_accessible
42  ) noexcept {}
43 
51  cuda::mr::any_resource<cuda::mr::device_accessible> primary_mr,
52  std::optional<cuda::mr::any_resource<cuda::mr::device_accessible>> fallback_mr =
53  std::nullopt
54  );
55 
56  ~RmmResourceAdaptor() = default;
57 
66  [[nodiscard]] bool operator==(RmmResourceAdaptor const& other) const noexcept {
67  return get() == other.get();
68  }
69 
75  [[nodiscard]] rmm::device_async_resource_ref get_upstream_resource() const noexcept;
76 
84  [[nodiscard]] std::optional<rmm::device_async_resource_ref>
85  get_fallback_resource() const noexcept;
86 
94  [[nodiscard]] ScopedMemoryRecord get_main_record() const;
95 
101  [[nodiscard]] std::int64_t current_allocated() const noexcept;
102 
114 
138 };
139 
140 static_assert(cuda::mr::resource_with<RmmResourceAdaptor, cuda::mr::device_accessible>);
141 
142 } // namespace rapidsmpf
A RMM memory resource adaptor tailored to RapidsMPF.
void begin_scoped_memory_record()
Begin recording a new scoped memory usage record for the current thread.
bool operator==(RmmResourceAdaptor const &other) const noexcept
Equality comparison.
ScopedMemoryRecord get_main_record() const
Returns a copy of the main memory record.
std::int64_t current_allocated() const noexcept
Get the total current allocated memory from both primary and fallback.
rmm::device_async_resource_ref get_upstream_resource() const noexcept
Get a reference to the primary upstream resource.
std::optional< rmm::device_async_resource_ref > get_fallback_resource() const noexcept
Get a reference to the fallback upstream resource.
ScopedMemoryRecord end_scoped_memory_record()
End the current scoped memory record and return it.
RmmResourceAdaptor(cuda::mr::any_resource< cuda::mr::device_accessible > primary_mr, std::optional< cuda::mr::any_resource< cuda::mr::device_accessible >> fallback_mr=std::nullopt)
Construct with specified primary and optional fallback memory resource.
friend void get_property(RmmResourceAdaptor const &, cuda::mr::device_accessible) noexcept
Tag this resource as device-accessible for the CCCL concept.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
RAPIDS Multi-Processor interfaces.
Definition: backend.hpp:14
Memory statistics for a specific scope.