MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / dfs

Function dfs

src/graph/algorithms/TopologicalSort.cpp:127–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127std::vector<NodeID> dfs(Graph &g)
128{
129 std::vector<NodeID> dfs_order_vector;
130
131 // Created visited vector
132 std::vector<bool> visited(g.nodes().size(), false);
133
134 // Create DFS stack
135 std::stack<NodeID> stack;
136
137 // Push inputs and mark as visited
138 for (auto &input : g.nodes(NodeType::Input))
139 {
140 if (input != EmptyNodeID)
141 {
142 visited[input] = true;
143 stack.push(input);
144 }
145 }
146
147 // Push const nodes and mark as visited
148 for (auto &const_node : g.nodes(NodeType::Const))
149 {
150 if (const_node != EmptyNodeID)
151 {
152 visited[const_node] = true;
153 stack.push(const_node);
154 }
155 }
156
157 // Iterate over vector and edges
158 while (!stack.empty())
159 {
160 // Pop a node from stack and process
161 NodeID n = stack.top();
162 dfs_order_vector.push_back(n);
163 stack.pop();
164
165 // Mark node as visited
166 if (!visited[n])
167 {
168 visited[n] = true;
169 }
170
171 const INode *node = g.node(n);
172 ARM_COMPUTE_ERROR_ON(node == nullptr);
173 // Reverse iterate to push branches from right to left and pop on the opposite order
174 for (const auto &eid : arm_compute::utils::iterable::reverse_iterate(node->output_edges()))
175 {
176 const Edge *e = g.edge(eid);
177 ARM_COMPUTE_ERROR_ON(e == nullptr);
178 if (!visited[e->consumer_id()] && detail::all_inputs_are_visited(e->consumer(), visited))
179 {
180 stack.push(e->consumer_id());
181 }
182 }
183 }
184

Callers 3

finalize_graphMethod · 0.85
mutateMethod · 0.85
mutateMethod · 0.85

Calls 9

reverse_iterateFunction · 0.85
all_inputs_are_visitedFunction · 0.85
push_backMethod · 0.80
nodeMethod · 0.80
edgeMethod · 0.80
consumer_idMethod · 0.80
consumerMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected