Public Types | Public Member Functions | List of all members
rapidsmpf::ScopedMemoryRecord Struct Reference

Memory statistics for a specific scope. More...

#include <rmm_resource_adaptor.hpp>

Public Types

enum class  AllocType : std::size_t { PRIMARY = 0 , FALLBACK = 1 , ALL = 2 }
 Allocation source types. More...
 
using AllocTypeArray = std::array< std::int64_t, 2 >
 Array type for storing per-allocator statistics.
 

Public Member Functions

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. More...
 
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. More...
 
std::int64_t current (AllocType alloc_type=AllocType::ALL) const noexcept
 Returns the current memory usage in bytes for the specified allocator type. More...
 
std::int64_t total (AllocType alloc_type=AllocType::ALL) const noexcept
 Returns the total number of bytes allocated. More...
 
std::int64_t peak (AllocType alloc_type=AllocType::ALL) const noexcept
 Returns the peak memory usage (in bytes) for the specified allocator type. More...
 
void record_allocation (AllocType alloc_type, std::int64_t nbytes)
 Records a memory allocation event. More...
 
void record_deallocation (AllocType alloc_type, std::int64_t nbytes)
 Records a memory deallocation event. More...
 
ScopedMemoryRecordadd_subscope (ScopedMemoryRecord const &subscope)
 Merge the memory statistics of a subscope into this record. More...
 
ScopedMemoryRecordadd_scope (ScopedMemoryRecord const &scope)
 Merge the memory statistics of another scope into this one. More...
 

Detailed Description

Memory statistics for a specific scope.

Note
Is trivially copyable.

Definition at line 29 of file rmm_resource_adaptor.hpp.

Member Enumeration Documentation

◆ AllocType

enum rapidsmpf::ScopedMemoryRecord::AllocType : std::size_t
strong

Allocation source types.

Enumerator
PRIMARY 

The primary allocator (first-choice allocator).

FALLBACK 

The fallback allocator (used when the primary fails).

ALL 

Aggregated statistics from both primary and fallback allocators.

Definition at line 31 of file rmm_resource_adaptor.hpp.

Member Function Documentation

◆ add_scope()

ScopedMemoryRecord& rapidsmpf::ScopedMemoryRecord::add_scope ( ScopedMemoryRecord const &  scope)

Merge the memory statistics of another scope into this one.

Unlike add_subscope(), this method treats the given scope as a peer or sibling, rather than a nested child. It aggregates totals and allocation counts and updates peak usage by taking the maximum peaks independently.

This is useful for combining memory statistics across multiple independent scopes, such as from different threads or non-nested regions.

Parameters
scopeThe scope to combine with this one.
Returns
Reference to this object after summing.
See also
add_subscope()

◆ add_subscope()

ScopedMemoryRecord& rapidsmpf::ScopedMemoryRecord::add_subscope ( ScopedMemoryRecord const &  subscope)

Merge the memory statistics of a subscope into this record.

Combines the memory tracking data from a nested scope (subscope) into this record, updating statistics to include the subscope's allocations, peaks, and totals.

This method treats the given record as a child scope nested within this scope, so peak usage is updated considering the current usage plus the subscope's peak, reflecting hierarchical (inclusive) memory usage accounting.

This design allows memory scopes to be organized hierarchically, so when querying a parent scope, its statistics are inclusive of all nested scopes — similar to hierarchical memory profiling tools. However, it assumes that the parent scope's statistics remain constant during the execution of the subscope.

Parameters
subscopeThe scoped memory record representing a completed nested region.
Returns
Reference to this object after merging the subscope.
See also
add_scope()

◆ current()

std::int64_t rapidsmpf::ScopedMemoryRecord::current ( AllocType  alloc_type = AllocType::ALL) const
noexcept

Returns the current memory usage in bytes for the specified allocator type.

Current usage is the total bytes currently allocated but not yet deallocated.

Parameters
alloc_typeThe allocator type to query. Use AllocType::ALL to return the sum across all types.
Returns
The current memory usage in bytes for the specified type.

◆ num_current_allocs()

std::int64_t rapidsmpf::ScopedMemoryRecord::num_current_allocs ( AllocType  alloc_type = AllocType::ALL) const
noexcept

Returns the number of currently active (non-deallocated) allocations for the specified allocator type.

This reflects the number of allocations that have not yet been deallocated.

Parameters
alloc_typeThe allocator type to query. Use AllocType::ALL to return the sum across all types.
Returns
The number of active allocations for the specified type.

◆ num_total_allocs()

std::int64_t rapidsmpf::ScopedMemoryRecord::num_total_allocs ( AllocType  alloc_type = AllocType::ALL) const
noexcept

Returns the total number of allocations performed by the specified allocator type.

Parameters
alloc_typeThe allocator type to query. Use AllocType::ALL to return the sum across all types.
Returns
The number of allocations for the specified type.

◆ peak()

std::int64_t rapidsmpf::ScopedMemoryRecord::peak ( AllocType  alloc_type = AllocType::ALL) const
noexcept

Returns the peak memory usage (in bytes) for the specified allocator type.

The peak represents the highest value reached by current memory usage over the lifetime of the allocator. It does not decrease after deallocations.

When queried with AllocType::ALL, this returns the highest combined memory usage ever observed across both primary and fallback allocators, not the sum of individual peaks.

Parameters
alloc_typeThe allocator type to query. Defaults to AllocType::ALL.
Returns
The peak memory usage in bytes for the specified type.

◆ record_allocation()

void rapidsmpf::ScopedMemoryRecord::record_allocation ( AllocType  alloc_type,
std::int64_t  nbytes 
)

Records a memory allocation event.

Updates the allocation counters and memory usage statistics, and adjusts peak usage if the new current usage exceeds the previous peak.

Parameters
alloc_typeThe allocator that performed the allocation.
nbytesThe number of bytes allocated.
Note
Is not thread-safe.

◆ record_deallocation()

void rapidsmpf::ScopedMemoryRecord::record_deallocation ( AllocType  alloc_type,
std::int64_t  nbytes 
)

Records a memory deallocation event.

Reduces the current memory usage for the specified allocator.

Parameters
alloc_typeThe allocator that performed the deallocation.
nbytesThe number of bytes deallocated.
Note
Is not thread-safe.

◆ total()

std::int64_t rapidsmpf::ScopedMemoryRecord::total ( AllocType  alloc_type = AllocType::ALL) const
noexcept

Returns the total number of bytes allocated.

This value accumulates over time and is not reduced by deallocations.

Parameters
alloc_typeThe allocator type to query. Use AllocType::ALL to return the sum across all types.
Returns
The total number of bytes allocated for the specified type.

The documentation for this struct was generated from the following file: