chainer.function_hooks.CupyMemoryProfileHook

class chainer.function_hooks.CupyMemoryProfileHook[source]

Function hook for measuring memory usage of functions in cupy memory pool.

Example

Code example:

from chainer.function_hooks import CupyMemoryProfileHook
hook = CupyMemoryProfileHook()
with hook:
    trainer.run()
hook.print_report()

Output example:

       FunctionName  UsedBytes  AcquiredBytes  Occurrence
     LinearFunction     5.16GB       179.98MB        3900
               ReLU     0.99GB       458.97MB        2600
SoftmaxCrossEntropy     0.01GB         5.08MB        1300
           Accuracy     0.00GB         0.35MB         700

where FunctionName is the name of function that calls the hook, and UsedBytes is the memory bytes the function used from cupy memory pool, and AcquiredBytes is the actual memory bytes the cupy memory pool acquired from GPU device on the function call, and Occurrence is the number of calls.

Variables

~CupyMemoryProfileHook.call_history – List of measurement results. It consists of the name of the function that calls this hook, the memory bytes the function used from cupy memory pool, and the memory bytes the cupy memory pool acquired from GPU device on the function call.

Methods

__enter__()[source]
__exit__(*_)[source]
added(function=None)[source]

Callback function invoked when the function hook is registered

Parameters

function (FunctionNode) – Function object to which the function hook is added. None if the function hook is registered globally.

backward_postprocess(function, in_data, out_grad)[source]

Callback function invoked after backward propagation.

Parameters
backward_preprocess(function, in_data, out_grad)[source]

Callback function invoked before backward propagation.

Parameters
deleted(function=None)[source]

Callback function invoked when the function hook is unregistered

Parameters

function (FunctionNode) – Function object from which the function hook is deleted. None if the function hook was registered globally.

forward_postprocess(function, in_data)[source]

Callback function invoked after forward propagation.

Parameters
  • function (FunctionNode) – Function object to which the function hook is registered.

  • in_data (tuple of N-dimensional array) – Input data of forward propagation.

forward_preprocess(function, in_data)[source]

Callback function invoked before forward propagation.

Parameters
  • function (FunctionNode) – Function object to which the function hook is registered.

  • in_data (tuple of N-dimensional array) – Input data of forward propagation.

print_report(unit='auto', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Prints a summary report of memory profiling in functions.

Parameters

unit (str) – Supplementary units used for used memories. B, KB, MB, GB, TB, PB, EB, ZB, auto`(default) and `auto_foreach are supported. If auto, units of memories are aligned to the largest values of ‘used_bytes’ and ‘acquired_bytes’. If auto_foreach, units of memories are adjusted for each element.

summary()[source]

Returns a summary of memory profiling in functions.

Returns

A summarized dictionary whose keys are function names and values are dictionaries of used_bytes, acquired_bytes, and occurrrence.

total_acquired_bytes()[source]

Returns total bytes that cupy memory pool acquired from GPU.

total_used_bytes()[source]

Returns total bytes that functions used from cupy memory pool.

__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.

Attributes

name = 'CupyMemoryProfileHook'