You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/07/11 20:44:43 UTC

[GitHub] zheng-da commented on a change in pull request #11641: [WIP] make CachedOp a normal operator

zheng-da commented on a change in pull request #11641: [WIP] make CachedOp a normal operator
URL: https://github.com/apache/incubator-mxnet/pull/11641#discussion_r201832693
 
 

 ##########
 File path: src/c_api/c_api_symbolic.cc
 ##########
 @@ -366,6 +367,36 @@ int MXSymbolGetInputSymbols(SymbolHandle sym, SymbolHandle **input_arr, int *inp
   API_END_HANDLE_ERROR();
 }
 
+int MXMakeSubgraph(SymbolHandle sym, SymbolHandle *input_symbols, mx_uint num_inputs,
+                   SymbolHandle *out) {
+  API_BEGIN();
+  nnvm::Symbol *s = static_cast<nnvm::Symbol*>(sym);
+  CHECK_EQ(s->ListInputs(nnvm::Symbol::kAll).size(), num_inputs)
+      << "The number of inputs needs to match the inputs in the subgraph";
+
+  // Construct a node for this subgraph.
+  std::vector<nnvm::NodeEntry> inputs(num_inputs);
+  for (size_t i = 0; i < inputs.size(); i++) {
+    nnvm::Symbol *s = static_cast<nnvm::Symbol*>(input_symbols[i]);
+    CHECK_EQ(s->outputs.size(), 1U) << "The input symbol should have one output";
+    inputs[i] = s->outputs[0];
+  }
+  nnvm::NodeEntry entry = nnvm::MakeNode("_CachedOp", "_CachedOp", inputs);
+  nnvm::NodePtr n = entry.node;
+
+  // Create CachedOp for the node.
+  std::vector<std::pair<std::string, std::string> > kwargs;
+  kwargs.push_back(std::pair<std::string, std::string>("inline_limit", "0"));
+  n->attrs.parsed = std::make_shared<mxnet::CachedOp>(*s, kwargs);
+
+  // Create a new symbol for this node.
+  s = new nnvm::Symbol();
 
 Review comment:
   i just follow the implementations in other APIs. The symbol will be saved in a Python symbol handle. AFAIK, once the python symbol handle is destroyed, the symbol object will also be destroyed.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services