-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1406] [BUG] Fix DLManagedTensor deleter #15016
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4156,7 +4156,7 @@ def from_dlpack(dlpack): | |
assert ctypes.pythonapi.PyCapsule_IsValid(dlpack, _c_str_dltensor), ValueError( | ||
'Invalid DLPack Tensor. DLTensor capsules can be consumed only once.') | ||
dlpack_handle = ctypes.c_void_p(ctypes.pythonapi.PyCapsule_GetPointer(dlpack, _c_str_dltensor)) | ||
check_call(_LIB.MXNDArrayFromDLPack(dlpack_handle, ctypes.byref(handle))) | ||
check_call(_LIB.MXNDArrayFromDLPack(dlpack_handle, False, ctypes.byref(handle))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It means deleter will free it |
||
# Rename PyCapsule (DLPack) | ||
ctypes.pythonapi.PyCapsule_SetName(dlpack, _c_str_used_dltensor) | ||
# delete the deleter of the old dlpack | ||
|
@@ -4262,8 +4262,6 @@ def _make_dl_managed_tensor(array): | |
if not ndarray.flags['C_CONTIGUOUS']: | ||
raise ValueError("Only c-contiguous arrays are supported for zero-copy") | ||
c_obj = _make_dl_managed_tensor(ndarray) | ||
address = ctypes.addressof(c_obj) | ||
address = ctypes.cast(address, ctypes.c_void_p) | ||
handle = NDArrayHandle() | ||
check_call(_LIB.MXNDArrayFromDLPack(address, ctypes.byref(handle))) | ||
check_call(_LIB.MXNDArrayFromDLPack(ctypes.byref(c_obj), True, ctypes.byref(handle))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the handle here is transient handle? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bc the DLManagedTensor here is freed immediately after this call |
||
return NDArray(handle=handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before calling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is false, the DLManagedTensor handle won't be freed after the call, and deleter will free it.
If it is true, the DLManagedTensor handle will be freed by the caller.