| 955 | } |
| 956 | |
| 957 | NodeDef* 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 | |
| 998 | NodeDef* MutableGraphView::GetOrCreateIdentityConsumingSwitch( |
| 999 | const OutputPort& fanin) { |
nothing calls this directly
no test coverage detected