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

Method SetCallContexts

tensorflow/compiler/xla/service/call_graph.cc:195–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193} // namespace
194
195void CallGraph::SetCallContexts() {
196 std::queue<CallGraphNode*> worklist;
197
198 // Initialize worklist with all roots of the call graph (computations without
199 // callers).
200 for (const HloComputation* computation : module_->computations()) {
201 CallGraphNode& node = GetNode(computation);
202 if (node.callers().empty()) {
203 node.set_context(CallContext::kSequential);
204 worklist.push(&node);
205 }
206 }
207
208 while (!worklist.empty()) {
209 CallGraphNode* node = worklist.front();
210 worklist.pop();
211
212 for (const CallSite& callsite : node->callsites()) {
213 for (const HloComputation* callee : callsite.called_computations()) {
214 CallGraphNode& callee_node = GetNode(callee);
215
216 // Update context of callee computation based on the callsite and its
217 // current context.
218 CallContext context_to_add;
219 if (callsite.context() == CallContext::kParallel) {
220 context_to_add = CallContext::kParallel;
221 } else {
222 CHECK_EQ(callsite.context(), CallContext::kSequential);
223 context_to_add = node->context();
224 }
225 CallContext new_context =
226 UnionContexts(context_to_add, callee_node.context());
227
228 if (new_context != callee_node.context()) {
229 // Context of computation has been changed so add node to worklist.
230 callee_node.set_context(new_context);
231 worklist.push(&callee_node);
232 }
233 }
234 }
235 }
236
237 // No node should have a kNone calling context.
238 for (const HloComputation* computation : module_->computations()) {
239 CHECK_NE(GetNode(computation).context(), CallContext::kNone);
240 }
241}
242
243void CallGraph::SetNodeDepths() {
244 std::queue<CallGraphNode*> worklist;

Callers 1

BuildMethod · 0.80

Calls 8

UnionContextsFunction · 0.85
computationsMethod · 0.80
set_contextMethod · 0.80
emptyMethod · 0.45
pushMethod · 0.45
frontMethod · 0.45
popMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected