samskalicky commented on a change in pull request #15921: dynamic custom 
operator support
URL: https://github.com/apache/incubator-mxnet/pull/15921#discussion_r336304389
 
 

 ##########
 File path: include/mxnet/lib_api.h
 ##########
 @@ -63,7 +211,46 @@ struct MXTensor {
   MXTensor() : data_ptr(NULL) {}
 
   MXTensor(void *data_ptr, const std::vector<int64_t> &shape, MXDType dtype)
-  : data_ptr(data_ptr), shape(shape), dtype(dtype) {}
+  : data_ptr(data_ptr), shape(shape), dtype(dtype) {
+    dltensor.data = data_ptr;
+    dltensor.ctx.device_type = kDLCPU;
+    dltensor.ctx.device_id = 0;
+    dltensor.ndim = shape.size();
+    dltensor.shape = const_cast<int64_t*>(shape.data());
+    dltensor.strides = NULL;
+    dltensor.byte_offset = 0;
+    dltensor.dtype.lanes = 1;
+    switch(dtype) {
+    case kFloat32:
+      dltensor.dtype.code = kDLFloat;
+      dltensor.dtype.bits = 32;
+      break;
+    case kFloat64:
+      dltensor.dtype.code = kDLFloat;
+      dltensor.dtype.bits = 64;
+      break;
+    case kFloat16:
+      dltensor.dtype.code = kDLFloat;
+      dltensor.dtype.bits = 16;
+      break;
+    case kUint8:
+      dltensor.dtype.code = kDLUInt;
+      dltensor.dtype.bits = 8;
+      break;
+    case kInt32:
+      dltensor.dtype.code = kDLInt;
+      dltensor.dtype.bits = 32;
+      break;
+    case kInt8:
+      dltensor.dtype.code = kDLInt;
+      dltensor.dtype.bits = 8;
+      break;
+    case kInt64:
+      dltensor.dtype.code = kDLInt;
+      dltensor.dtype.bits = 64;
 
 Review comment:
   What if we just do this:
   ```
   default:
         dltensor.dtype.code = 0;
         dltensor.dtype.bits = 0;
         std::cout << "Error! Invalid dtype flag: " << dtype << std::endl;
   ```
   Since we're not including any glog we cant do "LOG(FATAL)". 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to