cupy.cuda.memory_hooks.DebugPrintHook#

class cupy.cuda.memory_hooks.DebugPrintHook(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, flush=True)[source]#

Memory hook that prints debug information.

This memory hook outputs the debug information of input arguments of malloc and free methods involved in the hooked functions at postprocessing time (that is, just after each method is called).

Example

The basic usage is to use it with with statement.

Code example:

>>> import cupy
>>> from cupy.cuda import memory_hooks
>>>
>>> cupy.cuda.set_allocator(cupy.cuda.MemoryPool().malloc)
>>> with memory_hooks.DebugPrintHook():
...     x = cupy.array([1, 2, 3])
...     del x  

Output example:

{"hook":"alloc","device_id":0,"mem_size":512,"mem_ptr":150496608256}
{"hook":"malloc","device_id":0,"size":24,"mem_size":512,"mem_ptr":150496608256,"pmem_id":"0x7f39200c5278"}
{"hook":"free","device_id":0,"mem_size":512,"mem_ptr":150496608256,"pmem_id":"0x7f39200c5278"}

where the output format is JSONL (JSON Lines) and hook is the name of hook point, and device_id is the CUDA Device ID, and size is the requested memory size to allocate, and mem_size is the rounded memory size to be allocated, and mem_ptr is the memory pointer, and pmem_id is the pooled memory object ID.

Variables:
  • file – Output file_like object that redirect to.

  • flush – If True, this hook forcibly flushes the text stream at the end of print. The default is True.

Methods

__enter__(self)#
__exit__(self, *_)#
alloc_postprocess(self, **kwargs)[source]#

Callback function invoked after allocating memory from GPU device.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • mem_size (int) – Rounded memory bytesize allocated

  • mem_ptr (int) – Obtained memory pointer. 0 if an error occurred in allocation.

alloc_preprocess(self, **kwargs)#

Callback function invoked before allocating memory from GPU device.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • mem_size (int) – Rounded memory bytesize to be allocated

free_postprocess(self, **kwargs)[source]#

Callback function invoked after releasing memory to memory pool.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • mem_size (int) – Memory bytesize

  • mem_ptr (int) – Memory pointer to free

  • pmem_id (int) – Pooled memory object ID.

free_preprocess(self, **kwargs)#

Callback function invoked before releasing memory to memory pool.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • mem_size (int) – Memory bytesize

  • mem_ptr (int) – Memory pointer to free

  • pmem_id (int) – Pooled memory object ID.

malloc_postprocess(self, **kwargs)[source]#

Callback function invoked after retrieving memory from memory pool.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • size (int) – Requested memory bytesize to allocate

  • mem_size (int) – Rounded memory bytesize allocated

  • mem_ptr (int) – Obtained memory pointer. 0 if an error occurred in malloc.

  • pmem_id (int) – Pooled memory object ID. 0 if an error occurred in malloc.

malloc_preprocess(self, **kwargs)#

Callback function invoked before retrieving memory from memory pool.

Keyword Arguments:
  • device_id (int) – CUDA device ID

  • size (int) – Requested memory bytesize to allocate

  • mem_size (int) – Rounded memory bytesize to be allocated

__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 = 'DebugPrintHook'#