wkcn commented on a change in pull request #12047: [MXNET-779]Add DLPack
File path: python/mxnet/_ctypes/ndarray.py
@@ -31,21 +31,24 @@
"""Base data structure for ndarray"""
- __slots__ = ["handle", "writable"]
+ __slots__ = ["handle", "writable", "dlpack"]
# pylint: disable= no-member
- def __init__(self, handle, writable=True):
+ def __init__(self, handle, writable=True, dlpack=None):
Sorry. I don't know which object manages the actual memory after from_dlpack
In the following code,
a = mx.nd.array([1,2,3]) # Denote TBlob x to store the data
pack = a.to_dlpack_for_write()
b = mx.nd.from_dlpack(pack)
del a, pack
The original NDArray `a` and dlpack are released. However, the Manager
`NDArrayDLManager` should be kept.
The new NDArray `b` get the data pointer from DLPack.
Which object will call the deleter?
In PyTorch, the Tensor class has the deleter structrual parameter.
When the refcount of Tensor is zero, the Tensor Object will call the deleter
to release `ATenDLMTensor`.
MXNet doesn't have the explicit deleter structual parameter.
So I set `dlpack` as the member of NDArray (Python) class.
When the refcount of NDArray is zero, the refcount of dlpack in NDArray is
The dlpack will be released then call the deleter to delete
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
Apache Git Services