14 #include <type_traits>
15 #include <unordered_map>
16 #include <unordered_set>
18 #include <rmm/error.hpp>
88 [[nodiscard]] std::int64_t
total(
178 std::int64_t highest_peak_{0};
182 std::is_trivially_copyable_v<ScopedMemoryRecord>,
183 "ScopedMemoryRecord must be trivially copyable"
203 std::optional<rmm::device_async_resource_ref> fallback_mr = std::nullopt
205 : primary_mr_{primary_mr}, fallback_mr_{fallback_mr} {}
226 [[nodiscard]] std::optional<rmm::device_async_resource_ref>
298 void* do_allocate(std::
size_t bytes,
rmm::cuda_stream_view stream) override;
308 void* ptr, std::
size_t bytes,
rmm::cuda_stream_view stream
319 [[nodiscard]]
bool do_is_equal(
321 ) const noexcept override;
323 mutable std::mutex mutex_;
326 std::unordered_set<
void*> fallback_allocations_;
333 std::unordered_map<
void*, std::thread::
id> allocating_threads_;
A RMM memory resource adaptor tailored to RapidsMPF.
RmmResourceAdaptor(rmm::device_async_resource_ref primary_mr, std::optional< rmm::device_async_resource_ref > fallback_mr=std::nullopt)
Construct with specified primary and optional fallback memory resource.
void begin_scoped_memory_record()
Begin recording a new scoped memory usage record for the current thread.
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.
device_memory_resource(device_memory_resource const &)=default
detail::cccl_async_resource_ref< cuda::mr::resource_ref< cuda::mr::device_accessible > > device_async_resource_ref
Memory statistics for a specific scope.
ScopedMemoryRecord & add_subscope(ScopedMemoryRecord const &subscope)
Merge the memory statistics of a subscope into this record.
void record_allocation(AllocType alloc_type, std::int64_t nbytes)
Records a memory allocation event.
std::array< std::int64_t, 2 > AllocTypeArray
Array type for storing per-allocator statistics.
std::int64_t peak(AllocType alloc_type=AllocType::ALL) const noexcept
Returns the peak memory usage (in bytes) for the specified allocator type.
void record_deallocation(AllocType alloc_type, std::int64_t nbytes)
Records a memory deallocation event.
AllocType
Allocation source types.
@ PRIMARY
The primary allocator (first-choice allocator).
@ ALL
Aggregated statistics from both primary and fallback allocators.
@ FALLBACK
The fallback allocator (used when the primary fails).
ScopedMemoryRecord & add_scope(ScopedMemoryRecord const &scope)
Merge the memory statistics of another scope into this one.
std::int64_t total(AllocType alloc_type=AllocType::ALL) const noexcept
Returns the total number of bytes allocated.
std::int64_t num_current_allocs(AllocType alloc_type=AllocType::ALL) const noexcept
Returns the number of currently active (non-deallocated) allocations for the specified allocator type...
std::int64_t current(AllocType alloc_type=AllocType::ALL) const noexcept
Returns the current memory usage in bytes for the specified allocator type.
std::int64_t num_total_allocs(AllocType alloc_type=AllocType::ALL) const noexcept
Returns the total number of allocations performed by the specified allocator type.