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

Method GetControllingFaninToAdd

tensorflow/core/grappler/mutable_graph_view.cc:957–996  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

955}
956
957NodeDef* MutableGraphView::GetControllingFaninToAdd(absl::string_view node_name,
958 const OutputPort& fanin,
959 string* error_msg) {
960 if (!IsSwitch(*fanin.node)) {
961 return fanin.node;
962 } else {
963 if (IsOutputPortControlling(fanin)) {
964 // Can't add a Switch node control dependency.
965 TensorId tensor_id(fanin.node->name(), fanin.port_id);
966 *error_msg = absl::Substitute(
967 "can't add fanin '$0' as it will become a Switch control dependency",
968 tensor_id.ToString());
969 return nullptr;
970 }
971 // We can't anchor control dependencies directly on the switch node: unlike
972 // other nodes only one of the outputs of the switch node will be generated
973 // when the switch node is executed, and we need to make sure the control
974 // dependency is only triggered when the corresponding output is triggered.
975 // We start by looking for an identity node connected to the output of the
976 // switch node, and use it to anchor the control dependency.
977 for (const auto& fanout : GetFanout(fanin)) {
978 if (IsIdentity(*fanout.node) || IsIdentityNSingleInput(*fanout.node)) {
979 if (fanout.node->name() == node_name) {
980 *error_msg =
981 absl::Substitute("can't add found fanin '$0' to self",
982 AsControlDependency(fanout.node->name()));
983 return nullptr;
984 }
985 return fanout.node;
986 }
987 }
988
989 // No node found, check if node to be created is itself.
990 if (GeneratedNameForIdentityConsumingSwitch(fanin) == node_name) {
991 *error_msg = absl::Substitute("can't add generated fanin '$0' to self",
992 AsControlDependency(string(node_name)));
993 }
994 }
995 return nullptr;
996}
997
998NodeDef* MutableGraphView::GetOrCreateIdentityConsumingSwitch(
999 const OutputPort& fanin) {

Callers

nothing calls this directly

Calls 8

IsOutputPortControllingFunction · 0.85
IsIdentityNSingleInputFunction · 0.85
AsControlDependencyFunction · 0.85
IsSwitchFunction · 0.70
IsIdentityFunction · 0.70
nameMethod · 0.65
ToStringMethod · 0.45

Tested by

no test coverage detected