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

Function InsertControlDependencies

tensorflow/core/graph/collective_order.cc:147–180  ·  view source on GitHub ↗

Insert control dependencies defined by `dependency_edges` in `graph`. If `order_type` is `kEdges`, insert explicit control edges, else if `order_type` is `kAttrs`, encode dependencies as an attribute on collective node.

Source from the content-addressed store, hash-verified

145// `order_type` is `kEdges`, insert explicit control edges, else if `order_type`
146// is `kAttrs`, encode dependencies as an attribute on collective node.
147Status InsertControlDependencies(
148 Graph* graph, GraphCollectiveOrder order_type,
149 const absl::flat_hash_map<Node*, absl::flat_hash_set<Node*>>&
150 dependency_edges) {
151 if (order_type == GraphCollectiveOrder::kEdges) {
152 for (const auto& pair : dependency_edges) {
153 Node* src_node = pair.first;
154 for (Node* dst_node : pair.second) {
155 graph->AddControlEdge(src_node, dst_node);
156 }
157 }
158 } else if (order_type == GraphCollectiveOrder::kAttrs) {
159 // `wait_for` is the inverse of `dependency_edges`, i.e. `wait_for[node]`
160 // contains the list of instance keys for which `node` must wait.
161 absl::flat_hash_map<Node*, absl::flat_hash_set<int32>> wait_for;
162 for (const auto& pair : dependency_edges) {
163 int32 src_instance;
164 TF_RETURN_IF_ERROR(
165 GetNodeAttr(pair.first->attrs(), "instance_key", &src_instance));
166 for (Node* dst_node : pair.second) {
167 wait_for[dst_node].insert(src_instance);
168 }
169 }
170 for (const auto& pair : wait_for) {
171 std::vector<int32> wait_for_list(pair.second.begin(), pair.second.end());
172 pair.first->ClearAttr("wait_for");
173 pair.first->AddAttr("wait_for", wait_for_list);
174 }
175 } else {
176 return errors::Internal("Unexpected GraphCollectiveOrder type ",
177 static_cast<int>(order_type));
178 }
179 return Status::OK();
180}
181
182} // namespace
183

Callers 1

OrderCollectivesFunction · 0.85

Calls 9

InternalFunction · 0.85
ClearAttrMethod · 0.80
AddAttrMethod · 0.80
GetNodeAttrFunction · 0.50
AddControlEdgeMethod · 0.45
attrsMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected