reminisce commented on a change in pull request #17530: Add deferred compute 
support
URL: https://github.com/apache/incubator-mxnet/pull/17530#discussion_r378673220
 
 

 ##########
 File path: src/c_api/c_api_ndarray.cc
 ##########
 @@ -428,3 +436,42 @@ int MXCachedOpRegisterOpHook(NDArrayHandle handle,
   op->RegisterOpHook(clbk, monitor_all);
   API_END();
 }
+
+int MXNDArrayIsDeferredComputeEnabled(int *curr) {
+  API_BEGIN();
+  *curr = Imperative::Get()->is_deferred_compute();
+  API_END();
+}
+
+int MXNDArraySetDeferredComputeEnabled(int deferred_compute, int *prev) {
+  API_BEGIN();
+  *prev = 
Imperative::Get()->set_is_deferred_compute(static_cast<bool>(deferred_compute));
+  API_END();
+}
+
+int MXNDArrayGetDeferredComputeSymbol(NDArrayHandle *input_handles,
+                                      NDArrayHandle *output_handles,
+                                      const char **c_input_names,
+                                      int num_inputs,
+                                      int num_outputs, SymbolHandle *out) {
+  API_BEGIN();
+
+  // Obtain the NDArrays and their names
+  std::vector<std::pair<NDArray*, std::string>> inputs;
+  std::vector<NDArray *> outputs;
+  inputs.reserve(num_inputs);
+  outputs.reserve(num_outputs);
+  for (int i = 0; i < num_inputs; ++i) {
+    NDArray *array = reinterpret_cast<NDArray *>(input_handles[i]);
+    inputs.emplace_back(array, c_input_names[i]);
+  }
+  for (int i = 0; i < num_outputs; ++i) {
+    NDArray *array = reinterpret_cast<NDArray *>(output_handles[i]);
+    outputs.emplace_back(array);
+  }
+
+  // Obtain Symbeol
+  *out = Imperative::Get()->GetDeferredComputeSymbol(inputs, outputs);
+
+  API_END();
 
 Review comment:
   It's better to use `API_END_HANDLE_ERROR` to handle potential memory leak 
caused by throwing exceptions. For example,
   
https://github.com/apache/incubator-mxnet/blob/93c123daee0241845c3e7f6452f91ab2d3d144c8/src/c_api/c_api.cc#L1068-L1080

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to