ZhennanQin commented on a change in pull request #15886: Graph Partition API
URL: https://github.com/apache/incubator-mxnet/pull/15886#discussion_r318414073
##########
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:
I don't think that check is necessary, as user can use different `args`
between `optimize_for` and `bind`.
Another case is, to support multiple backends mixed running, user may run
optimize_for many times. Like,
```
sym = sym.optimize_for('MKLDNN', ctx= mx.cpu(), args)
sym = sym.optimize_for('backendA', ctx= mx.gpu(), args) # backend A to
handle the rest graph
sym = sym.optimize_for('backendB', ctx= mx.cpu(), args) # backend B to
handle the rest graph
exe = sym.bind(ctx=mx.cpu(), args=args, aux_states=aux, grad_req='null')
```
For this case, context is mainly decided by graph partition, not bind.
----------------------------------------------------------------
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