tqchen commented on a change in pull request #12047: [MXNET-779]Add DLPack
Transformation API
URL: https://github.com/apache/incubator-mxnet/pull/12047#discussion_r209143790
##########
File path: src/c_api/c_api.cc
##########
@@ -494,6 +494,57 @@ int MXNDArrayGetData(NDArrayHandle handle,
API_END();
}
+int MXNDArrayToDLPack(NDArrayHandle handle,
+ DLManagedTensorHandle *out_dlpack) {
+ API_BEGIN();
+ NDArray *arr = static_cast<NDArray*>(handle);
+ *out_dlpack = arr->ToDLPack();
+ API_END();
+}
+
+int MXNDArrayFromDLPack(DLManagedTensorHandle dlpack,
+ NDArrayHandle *out_handle) {
+ API_BEGIN();
+ NDArray *pdata = new NDArray();
+ *pdata = NDArray::FromDLPack(
+ static_cast<DLManagedTensor*>(dlpack));
+ *out_handle = pdata;
+ API_END();
+}
+
+int MXNDArrayCallDLPackDeleter(DLManagedTensorHandle dlpack) {
+ API_BEGIN();
+ if (dlpack) {
+ DLManagedTensor *p_dlpack = static_cast<DLManagedTensor*>(dlpack);
+ p_dlpack->deleter(p_dlpack);
+ }
+ API_END();
+}
+
+
+typedef struct {
+ char py_object[16];
Review comment:
This seems to be dangerous unless pycapsule is already standardized and
won't change
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services