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

Method AddNewNodes

tensorflow/core/grappler/utils/graph_view.cc:938–974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

936}
937
938void MutableGraphView::AddNewNodes(
939 absl::flat_hash_map<string, NodeViewFanouts>* renamed_fanouts,
940 std::vector<int>* new_node_indices) {
941 new_node_indices->reserve(mutation_.new_nodes_.size());
942 for (auto& new_node : mutation_.new_nodes_) {
943 int node_index;
944 auto graph_it = node_index_by_name_.find(new_node.node.name());
945 if (graph_it != node_index_by_name_.end()) {
946 // Overwrite existing node.
947 node_index = graph_it->second;
948 MutableNodeView& node_view = nodes_[node_index];
949 RemoveAllFaninFanoutInternal(&node_view);
950 auto* node_def = graph_->mutable_node(node_index);
951 node_def->mutable_op()->swap(*new_node.node.mutable_op());
952 node_def->mutable_device()->swap(*new_node.node.mutable_device());
953 node_def->mutable_input()->Clear();
954 node_def->mutable_attr()->swap(*new_node.node.mutable_attr());
955 mutation_.removed_nodes_[node_index] = false;
956 } else {
957 // New node.
958 auto* new_node_def = graph_->add_node();
959 *new_node_def = std::move(new_node.node);
960 node_index = nodes_.size();
961 nodes_.emplace_back(this, node_index);
962 MutableNodeView& new_node_view = nodes_.back();
963 auto it = renamed_fanouts->find(new_node_view.GetName());
964 if (it != renamed_fanouts->end()) {
965 // Reuse fanouts of renamed node.
966 NodeViewFanouts& fanouts = it->second;
967 ReplaceNodeFanouts(&new_node_view, &fanouts);
968 renamed_fanouts->erase(it);
969 }
970 node_index_by_name_.emplace(new_node_view.GetName(), node_index);
971 }
972 new_node_indices->emplace_back(node_index);
973 }
974}
975
976void MutableGraphView::FixRenamedFanouts(
977 const absl::flat_hash_map<string, NodeViewFanouts>& renamed_fanouts) {

Callers

nothing calls this directly

Calls 13

nameMethod · 0.65
reserveMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
swapMethod · 0.45
ClearMethod · 0.45
mutable_inputMethod · 0.45
emplace_backMethod · 0.45
backMethod · 0.45
GetNameMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected