-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Feature request: share memory between numpy.array and mxnet.ndarray #14244
Comments
I will take a look this weekend. |
Hey, I did some research this weekend and am convinced it might be possible. So is it acceptable if we assume we are using cython (instead of ctypes) @szha |
@junrushao1994 could you elaborate on the consideration? |
The point is that we need transfer/share ownership of numpy's ndarray to mxnet's C++ backend, because we cannot guarantee the frontend object to exist forever. Therefore, we need a customized deleter of MXNet's NDArray, aka calling something Per private discussion with @reminisce, his concern is how this could be compatible with the executor and memory planning, in which the executor may take over the ownership. I am not sure about this. |
For the sharing from numpy to NDArray, we should use ctypes or weakref module add the inference of numpy object, and decrease the inference through NDArray::deleter. For the sharing from NDArray to numpy, I think we can add a deleter attribute for numpy object. https://docs.scipy.org/doc/numpy/user/basics.subclassing.html?highlight=deleter |
Agreed with @wkcn |
I prototyped a version that supports zero copy from numpy to DLManagedTensor in dlpack 0.2, but it turns out that MXNet hasn’t support dlpack 0.2 yet... |
We can update the submodule dlpack. |
@wkcn I opened a PR about this to dmlc/dlpack#38. |
@wkcn Sorry I made a mistake. @reminisce reminded me that we already got dlpack 0.2 in MXNet, so everything should be fine |
In the submodule DLPack, DLPACK_VERSION is 010 rather than 020. |
I think it is suitable to add a new argument. NDArray to NumPya = mx.nd.array([1,2,3]) NumPy to NDArrayc = np.array([4,5]) |
I think adding a parameter to the existing API may introduce certain level of ambiguity which is not desirable. For example, |
@reminisce Sounds good. Will do! |
Thx. |
Last time I did a benchmark and @szha pointed out that
This is a safe choice but sometimes it can be a performance problem. I check the C API and find no function to share data from outside. Is it possible for MXNet to provide such api?
The text was updated successfully, but these errors were encountered: