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
mallocandfreemethods 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
withstatement.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
hookis the name of hook point, anddevice_idis the CUDA Device ID, andsizeis the requested memory size to allocate, andmem_sizeis the rounded memory size to be allocated, andmem_ptris the memory pointer, andpmem_idis 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 isTrue.
Methods
- __enter__(self)#
- __exit__(self, *_)#
- alloc_postprocess(self, **kwargs)[source]#
Callback function invoked after allocating memory from GPU device.
- alloc_preprocess(self, **kwargs)#
Callback function invoked before allocating memory from GPU device.
- free_postprocess(self, **kwargs)[source]#
Callback function invoked after releasing memory to memory pool.
- free_preprocess(self, **kwargs)#
Callback function invoked before releasing memory to memory pool.
- malloc_postprocess(self, **kwargs)[source]#
Callback function invoked after retrieving memory from memory pool.
- Keyword Arguments:
- malloc_preprocess(self, **kwargs)#
Callback function invoked before retrieving memory from 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 = 'DebugPrintHook'#