cupy.cuda.PythonFunctionAllocator#

class cupy.cuda.PythonFunctionAllocator(malloc_func, free_func)[source]#

Allocator with python functions to perform memory allocation.

This allocator keeps functions corresponding to malloc and free, delegating the actual allocation to external sources while only handling the timing of the resource allocation and deallocation.

malloc should follow the signature malloc(int, int) -> int returning the pointer to the allocated memory given the param object, the number of bytes to allocate and the device id on which the allocation should take place.

Similarly, free should follow the signature free(int, int) with no return, taking the pointer to the allocated memory and the device id on which the memory was allocated.

If the external memory management supports asynchronous operations, the current CuPy stream can be retrieved inside malloc_func and free_func by calling cupy.cuda.get_current_stream(). To use external streams, wrap them with cupy.cuda.ExternalStream().

Parameters
  • malloc_func (function) – malloc function to be called.

  • free_func (function) – free function to be called.

Methods

malloc(self, size_t size) MemoryPointer#
__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.