@tqchen 
Hi! What should I do next for this PR?
For the release of DLPack,
here are the implements of TVM, PyTorch and Cupy.

[TVM 
src/runtime/ndarray.cc#L148](https://github.com/dmlc/tvm/blob/master/src/runtime/ndarray.cc#L148)
```c++
NDArray NDArray::FromDLPack(DLManagedTensor* tensor) {
  NDArray::Container* data = new NDArray::Container();
  data->deleter = Internal::DLPackDeleter;
  data->manager_ctx = tensor;
  data->dl_tensor = tensor->dl_tensor;
  return NDArray(data);
}
```

[PyTorch 
aten/src/ATen/DLConvertor.cpp#L170](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/DLConvertor.cpp#L170)
```C++
Tensor fromDLPack(const DLManagedTensor* src) {
  Backend backend = getATenBackend(src->dl_tensor.ctx);
  ScalarType stype = toScalarType(src->dl_tensor.dtype);
  auto deleter = [src](void * self) {
    src->deleter(const_cast<DLManagedTensor*>(src));
  };
  return getType(backend, stype).tensorFromBlob(
      src->dl_tensor.data,
      IntList(src->dl_tensor.shape, src->dl_tensor.ndim),
      IntList(src->dl_tensor.strides, src->dl_tensor.ndim),
      deleter);
}
```

[CuPy 
cupy/core/dlpack.pyx#L231](https://github.com/cupy/cupy/blob/master/cupy/core/dlpack.pyx#L231)
```python
mem = DLPackMemory(dltensor)
mem_ptr = memory.MemoryPointer(mem, mem.dlm_tensor.dl_tensor.byte_offset)
cupy_array = ndarray(shape_vec, cp_dtype, mem_ptr)
```

The all NDArray save the deleter of dlpack or DLManagedTensor.

So I added a new member `dlpack` for mx.nd.NDArray (Python) for store of dlpack.
When the NDArray release, the dlpack will call the deleter.
Dose NDArray(C++) manage the release of dltensor?

[ Full content available at: 
https://github.com/apache/incubator-mxnet/pull/12047 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to