samskalicky commented on a change in pull request #15886: Graph Partition API
URL: https://github.com/apache/incubator-mxnet/pull/15886#discussion_r318703729
 
 

 ##########
 File path: src/c_api/c_api_symbolic.cc
 ##########
 @@ -1199,3 +1200,73 @@ int MXShallowCopySymbol(SymbolHandle src, SymbolHandle* 
out) {
   *out = out_sym;
   API_END_HANDLE_ERROR(delete out_sym);
 }
+
+int MXOptimizeForBackend(SymbolHandle sym_handle,
+                         const char* backend_name,
+                         SymbolHandle* ret_sym_handle,
+                         const mx_uint len,
+                         NDArrayHandle* in_args_handle,
+                         const mx_uint num_options,
+                         const char** keys,
+                         const char** vals) {
+  nnvm::Symbol *s = new nnvm::Symbol();
+  API_BEGIN();
+  nnvm::Symbol *sym = static_cast<nnvm::Symbol *>(sym_handle);
+  *s = sym->Copy();
+  nnvm::Graph g = Symbol2Graph(*s);
+  if (len) {
+    NDArray **in_args_ptr = reinterpret_cast<NDArray**>(in_args_handle);
+    Context default_ctx = in_args_ptr[0]->ctx();
 
 Review comment:
   First, lets clarify that we already help users avoid this problem by not 
explicitly accepting a ctx argument to optimize_for. Instead we'll pull the 
context from where the args reside. 
   
   
https://github.com/apache/incubator-mxnet/blob/9ccf6c60f38b1589595d4d5f6d31d00b846150dd/src/c_api/c_api_symbolic.cc#L1219-L1232
   
   We're not trying to support multi-context execution yet. So I think we 
should add some check/guard to prevent this situation for now. We can remove it 
later when we actively support multi-context and auto-insertion of copy 
operators from one context to another. 
   
   Lets set an attribute on the graph like "PartitionedContext" and assign it 
the first time we do a partition. And we'll check it if it already exists and 
validate that the same context is used for each partitioning and bind. 
   
   That way we can make sure users have a good experience by enforcing what we 
currently support. 

----------------------------------------------------------------
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