wkcn commented on a change in pull request #12047: [MXNET-779]Add DLPack 
Transformation API
URL: https://github.com/apache/incubator-mxnet/pull/12047#discussion_r208824421
 
 

 ##########
 File path: python/mxnet/_ctypes/ndarray.py
 ##########
 @@ -31,21 +31,24 @@
 
 class NDArrayBase(object):
     """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):
 
 Review comment:
   The dlpack in NDArray is PyCapsule which is the return value of 
`to_dlpack_for_read/write`.
   When calling `FromDLPack` function, NDArray need to manage the release of 
`NDArrayDLManager::handle` in `ndarray.cc`.
   e.g.
   ```
   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
   # a and PyCapsule pack has been released.
   # b need to manage the release TBlob x.
   ```
   NDArray doesn't have the deleter function, so I made dlpack as a member of 
NDArray.
   When the reference count of dlpack in NDArray is zero, the TBlob will be 
released.
   Is there any other way to keep the reference?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to