cuquantum.custatevec.set_device_mem_handler

cuquantum.custatevec.set_device_mem_handler(intptr_t handle, handler)[源代码]

为 cuStateVec 设置设备内存处理程序。

handler 对象可以通过多种方式传入

  • 如果 handler 是一个 int,它指的是完全初始化的 custatevecDeviceMemHandler_t 结构体的地址。

  • 如果 handler 是一个 Python 序列

    • 如果 handler 是长度为 4 的序列,它被解释为 (ctx, device_alloc, device_free, name),其中前三个元素是对应成员的指针地址 (int)。 name 是一个 str,作为处理程序的名称。

    • 如果 handler 是长度为 3 的序列,它被解释为 (malloc, free, name),其中前两个对象是具有以下调用约定的 Python *可调用对象*

      • ptr = malloc(size, stream)

      • free(ptr, size, stream)

      所有参数和返回值 (ptr) 都是 Python intname 与上面相同。

注意

仅当 handler 是长度为 3 的序列时,当例程需要内存分配和释放时,GIL 才会被持有,因此对于所有其他情况,请确保您的 handler 不会操作任何 Python 对象。

参数
  • handle (intptr_t) – 库句柄。

  • handler – 内存处理程序对象,请参阅上文。