mxnet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] wkcn commented on a change in pull request #12047: [MXNET-779]Add DLPack Transformation API
Date Fri, 10 Aug 2018 01:32:01 GMT
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_r209124075
 
 

 ##########
 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:
   NDArray in MXNet and TVM are different. NDArray in TVM has the function `IncRef` and `DecRef`
to change the reference count, however that in MXNet uses `NDArray::ptr_` (std::shared_ptr<Chunk>)
to manage the reference count. `NDArray::ptr_` is a private member of `NDArray`.
   The PR is similar to the PyTorch DLPack implementation [Code](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/DLConvertor.cpp#L128)
   I add a `NDArrayDLManager` to manage the reference count of NDArray. [Code](https://github.com/apache/incubator-mxnet/pull/12047/files#diff-67d2910557c85e38570cd7c4f940cdbdR315)
line 315 in src/ndarray/ndarray.cc
   
   Setting `dlpack` as the NDArray(Python Class) member is to avoid the release of NDArrayDLManager,
e.g. When the original NDArray and the PyCapsule (DLPack) are release, the new NDArray (generated
by from_dlpack) still exists. 

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


With regards,
Apache Git Services

Mime
View raw message