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

Method AddControlDependencies

tensorflow/core/graph/graph_constructor.cc:887–936  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

885}
886
887void GraphConstructor::AddControlDependencies(
888 NodeDef* node_def, std::vector<bool>* input_already_exists) {
889 // To avoid adding redundant control dependencies to every imported node, skip
890 // nodes that will inherit the dependencies from another imported node.
891 bool inherits_deps = false;
892 for (int i = 0; i < node_def->input_size(); ++i) {
893 // Assume we won't inherit dependencies from remapped inputs that already
894 // exist in the graph. Even if we're wrong, we'll only add redundant
895 // dependencies.
896 if ((*input_already_exists)[i]) continue;
897
898 // If this input is a backedge, assume we won't inherit the dependencies.
899 // TODO(skyewm): we have many redundant ParseTensorName calls. It could be
900 // worth optimizing these.
901 TensorId id(ParseTensorName(node_def->input(i)));
902 auto iter = gdef_nodes_.find(id.first);
903 DCHECK(iter != gdef_nodes_.end()) << id.first;
904 if (iter->second.node == nullptr) {
905 // Input hasn't been created yet, indicating it's a backedge.
906 continue;
907 }
908 inherits_deps = true;
909 }
910 if (inherits_deps) return;
911
912 // node_def either has no inputs or all remapped inputs, add the control
913 // dependencies
914 for (const string& control_dep : opts_.control_dependencies) {
915 string input = TensorId(control_dep, Graph::kControlSlot).ToString();
916 bool found = false;
917 for (int i = node_def->input_size() - 1; i >= 0; --i) {
918 const string& node_input = node_def->input(i);
919 if (node_input[0] != '^') {
920 // Control inputs are at the end. Break when we reach the non-control
921 // inputs.
922 break;
923 }
924 if (node_input == input) {
925 // Control dependency already exists
926 found = true;
927 break;
928 }
929 }
930 if (found) {
931 continue;
932 }
933 node_def->add_input(input);
934 input_already_exists->push_back(true);
935 }
936}
937
938void GraphConstructor::AddPrefixToNodeDef(
939 const std::vector<bool>& input_already_exists, NodeDef* node_def) {

Callers

nothing calls this directly

Calls 9

ParseTensorNameFunction · 0.85
TensorIdClass · 0.70
input_sizeMethod · 0.45
inputMethod · 0.45
findMethod · 0.45
endMethod · 0.45
ToStringMethod · 0.45
add_inputMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected