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

Function BuildControlFlowInfo

tensorflow/core/graph/control_flow.cc:86–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84} // namespace
85
86Status BuildControlFlowInfo(const Graph* g, std::vector<ControlFlowInfo>* info,
87 std::vector<string>* unreachable_nodes) {
88 info->clear();
89 info->resize(g->num_node_ids());
90
91 std::vector<const Node*> parent_nodes;
92 parent_nodes.resize(g->num_node_ids());
93
94 const Node* src_node = g->source_node();
95 ControlFlowInfo& src_info = (*info)[src_node->id()];
96 src_info.frame = src_node;
97 src_info.parent_frame = src_node;
98
99 string frame_name;
100 std::deque<const Node*> ready;
101 ready.push_back(src_node);
102 while (!ready.empty()) {
103 const Node* curr_node = ready.front();
104 ready.pop_front();
105 const ControlFlowInfo& curr_info = (*info)[curr_node->id()];
106 const Node* frame = curr_info.frame;
107 const Node* parent = curr_info.parent_frame;
108 frame_name = curr_info.frame_name;
109
110 if (IsExit(curr_node)) {
111 // Exit to the parent frame.
112 const ControlFlowInfo& parent_info = (*info)[parent->id()];
113 frame = parent_info.frame;
114 parent = parent_info.parent_frame;
115 frame_name = parent_info.frame_name;
116 }
117
118 for (const Edge* out_edge : curr_node->out_edges()) {
119 const Node* out = out_edge->dst();
120 int out_id = out->id();
121 ControlFlowInfo* out_info = &(*info)[out_id];
122 const Node* out_parent = out_info->parent_frame;
123 bool is_visited = (parent_nodes[out_id] != nullptr);
124
125 // Skip Sink/Source nodes.
126 if (!out->IsOp()) continue;
127
128 // Add to ready queue if not seen.
129 if (!is_visited) {
130 parent_nodes[out->id()] = curr_node;
131 ready.push_back(out);
132 }
133
134 // Process the node 'out'.
135 if (IsEnter(out)) {
136 if (is_visited) {
137 const string& parent_frame = (*info)[out_parent->id()].frame_name;
138 if (parent_frame != frame_name) {
139 return errors::InvalidArgument(
140 FormatNodeForError(*out),
141 " has inputs from different frames. The input ",
142 FormatNodeForError(*curr_node), " is in frame '", frame_name,
143 "'. The input ", FormatNodeForError(*parent_nodes[out->id()]),

Callers 12

FunctionalizeWhileLoopFunction · 0.85
BuildFunctionDefMethod · 0.85
ValidateAndBuildMethod · 0.85
PopulateMethod · 0.85
InlineFunctionCallsFunction · 0.85
InitializeMethod · 0.85
FunctionDefToBodyHelperFunction · 0.85
RunMethod · 0.85
AddControlFlowFunction · 0.85
PartitionWithTensorFuseFunction · 0.85
TESTFunction · 0.85

Calls 15

InvalidArgumentFunction · 0.85
FormatNodeForErrorFunction · 0.85
ValidateControlFlowInfoFunction · 0.85
IsOpMethod · 0.80
op_nodesMethod · 0.80
IsExitFunction · 0.70
IsEnterFunction · 0.70
nameMethod · 0.65
GetNodeAttrFunction · 0.50
clearMethod · 0.45
resizeMethod · 0.45
num_node_idsMethod · 0.45

Tested by 1

TESTFunction · 0.68