statistics_resource_adaptor.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <rmm/detail/export.hpp>
8 #include <rmm/mr/detail/statistics_resource_adaptor_impl.hpp>
9 #include <rmm/resource_ref.hpp>
10 
11 #include <cuda/memory_resource>
12 
13 #include <cstddef>
14 #include <utility>
15 
16 namespace RMM_NAMESPACE {
17 namespace mr {
33  : public cuda::mr::shared_resource<detail::statistics_resource_adaptor_impl> {
34  using shared_base = cuda::mr::shared_resource<detail::statistics_resource_adaptor_impl>;
35 
36  public:
38  using counter = detail::statistics_resource_adaptor_impl::counter;
40  using read_lock_t = detail::statistics_resource_adaptor_impl::read_lock_t;
42  using write_lock_t = detail::statistics_resource_adaptor_impl::write_lock_t;
43 
47  RMM_CONSTEXPR_FRIEND void get_property(statistics_resource_adaptor const&,
48  cuda::mr::device_accessible) noexcept
49  {
50  }
51 
58  cuda::mr::any_resource<cuda::mr::device_accessible> upstream);
59 
60  ~statistics_resource_adaptor() = default;
61 
65  [[nodiscard]] device_async_resource_ref get_upstream_resource() const noexcept;
66 
72  [[nodiscard]] counter get_bytes_counter() const noexcept;
73 
79  [[nodiscard]] counter get_allocations_counter() const noexcept;
80 
86  std::pair<counter, counter> push_counters();
87 
94  std::pair<counter, counter> pop_counters();
95 };
96 
97 static_assert(cuda::mr::resource_with<statistics_resource_adaptor, cuda::mr::device_accessible>,
98  "statistics_resource_adaptor does not satisfy the cuda::mr::resource concept");
99  // end of group
101 } // namespace mr
102 } // namespace RMM_NAMESPACE
Resource that uses an upstream resource to allocate memory and tracks allocation statistics (current,...
Definition: statistics_resource_adaptor.hpp:33
detail::statistics_resource_adaptor_impl::read_lock_t read_lock_t
Shared-reader lock type used to protect the counter stack.
Definition: statistics_resource_adaptor.hpp:40
detail::statistics_resource_adaptor_impl::write_lock_t write_lock_t
Exclusive-writer lock type used to protect the counter stack.
Definition: statistics_resource_adaptor.hpp:42
statistics_resource_adaptor(cuda::mr::any_resource< cuda::mr::device_accessible > upstream)
Construct a statistics resource adaptor using upstream to satisfy allocation requests.
detail::statistics_resource_adaptor_impl::counter counter
Counter type tracking current, peak, and total bytes or allocations.
Definition: statistics_resource_adaptor.hpp:38
friend void get_property(statistics_resource_adaptor const &, cuda::mr::device_accessible) noexcept
Enables the cuda::mr::device_accessible property.
Definition: statistics_resource_adaptor.hpp:47
device_async_resource_ref get_upstream_resource() const noexcept
rmm::device_async_resource_ref to the upstream resource
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
Alias for a cuda::mr::resource_ref with the property cuda::mr::device_accessible.
Definition: resource_ref.hpp:30