rmm_resource_adaptor.hpp
1 
6 #pragma once
7 
8 #include <cstddef>
9 #include <cstdint>
10 
11 #include <cuda/memory_resource>
12 
13 #include <rmm/resource_ref.hpp>
14 
15 #include <rapidsmpf/detail/rmm_resource_adaptor_impl.hpp>
16 #include <rapidsmpf/memory/back_ref_mixin.hpp>
17 #include <rapidsmpf/memory/scoped_memory_record.hpp>
18 
19 namespace rapidsmpf {
20 class BufferResource;
21 
36  : public cuda::mr::shared_resource<detail::RmmResourceAdaptorImpl<
37  cuda::mr::any_resource<cuda::mr::device_accessible>>>,
38  public BackRefMixin<BufferResource> {
39  using any_device_resource = cuda::mr::any_resource<cuda::mr::device_accessible>;
40  using shared_base =
41  cuda::mr::shared_resource<detail::RmmResourceAdaptorImpl<any_device_resource>>;
42 
43  public:
45  friend void get_property(
46  RmmResourceAdaptor const&, cuda::mr::device_accessible
47  ) noexcept {}
48 
49  ~RmmResourceAdaptor() = default;
50 
62  [[nodiscard]] bool operator==(RmmResourceAdaptor const& other) const noexcept {
63  return get() == other.get();
64  }
65 
71  [[nodiscard]] rmm::device_async_resource_ref get_upstream_resource() const noexcept;
72 
80  [[nodiscard]] ScopedMemoryRecord get_main_record() const;
81 
87  [[nodiscard]] std::int64_t current_allocated() const noexcept;
88 
100 
124 
125  private:
126  // Only `BufferResource` may create the primary adaptor; all other instances
127  // are copies obtained via `BufferResource::device_mr_adaptor()`. This keeps
128  // the back-reference lifetime contract enforceable (see class docs).
129  friend class BufferResource;
130 
136  explicit RmmResourceAdaptor(
137  cuda::mr::any_resource<cuda::mr::device_accessible> primary_mr
138  );
139 };
140 
141 static_assert(cuda::mr::resource_with<RmmResourceAdaptor, cuda::mr::device_accessible>);
142 
143 } // namespace rapidsmpf
Mixin that lets copies of the this object keep an external object reference of type BackRef alive.
Class managing buffer resources.
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 through this resource.
rmm::device_async_resource_ref get_upstream_resource() const noexcept
Get a reference to the primary upstream resource.
ScopedMemoryRecord end_scoped_memory_record()
End the current scoped memory record and return it.
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.