rmm.statistics#

class rmm.statistics.ProfilerRecords#

Bases: object

Records of the memory statistics recorded by a profiler.

Attributes:
records

Dictionary mapping record names to their memory statistics.

Methods

MemoryRecord([num_calls, memory_total, ...])

Memory statistics of a single code block.

add(name, data)

Add memory statistics to the record named name.

report([ordered_by])

Pretty format the recorded memory statistics.

class MemoryRecord(num_calls: int = 0, memory_total: int = 0, memory_peak: int = 0)#

Bases: object

Memory statistics of a single code block.

Attributes:
num_calls

Number of times this code block was invoked.

memory_total

Total number of bytes allocated.

memory_peak

Peak number of bytes allocated.

Methods

add

add(memory_total: int, memory_peak: int)#
memory_peak: int = 0#
memory_total: int = 0#
num_calls: int = 0#
add(name: str, data: Statistics) None#

Add memory statistics to the record named name.

This method is thread-safe.

Parameters:
name

Name of the record.

data

Memory statistics of name.

property records: dict[str, MemoryRecord]#

Dictionary mapping record names to their memory statistics.

report(ordered_by: Literal['num_calls', 'memory_peak', 'memory_total'] = 'memory_peak') str#

Pretty format the recorded memory statistics.

Parameters:
ordered_by

Sort the statistics by this attribute.

Returns:
The pretty formatted string of the memory statistics
class rmm.statistics.Statistics(current_bytes: int, current_count: int, peak_bytes: int, peak_count: int, total_bytes: int, total_count: int)#

Bases: object

Statistics returned by {get,push,pop}_statistics().

Attributes:
current_bytes

Current number of bytes allocated

current_count

Current number of allocations allocated

peak_bytes

Peak number of bytes allocated

peak_count

Peak number of allocations allocated

total_bytes

Total number of bytes allocated

total_count

Total number of allocations allocated

current_bytes: int#
current_count: int#
peak_bytes: int#
peak_count: int#
total_bytes: int#
total_count: int#
rmm.statistics.enable_statistics() None#

Enable allocation statistics.

This function is idempotent. If statistics have been enabled for the current RMM resource stack, this is a no-op.

Warning

This modifies the current RMM memory resource. StatisticsResourceAdaptor is pushed onto the current RMM memory resource stack and must remain the topmost resource throughout the statistics gathering.

rmm.statistics.get_statistics() Statistics | None#

Get the current allocation statistics.

Returns:
If enabled, returns the current tracked statistics.
If disabled, returns None.
rmm.statistics.pop_statistics() Statistics | None#

Pop the counters of the current allocation statistics stack.

This returns the counters of current tracked statistics and pops them from the stack.

If statistics are disabled (the current memory resource is not an instance of StatisticsResourceAdaptor), this function is a no-op.

Returns:
If enabled, returns the popped counters.
If disabled, returns None.
rmm.statistics.profiler(*, records: ProfilerRecords = ProfilerRecords({}), name: str = '')#

Decorator and context to profile function or code block.

If statistics are enabled (the current memory resource is an instance of StatisticsResourceAdaptor), this decorator records the memory statistics of the decorated function or code block.

If statistics are disabled, this decorator/context is a no-op.

Parameters:
records

The profiler records that the memory statistics are written to. If not set, a default profiler records are used.

name

The name of the memory profile, mandatory when the profiler is used as a context manager. If used as a decorator, an empty name is allowed. In this case, the name is the filename, line number, and function name.

rmm.statistics.push_statistics() Statistics | None#

Push new counters on the current allocation statistics stack.

This returns the current tracked statistics and pushes a new set of zero counters on the stack of statistics.

If statistics are disabled (the current memory resource is not an instance of StatisticsResourceAdaptor), this function is a no-op.

Returns:
If enabled, returns the current tracked statistics _before_ the pop.
If disabled, returns None.
rmm.statistics.statistics()#

Context to enable allocation statistics.

If statistics have been enabled already (the current memory resource is an instance of StatisticsResourceAdaptor), new counters are pushed on the current allocation statistics stack when entering the context and popped again when exiting using push_statistics() and push_statistics().

If statistics have not been enabled, a new StatisticsResourceAdaptor is set as the current RMM memory resource when entering the context and removed again when exiting.

Raises:
ValueError

If the current RMM memory source was changed while in the context.