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

Method AddAndDedupFanouts

tensorflow/core/grappler/mutable_graph_view.cc:342–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340} // namespace
341
342void MutableGraphView::AddAndDedupFanouts(NodeDef* node) {
343 // TODO(lyandy): Checks for self loops, Switch control dependencies, fanins
344 // exist, and all regular fanins come before controlling fanins.
345 absl::flat_hash_set<absl::string_view> fanins;
346 absl::flat_hash_set<absl::string_view> controlling_fanins;
347 int max_input_port = -1;
348 int pos = 0;
349 const int last_idx = node->input_size() - 1;
350 int last_pos = last_idx;
351 while (pos <= last_pos) {
352 TensorId tensor_id = ParseTensorName(node->input(pos));
353 absl::string_view input_node_name = tensor_id.node();
354 bool is_control_input = IsTensorIdControlling(tensor_id);
355 bool can_dedup_control_with_regular_input =
356 CanDedupControlWithRegularInput(*this, input_node_name);
357 bool can_dedup_control =
358 is_control_input && (can_dedup_control_with_regular_input ||
359 (!can_dedup_control_with_regular_input &&
360 controlling_fanins.contains(input_node_name)));
361 if (!gtl::InsertIfNotPresent(&fanins, input_node_name) &&
362 can_dedup_control) {
363 node->mutable_input()->SwapElements(pos, last_pos);
364 --last_pos;
365 } else {
366 OutputPort output(nodes()[input_node_name], tensor_id.index());
367
368 if (is_control_input) {
369 fanouts()[output].emplace(node, Graph::kControlSlot);
370 } else {
371 max_input_port = pos;
372 max_regular_output_port()[output.node] =
373 std::max(max_regular_output_port()[output.node], output.port_id);
374 fanouts()[output].emplace(node, pos);
375 }
376 ++pos;
377 }
378 if (is_control_input) {
379 controlling_fanins.insert(input_node_name);
380 }
381 }
382
383 if (last_pos < last_idx) {
384 node->mutable_input()->DeleteSubrange(last_pos + 1, last_idx - last_pos);
385 }
386
387 if (max_input_port > -1) {
388 max_regular_input_port()[node] = max_input_port;
389 }
390}
391
392void MutableGraphView::UpdateMaxRegularOutputPortForRemovedFanin(
393 const OutputPort& fanin,

Callers

nothing calls this directly

Calls 13

ParseTensorNameFunction · 0.85
IsTensorIdControllingFunction · 0.85
InsertIfNotPresentFunction · 0.85
containsMethod · 0.80
maxFunction · 0.50
input_sizeMethod · 0.45
inputMethod · 0.45
nodeMethod · 0.45
mutable_inputMethod · 0.45
indexMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected