@@ -100,17 +100,16 @@ void sortTopological(std::set<std::weak_ptr<node_impl>,
100
100
Source.pop ();
101
101
SortedNodes.push_back (Node);
102
102
103
- for (auto &SuccWP : Node->MSuccessors ) {
104
- auto Succ = SuccWP.lock ();
103
+ for (node_impl &Succ : Node->successors ()) {
105
104
106
- if (PartitionBounded && (Succ-> MPartitionNum != Node->MPartitionNum )) {
105
+ if (PartitionBounded && (Succ. MPartitionNum != Node->MPartitionNum )) {
107
106
continue ;
108
107
}
109
108
110
- auto &TotalVisitedEdges = Succ-> MTotalVisitedEdges ;
109
+ auto &TotalVisitedEdges = Succ. MTotalVisitedEdges ;
111
110
++TotalVisitedEdges;
112
- if (TotalVisitedEdges == Succ-> MPredecessors .size ()) {
113
- Source.push (Succ);
111
+ if (TotalVisitedEdges == Succ. MPredecessors .size ()) {
112
+ Source.push (Succ. weak_from_this () );
114
113
}
115
114
}
116
115
}
@@ -127,14 +126,14 @@ void sortTopological(std::set<std::weak_ptr<node_impl>,
127
126
// / a node with a smaller partition number.
128
127
// / @param Node Node to assign to the partition.
129
128
// / @param PartitionNum Number to propagate.
130
- void propagatePartitionUp (std::shared_ptr< node_impl> Node, int PartitionNum) {
131
- if (((Node-> MPartitionNum != -1 ) && (Node-> MPartitionNum <= PartitionNum)) ||
132
- (Node-> MCGType == sycl::detail::CGType::CodeplayHostTask)) {
129
+ void propagatePartitionUp (node_impl & Node, int PartitionNum) {
130
+ if (((Node. MPartitionNum != -1 ) && (Node. MPartitionNum <= PartitionNum)) ||
131
+ (Node. MCGType == sycl::detail::CGType::CodeplayHostTask)) {
133
132
return ;
134
133
}
135
- Node-> MPartitionNum = PartitionNum;
136
- for (auto &Predecessor : Node-> MPredecessors ) {
137
- propagatePartitionUp (Predecessor. lock () , PartitionNum);
134
+ Node. MPartitionNum = PartitionNum;
135
+ for (node_impl &Predecessor : Node. predecessors () ) {
136
+ propagatePartitionUp (Predecessor, PartitionNum);
138
137
}
139
138
}
140
139
@@ -146,17 +145,18 @@ void propagatePartitionUp(std::shared_ptr<node_impl> Node, int PartitionNum) {
146
145
// / @param HostTaskList List of host tasks that have already been processed and
147
146
// / are encountered as successors to the node Node.
148
147
void propagatePartitionDown (
149
- const std::shared_ptr< node_impl> &Node, int PartitionNum,
148
+ node_impl &Node, int PartitionNum,
150
149
std::list<std::shared_ptr<node_impl>> &HostTaskList) {
151
- if (Node-> MCGType == sycl::detail::CGType::CodeplayHostTask) {
152
- if (Node-> MPartitionNum != -1 ) {
153
- HostTaskList.push_front (Node);
150
+ if (Node. MCGType == sycl::detail::CGType::CodeplayHostTask) {
151
+ if (Node. MPartitionNum != -1 ) {
152
+ HostTaskList.push_front (Node. shared_from_this () );
154
153
}
155
154
return ;
156
155
}
157
- Node->MPartitionNum = PartitionNum;
158
- for (auto &Successor : Node->MSuccessors ) {
159
- propagatePartitionDown (Successor.lock (), PartitionNum, HostTaskList);
156
+ Node.MPartitionNum = PartitionNum;
157
+ for (node_impl &Successor : Node.successors ()) {
158
+ propagatePartitionDown (Successor, PartitionNum,
159
+ HostTaskList);
160
160
}
161
161
}
162
162
@@ -165,8 +165,8 @@ void propagatePartitionDown(
165
165
// / @param Node node to test
166
166
// / @return True is `Node` is a root of its partition
167
167
bool isPartitionRoot (std::shared_ptr<node_impl> Node) {
168
- for (auto &Predecessor : Node->MPredecessors ) {
169
- if (Predecessor.lock ()-> MPartitionNum == Node->MPartitionNum ) {
168
+ for (node_impl &Predecessor : Node->predecessors () ) {
169
+ if (Predecessor.MPartitionNum == Node->MPartitionNum ) {
170
170
return false ;
171
171
}
172
172
}
@@ -221,15 +221,15 @@ void exec_graph_impl::makePartitions() {
221
221
auto Node = HostTaskList.front ();
222
222
HostTaskList.pop_front ();
223
223
CurrentPartition++;
224
- for (auto &Predecessor : Node->MPredecessors ) {
225
- propagatePartitionUp (Predecessor. lock () , CurrentPartition);
224
+ for (node_impl &Predecessor : Node->predecessors () ) {
225
+ propagatePartitionUp (Predecessor, CurrentPartition);
226
226
}
227
227
CurrentPartition++;
228
228
Node->MPartitionNum = CurrentPartition;
229
229
CurrentPartition++;
230
230
auto TmpSize = HostTaskList.size ();
231
- for (auto &Successor : Node->MSuccessors ) {
232
- propagatePartitionDown (Successor. lock () , CurrentPartition, HostTaskList);
231
+ for (node_impl &Successor : Node->successors () ) {
232
+ propagatePartitionDown (Successor, CurrentPartition, HostTaskList);
233
233
}
234
234
if (HostTaskList.size () > TmpSize) {
235
235
// At least one HostTask has been re-numbered so group merge opportunities
@@ -290,9 +290,9 @@ void exec_graph_impl::makePartitions() {
290
290
for (const auto &Partition : MPartitions) {
291
291
for (auto const &Root : Partition->MRoots ) {
292
292
auto RootNode = Root.lock ();
293
- for (const auto &Dep : RootNode->MPredecessors ) {
294
- auto NodeDep = Dep. lock ();
295
- auto &Predecessor = MPartitions[MPartitionNodes[NodeDep]];
293
+ for (node_impl &NodeDep : RootNode->predecessors () ) {
294
+ auto &Predecessor =
295
+ MPartitions[MPartitionNodes[NodeDep. shared_from_this () ]];
296
296
Partition->MPredecessors .push_back (Predecessor.get ());
297
297
Predecessor->MSuccessors .push_back (Partition.get ());
298
298
}
@@ -424,8 +424,8 @@ std::set<std::shared_ptr<node_impl>> graph_impl::getCGEdges(
424
424
bool ShouldAddDep = true ;
425
425
// If any of this node's successors have this requirement then we skip
426
426
// adding the current node as a dependency.
427
- for (auto &Succ : Node->MSuccessors ) {
428
- if (Succ.lock ()-> hasRequirementDependency (Req)) {
427
+ for (node_impl &Succ : Node->successors () ) {
428
+ if (Succ.hasRequirementDependency (Req)) {
429
429
ShouldAddDep = false ;
430
430
break ;
431
431
}
@@ -774,17 +774,17 @@ void graph_impl::beginRecording(sycl::detail::queue_impl &Queue) {
774
774
// predecessors until we find the real dependency.
775
775
void exec_graph_impl::findRealDeps (
776
776
std::vector<ur_exp_command_buffer_sync_point_t > &Deps,
777
- std::shared_ptr<node_impl> CurrentNode, int ReferencePartitionNum) {
778
- if (!CurrentNode->requiresEnqueue ()) {
779
- for (auto &N : CurrentNode->MPredecessors ) {
780
- auto NodeImpl = N.lock ();
777
+ node_impl &CurrentNode, int ReferencePartitionNum) {
778
+ if (!CurrentNode.requiresEnqueue ()) {
779
+ for (node_impl &NodeImpl : CurrentNode.predecessors ()) {
781
780
findRealDeps (Deps, NodeImpl, ReferencePartitionNum);
782
781
}
783
782
} else {
783
+ auto CurrentNodePtr = CurrentNode.shared_from_this ();
784
784
// Verify if CurrentNode belong the the same partition
785
- if (MPartitionNodes[CurrentNode ] == ReferencePartitionNum) {
785
+ if (MPartitionNodes[CurrentNodePtr ] == ReferencePartitionNum) {
786
786
// Verify that the sync point has actually been set for this node.
787
- auto SyncPoint = MSyncPoints.find (CurrentNode );
787
+ auto SyncPoint = MSyncPoints.find (CurrentNodePtr );
788
788
assert (SyncPoint != MSyncPoints.end () &&
789
789
" No sync point has been set for node dependency." );
790
790
// Check if the dependency has already been added.
@@ -802,8 +802,8 @@ exec_graph_impl::enqueueNodeDirect(const sycl::context &Ctx,
802
802
ur_exp_command_buffer_handle_t CommandBuffer,
803
803
std::shared_ptr<node_impl> Node) {
804
804
std::vector<ur_exp_command_buffer_sync_point_t > Deps;
805
- for (auto &N : Node->MPredecessors ) {
806
- findRealDeps (Deps, N. lock () , MPartitionNodes[Node]);
805
+ for (node_impl &N : Node->predecessors () ) {
806
+ findRealDeps (Deps, N, MPartitionNodes[Node]);
807
807
}
808
808
ur_exp_command_buffer_sync_point_t NewSyncPoint;
809
809
ur_exp_command_buffer_command_handle_t NewCommand = 0 ;
@@ -858,8 +858,8 @@ exec_graph_impl::enqueueNode(ur_exp_command_buffer_handle_t CommandBuffer,
858
858
std::shared_ptr<node_impl> Node) {
859
859
860
860
std::vector<ur_exp_command_buffer_sync_point_t > Deps;
861
- for (auto &N : Node->MPredecessors ) {
862
- findRealDeps (Deps, N. lock () , MPartitionNodes[Node]);
861
+ for (node_impl &N : Node->predecessors () ) {
862
+ findRealDeps (Deps, N, MPartitionNodes[Node]);
863
863
}
864
864
865
865
sycl::detail::EventImplPtr Event =
@@ -1328,8 +1328,8 @@ void exec_graph_impl::duplicateNodes() {
1328
1328
auto NodeCopy = NewNodes[i];
1329
1329
// Look through all the original node successors, find their copies and
1330
1330
// register those as successors with the current copied node
1331
- for (auto &NextNode : OriginalNode->MSuccessors ) {
1332
- auto Successor = NodesMap.at (NextNode.lock ());
1331
+ for (node_impl &NextNode : OriginalNode->successors () ) {
1332
+ auto Successor = NodesMap.at (NextNode.shared_from_this ());
1333
1333
NodeCopy->registerSuccessor (Successor);
1334
1334
}
1335
1335
}
@@ -1370,8 +1370,8 @@ void exec_graph_impl::duplicateNodes() {
1370
1370
auto SubgraphNode = SubgraphNodes[i];
1371
1371
auto NodeCopy = NewSubgraphNodes[i];
1372
1372
1373
- for (auto &NextNode : SubgraphNode->MSuccessors ) {
1374
- auto Successor = SubgraphNodesMap.at (NextNode.lock ());
1373
+ for (node_impl &NextNode : SubgraphNode->successors () ) {
1374
+ auto Successor = SubgraphNodesMap.at (NextNode.shared_from_this ());
1375
1375
NodeCopy->registerSuccessor (Successor);
1376
1376
}
1377
1377
}
@@ -1392,9 +1392,8 @@ void exec_graph_impl::duplicateNodes() {
1392
1392
// original subgraph node
1393
1393
1394
1394
// Predecessors
1395
- for (auto &PredNodeWeak : NewNode->MPredecessors ) {
1396
- auto PredNode = PredNodeWeak.lock ();
1397
- auto &Successors = PredNode->MSuccessors ;
1395
+ for (node_impl &PredNode : NewNode->predecessors ()) {
1396
+ auto &Successors = PredNode.MSuccessors ;
1398
1397
1399
1398
// Remove the subgraph node from this nodes successors
1400
1399
Successors.erase (std::remove_if (Successors.begin (), Successors.end (),
@@ -1406,14 +1405,13 @@ void exec_graph_impl::duplicateNodes() {
1406
1405
// Add all input nodes from the subgraph as successors for this node
1407
1406
// instead
1408
1407
for (auto &Input : Inputs) {
1409
- PredNode-> registerSuccessor (Input);
1408
+ PredNode. registerSuccessor (Input);
1410
1409
}
1411
1410
}
1412
1411
1413
1412
// Successors
1414
- for (auto &SuccNodeWeak : NewNode->MSuccessors ) {
1415
- auto SuccNode = SuccNodeWeak.lock ();
1416
- auto &Predecessors = SuccNode->MPredecessors ;
1413
+ for (node_impl &SuccNode : NewNode->successors ()) {
1414
+ auto &Predecessors = SuccNode.MPredecessors ;
1417
1415
1418
1416
// Remove the subgraph node from this nodes successors
1419
1417
Predecessors.erase (std::remove_if (Predecessors.begin (),
@@ -1426,7 +1424,7 @@ void exec_graph_impl::duplicateNodes() {
1426
1424
// Add all Output nodes from the subgraph as predecessors for this node
1427
1425
// instead
1428
1426
for (auto &Output : Outputs) {
1429
- Output->registerSuccessor (SuccNode);
1427
+ Output->registerSuccessor (SuccNode. shared_from_this () );
1430
1428
}
1431
1429
}
1432
1430
0 commit comments