From 0d4e7f88ade76a10eefd225b89bc01ffea935771 Mon Sep 17 00:00:00 2001 From: jinlianchao185874 <35051541+jinlianchao185874@users.noreply.github.com> Date: Sat, 26 Dec 2020 20:15:25 +0800 Subject: [PATCH 1/2] Create dlpack_1.py --- mindspore/numpy/dlpack_1.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mindspore/numpy/dlpack_1.py diff --git a/mindspore/numpy/dlpack_1.py b/mindspore/numpy/dlpack_1.py new file mode 100644 index 00000000000..234230bdd7a --- /dev/null +++ b/mindspore/numpy/dlpack_1.py @@ -0,0 +1,33 @@ +DLManagedTensor* toDLPack(constTensor& src){ +ATenDLMTensor * atDLMTensor(newATenDLMTensor); + +atDLMTensor->handle = src; + +atDLMTensor->tensor.manager_ctx = atDLMTensor; + +atDLMTensor->tensor.deleter = &deleter; + +atDLMTensor->tensor.dl_tensor.data = src.data_ptr(); + +int64_tdevice_id = 0; + +if(src.type().is_cuda()) { +device_id = src.get_device(); + +} + +atDLMTensor->tensor.dl_tensor.ctx = getDLContext(src.type(), device_id); + +atDLMTensor->tensor.dl_tensor.ndim = src.dim( +); +atDLMTensor->tensor.dl_tensor.dtype = getDLDataType(src.type()); + +atDLMTensor->tensor.dl_tensor.shape = const_cast< int64_t*>(src.sizes().data()); + +atDLMTensor->tensor.dl_tensor.strides = const_cast< int64_t*>(src.strides().data()); + +atDLMTensor->tensor.dl_tensor.byte_offset = 0; + +return&(atDLMTensor->tensor); + +} From 52d7ef4913e209a589df7ffa78235ffef6a8b9bf Mon Sep 17 00:00:00 2001 From: jinlianchao185874 <35051541+jinlianchao185874@users.noreply.github.com> Date: Sat, 26 Dec 2020 20:33:12 +0800 Subject: [PATCH 2/2] Update dlpack_1.py --- mindspore/numpy/dlpack_1.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mindspore/numpy/dlpack_1.py b/mindspore/numpy/dlpack_1.py index 234230bdd7a..f77daaa70bf 100644 --- a/mindspore/numpy/dlpack_1.py +++ b/mindspore/numpy/dlpack_1.py @@ -31,3 +31,13 @@ return&(atDLMTensor->tensor); } + + +DLPack FromDLPack(DLtensor){ +DLtensor dltensor; +dltensor.data* = mindsporeTensor.data; +dltensor.ndim = mindsporeTensor.ndim; +dltensor.dtype = mindsporeTensor.dtype; +dltensor.shape* = mindsporeTensor.shape; +dltensor.stride* = mindsporeTensor.stride; +}