@@ -74,8 +74,6 @@ void duplicateNode(const std::shared_ptr<node_impl> Node,
74
74
}
75
75
}
76
76
77
- } // anonymous namespace
78
-
79
77
// / Recursively add nodes to execution stack.
80
78
// / @param NodeImpl Node to schedule.
81
79
// / @param Schedule Execution ordering to add node to.
@@ -90,6 +88,7 @@ void sortTopological(std::shared_ptr<node_impl> NodeImpl,
90
88
91
89
Schedule.push_front (NodeImpl);
92
90
}
91
+ } // anonymous namespace
93
92
94
93
void exec_graph_impl::schedule () {
95
94
if (MSchedule.empty ()) {
@@ -122,8 +121,7 @@ std::shared_ptr<node_impl> graph_impl::addNodesToExits(
122
121
123
122
// Find all exit nodes in the current graph and register the Inputs as
124
123
// successors
125
- for (size_t i = 0 ; i < MNodeStorage.size (); i++) {
126
- auto NodeImpl = MNodeStorage[i];
124
+ for (auto &NodeImpl : MNodeStorage) {
127
125
if (NodeImpl->MSuccessors .size () == 0 ) {
128
126
for (auto &Input : Inputs) {
129
127
NodeImpl->registerSuccessor (Input, NodeImpl);
@@ -184,16 +182,8 @@ graph_impl::add(const std::vector<std::shared_ptr<node_impl>> &Dep) {
184
182
Deps.insert (Deps.end (), MExtraDependencies.begin (), MExtraDependencies.end ());
185
183
186
184
MNodeStorage.push_back (NodeImpl);
187
- // TODO: Encapsulate in separate function to avoid duplication
188
- if (!Deps.empty ()) {
189
- for (auto &N : Deps) {
190
- N->registerSuccessor (NodeImpl, N); // register successor
191
- this ->removeRoot (NodeImpl); // remove receiver from root node
192
- // list
193
- }
194
- } else {
195
- this ->addRoot (NodeImpl);
196
- }
185
+
186
+ addDepsToNode (NodeImpl, Deps);
197
187
198
188
return NodeImpl;
199
189
}
@@ -268,7 +258,7 @@ graph_impl::add(sycl::detail::CG::CGTYPE CGType,
268
258
MemObj->markBeingUsedInGraph ();
269
259
}
270
260
// Look through the graph for nodes which share this requirement
271
- for (auto Node : MNodeStorage) {
261
+ for (auto & Node : MNodeStorage) {
272
262
if (Node->hasRequirement (Req)) {
273
263
bool ShouldAddDep = true ;
274
264
// If any of this node's successors have this requirement then we skip
@@ -304,15 +294,7 @@ graph_impl::add(sycl::detail::CG::CGTYPE CGType,
304
294
std::make_shared<node_impl>(CGType, std::move (CommandGroup));
305
295
MNodeStorage.push_back (NodeImpl);
306
296
307
- if (!Deps.empty ()) {
308
- for (auto &N : Deps) {
309
- N->registerSuccessor (NodeImpl, N); // register successor
310
- this ->removeRoot (NodeImpl); // remove receiver from root node
311
- // list
312
- }
313
- } else {
314
- this ->addRoot (NodeImpl);
315
- }
297
+ addDepsToNode (NodeImpl, Deps);
316
298
317
299
// Set barrier nodes as prerequisites (new start points) for subsequent nodes
318
300
if (CGType == sycl::detail::CG::Barrier) {
@@ -387,7 +369,7 @@ void graph_impl::makeEdge(std::shared_ptr<node_impl> Src,
387
369
388
370
bool SrcFound = false ;
389
371
bool DestFound = false ;
390
- for (auto Node : MNodeStorage) {
372
+ for (const auto & Node : MNodeStorage) {
391
373
392
374
SrcFound |= Node == Src;
393
375
DestFound |= Node == Dest;
0 commit comments