22 #include <shared_mutex>
44 template <
typename Upstream>
49 std::shared_lock<std::shared_timed_mutex>;
51 std::unique_lock<std::shared_timed_mutex>;
97 RMM_EXPECTS(
nullptr != upstream,
"Unexpected null upstream resource pointer.");
129 return upstream_->supports_get_mem_info();
176 void* ptr = upstream_->allocate(bytes, stream);
197 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
199 upstream_->deallocate(ptr, bytes, stream);
217 bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
219 if (
this == &other) {
return true; }
220 auto cast =
dynamic_cast<statistics_resource_adaptor<Upstream> const*
>(&other);
221 return cast !=
nullptr ? upstream_->is_equal(*cast->get_upstream())
222 : upstream_->is_equal(other);
233 std::pair<std::size_t, std::size_t> do_get_mem_info(cuda_stream_view stream)
const override
235 return upstream_->get_mem_info(stream);
239 counter allocations_;
240 std::shared_timed_mutex
mutable mtx_;
252 template <
typename Upstream>
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:89
Resource that uses Upstream to allocate memory and tracks statistics on memory allocations.
Definition: statistics_resource_adaptor.hpp:45
std::shared_lock< std::shared_timed_mutex > read_lock_t
Type of lock used to synchronize read access.
Definition: statistics_resource_adaptor.hpp:49
bool supports_streams() const noexcept override
Checks whether the upstream resource supports streams.
Definition: statistics_resource_adaptor.hpp:120
statistics_resource_adaptor(statistics_resource_adaptor &&) noexcept=default
Default move constructor.
std::unique_lock< std::shared_timed_mutex > write_lock_t
Type of lock used to synchronize write access.
Definition: statistics_resource_adaptor.hpp:51
bool supports_get_mem_info() const noexcept override
Query whether the resource supports the get_mem_info API.
Definition: statistics_resource_adaptor.hpp:127
statistics_resource_adaptor(Upstream *upstream)
Construct a new statistics resource adaptor using upstream to satisfy allocation requests.
Definition: statistics_resource_adaptor.hpp:95
counter get_allocations_counter() const noexcept
Returns a counter struct for this adaptor containing the current, peak, and total number of allocatio...
Definition: statistics_resource_adaptor.hpp:153
counter get_bytes_counter() const noexcept
Returns a counter struct for this adaptor containing the current, peak, and total number of allocated...
Definition: statistics_resource_adaptor.hpp:139
Upstream * get_upstream() const noexcept
Pointer to the upstream resource.
Definition: statistics_resource_adaptor.hpp:112
statistics_resource_adaptor< Upstream > make_statistics_adaptor(Upstream *upstream)
Convenience factory to return a statistics_resource_adaptor around the upstream resource upstream.
Definition: statistics_resource_adaptor.hpp:253
Utility struct for counting the current, peak, and total value of a number.
Definition: statistics_resource_adaptor.hpp:55
counter & operator-=(int64_t val)
Subtract val from the current value and update the peak value if necessary.
Definition: statistics_resource_adaptor.hpp:80
int64_t value
Current value.
Definition: statistics_resource_adaptor.hpp:56
int64_t peak
Max value of value
Definition: statistics_resource_adaptor.hpp:57
counter & operator+=(int64_t val)
Add val to the current value and update the peak value if necessary.
Definition: statistics_resource_adaptor.hpp:66
int64_t total
Sum of all added values.
Definition: statistics_resource_adaptor.hpp:58