cuquantum.cutensornet.set_device_mem_handler(intptr_t handle, handler)[source]

Set the device memory handler for cuTensorNet.

The handler object can be passed in multiple ways:

  • If handler is an int, it refers to the address of a fully initialized cutensornetDeviceMemHandler_t struct.

  • If handler is a Python sequence:

    • If handler is a sequence of length 4, it is interpreted as (ctx, device_alloc, device_free, name), where the first three elements are the pointer addresses (int) of the corresponding members. name is a str as the name of the handler.

    • If handler is a sequence of length 3, it is interpreted as (malloc, free, name), where the first two objects are Python callables with the following calling convention:

      • ptr = malloc(size, stream)

      • free(ptr, size, stream)

      with all arguments and return value (ptr) being Python int. name is the same as above.


Only when handler is a length-3 sequence will the GIL be held whenever a routine requires memory allocation and deallocation, so for all other cases be sure your handler does not manipulate any Python objects.

  • handle (intptr_t) – The library handle.

  • handler – The memory handler object, see above.