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

Method AddFaninsInternal

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

Source from the content-addressed store, hash-verified

532}
533
534void MutableGraphView::AddFaninsInternal(
535 std::vector<std::vector<TensorId>>* fanins) {
536 const int num_nodes = nodes_.size();
537 for (int i = 0; i < num_nodes; ++i) {
538 MutableNodeView& node_view = nodes_[i];
539 NodeDef* node = node_view.node();
540 std::vector<TensorId>& node_fanins = fanins->at(i);
541 absl::flat_hash_set<absl::string_view> observed_controls;
542 int pos = 0;
543 const int last_idx = node_fanins.size() - 1;
544 int last_pos = last_idx;
545 node_view.fanins_count_.reserve(node->input_size());
546 node_view.controlling_fanins_index_.reserve(node->input_size());
547 while (pos <= last_pos) {
548 const TensorId& fanin_id = node_fanins[pos];
549 bool is_control = IsTensorIdControl(fanin_id);
550 const int fanin_node_index = node_index_by_name_[fanin_id.node()];
551 MutableNodeView& fanin_node_view = nodes_[fanin_node_index];
552
553 if (is_control) {
554 if (gtl::InsertIfNotPresent(&observed_controls, fanin_id.node())) {
555 fanin_node_view.controlled_fanouts_.emplace_back(
556 this, i, Graph::kControlSlot,
557 node_view.controlling_fanins_.size());
558 node_view.controlling_fanins_.emplace_back(
559 this, fanin_node_index, Graph::kControlSlot,
560 fanin_node_view.controlled_fanouts_.size() - 1);
561 IncrementFaninCount(
562 &node_view.fanins_count_,
563 {&graph_->node(fanin_node_index), Graph::kControlSlot});
564 node_view.controlling_fanins_index_.emplace(
565 fanin_id.node(), pos - node_view.NumRegularFanins());
566 ++pos;
567 } else {
568 node->mutable_input()->SwapElements(pos, last_pos);
569 std::swap(node_fanins[pos], node_fanins[last_pos]);
570 --last_pos;
571 }
572 } else {
573 if (fanin_node_view.regular_fanouts_by_port_.size() <
574 fanin_id.index() + 1) {
575 fanin_node_view.regular_fanouts_by_port_.resize(fanin_id.index() + 1);
576 }
577 auto& fanin_regular_fanouts =
578 fanin_node_view.regular_fanouts_by_port_[fanin_id.index()];
579 fanin_regular_fanouts.emplace_back(this, i,
580 node_view.regular_fanins_.size(),
581 node_view.regular_fanins_.size());
582 ++fanin_node_view.num_regular_fanouts_;
583 node_view.regular_fanins_.emplace_back(
584 this, fanin_node_index, fanin_id.index(),
585 fanin_regular_fanouts.size() - 1);
586 IncrementFaninCount(
587 &node_view.fanins_count_,
588 {&graph_->node(fanin_node_index), fanin_id.index()});
589 ++pos;
590 }
591 }

Callers

nothing calls this directly

Calls 14

IsTensorIdControlFunction · 0.85
InsertIfNotPresentFunction · 0.85
IncrementFaninCountFunction · 0.85
NumRegularFaninsMethod · 0.80
sizeMethod · 0.45
nodeMethod · 0.45
atMethod · 0.45
reserveMethod · 0.45
input_sizeMethod · 0.45
emplace_backMethod · 0.45
emplaceMethod · 0.45
mutable_inputMethod · 0.45

Tested by

no test coverage detected