MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReplaceNode

Function ReplaceNode

serving/processor/framework/graph_optimizer.cc:666–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

664namespace {
665
666Status ReplaceNode(
667 const std::string& op_name,
668 Node* node, Graph* graph,
669 std::vector<SrcInfo>& input_info,
670 std::unordered_map<std::string, const AttrValue*>& attr_info) {
671
672 // Create KvLookup/KvImport op here and remove the node
673 NodeDef new_node_def;
674 new_node_def.set_name(node->name());
675 new_node_def.set_op(op_name);
676
677 // Set attrs
678 for (auto attr : attr_info) {
679 (*new_node_def.mutable_attr())[attr.first] = *(attr.second);
680 }
681
682 Status status;
683 Node *new_node = graph->AddNode(new_node_def, &status);
684 if (!status.ok()) return status;
685
686 // Add input egdes, from slot 0 -> n
687 for (size_t i = 0; i < input_info.size(); ++i) {
688 int idx = i;
689 if (input_info[i].src_slot == Graph::kControlSlot) {
690 idx = Graph::kControlSlot;
691 }
692 graph->AddEdge(input_info[i].src_node,
693 input_info[i].src_slot,
694 new_node, idx);
695 }
696
697 // Add output edges
698 for (const Edge* edge : node->out_edges()) {
699 graph->AddEdge(new_node, edge->src_output(),
700 edge->dst(), edge->dst_input());
701 }
702
703 // remove current node
704 graph->RemoveNode(node);
705
706 return Status::OK();
707}
708
709Status ReplaceNode(
710 const std::string& op_name,

Callers 4

ConvertKVOpsMethod · 0.70
ConvertToHashTableOpMethod · 0.70
ConvertToHashLookupOpMethod · 0.70
ConvertToHashImportOpMethod · 0.70

Calls 15

InternalFunction · 0.85
set_opMethod · 0.80
nameMethod · 0.65
set_nameMethod · 0.45
AddNodeMethod · 0.45
okMethod · 0.45
sizeMethod · 0.45
AddEdgeMethod · 0.45
src_outputMethod · 0.45
dstMethod · 0.45
dst_inputMethod · 0.45
RemoveNodeMethod · 0.45

Tested by

no test coverage detected