@@ -1227,40 +1227,38 @@ exec_graph_impl::enqueue(sycl::detail::queue_impl &Queue,
1227
1227
1228
1228
void exec_graph_impl::duplicateNodes () {
1229
1229
// Map of original modifiable nodes (keys) to new duplicated nodes (values)
1230
- std::map<std::shared_ptr< node_impl>, std::shared_ptr< node_impl> > NodesMap;
1230
+ std::map<node_impl *, node_impl * > NodesMap;
1231
1231
1232
- const std::vector<std::shared_ptr<node_impl>> &ModifiableNodes =
1233
- MGraphImpl->MNodeStorage ;
1232
+ nodes_range ModifiableNodes{MGraphImpl->MNodeStorage };
1234
1233
std::deque<std::shared_ptr<node_impl>> NewNodes;
1235
1234
1236
- for (size_t i = 0 ; i < ModifiableNodes.size (); i++) {
1237
- auto OriginalNode = ModifiableNodes[i];
1238
- std::shared_ptr<node_impl> NodeCopy =
1239
- std::make_shared<node_impl>(*OriginalNode);
1235
+ for (node_impl &OriginalNode : ModifiableNodes) {
1236
+ NewNodes.push_back (std::make_shared<node_impl>(OriginalNode));
1237
+ node_impl &NodeCopy = *NewNodes.back ();
1240
1238
1241
1239
// Associate the ID of the original node with the node copy for later quick
1242
1240
// access
1243
- MIDCache.insert (std::make_pair (OriginalNode-> MID , NodeCopy));
1241
+ MIDCache.insert (std::make_pair (OriginalNode. MID , & NodeCopy));
1244
1242
1245
1243
// Clear edges between nodes so that we can replace with new ones
1246
- NodeCopy-> MSuccessors .clear ();
1247
- NodeCopy-> MPredecessors .clear ();
1244
+ NodeCopy. MSuccessors .clear ();
1245
+ NodeCopy. MPredecessors .clear ();
1248
1246
// Push the new node to the front of the stack
1249
- NewNodes.push_back (NodeCopy);
1250
1247
// Associate the new node with the old one for updating edges
1251
- NodesMap.insert ({OriginalNode, NodeCopy});
1248
+ NodesMap.insert ({& OriginalNode, & NodeCopy});
1252
1249
}
1253
1250
1254
1251
// Now that all nodes have been copied rebuild edges on new nodes. This must
1255
1252
// be done as a separate step since successors may be out of order.
1256
- for (size_t i = 0 ; i < ModifiableNodes.size (); i++) {
1257
- auto OriginalNode = ModifiableNodes[i];
1258
- auto NodeCopy = NewNodes[i];
1253
+ auto OrigIt = ModifiableNodes.begin (), OrigEnd = ModifiableNodes.end ();
1254
+ for (auto NewIt = NewNodes.begin (); OrigIt != OrigEnd; ++OrigIt, ++NewIt) {
1255
+ node_impl &OriginalNode = *OrigIt;
1256
+ node_impl &NodeCopy = **NewIt;
1259
1257
// Look through all the original node successors, find their copies and
1260
1258
// register those as successors with the current copied node
1261
- for (node_impl &NextNode : OriginalNode-> successors ()) {
1262
- node_impl &Successor = *NodesMap.at (NextNode. shared_from_this () );
1263
- NodeCopy-> registerSuccessor (Successor);
1259
+ for (node_impl &NextNode : OriginalNode. successors ()) {
1260
+ node_impl &Successor = *NodesMap.at (& NextNode);
1261
+ NodeCopy. registerSuccessor (Successor);
1264
1262
}
1265
1263
}
1266
1264
@@ -1273,49 +1271,47 @@ void exec_graph_impl::duplicateNodes() {
1273
1271
if (NewNode->MNodeType != node_type::subgraph) {
1274
1272
continue ;
1275
1273
}
1276
- const std::vector<std::shared_ptr<node_impl>> &SubgraphNodes =
1277
- NewNode->MSubGraphImpl ->MNodeStorage ;
1274
+ nodes_range SubgraphNodes{NewNode->MSubGraphImpl ->MNodeStorage };
1278
1275
std::deque<std::shared_ptr<node_impl>> NewSubgraphNodes{};
1279
1276
1280
1277
// Map of original subgraph nodes (keys) to new duplicated nodes (values)
1281
- std::map<std::shared_ptr<node_impl>, std::shared_ptr<node_impl>>
1282
- SubgraphNodesMap;
1278
+ std::map<node_impl *, node_impl *> SubgraphNodesMap;
1283
1279
1284
1280
// Copy subgraph nodes
1285
- for (size_t i = 0 ; i < SubgraphNodes. size (); i++ ) {
1286
- auto SubgraphNode = SubgraphNodes[i] ;
1287
- auto NodeCopy = std::make_shared<node_impl>(*SubgraphNode );
1281
+ for (node_impl &SubgraphNode : SubgraphNodes) {
1282
+ NewSubgraphNodes. push_back (std::make_shared<node_impl>( SubgraphNode)) ;
1283
+ node_impl & NodeCopy = *NewSubgraphNodes. back ( );
1288
1284
// Associate the ID of the original subgraph node with all extracted node
1289
1285
// copies for future quick access.
1290
- MIDCache.insert (std::make_pair (SubgraphNode-> MID , NodeCopy));
1286
+ MIDCache.insert (std::make_pair (SubgraphNode. MID , & NodeCopy));
1291
1287
1292
- NewSubgraphNodes.push_back (NodeCopy);
1293
- SubgraphNodesMap.insert ({SubgraphNode, NodeCopy});
1294
- NodeCopy->MSuccessors .clear ();
1295
- NodeCopy->MPredecessors .clear ();
1288
+ SubgraphNodesMap.insert ({&SubgraphNode, &NodeCopy});
1289
+ NodeCopy.MSuccessors .clear ();
1290
+ NodeCopy.MPredecessors .clear ();
1296
1291
}
1297
1292
1298
1293
// Rebuild edges for new subgraph nodes
1299
- for (size_t i = 0 ; i < SubgraphNodes.size (); i++) {
1300
- auto SubgraphNode = SubgraphNodes[i];
1301
- auto NodeCopy = NewSubgraphNodes[i];
1302
-
1303
- for (node_impl &NextNode : SubgraphNode->successors ()) {
1304
- node_impl &Successor =
1305
- *SubgraphNodesMap.at (NextNode.shared_from_this ());
1306
- NodeCopy->registerSuccessor (Successor);
1294
+ auto OrigIt = SubgraphNodes.begin (), OrigEnd = SubgraphNodes.end ();
1295
+ for (auto NewIt = NewSubgraphNodes.begin (); OrigIt != OrigEnd;
1296
+ ++OrigIt, ++NewIt) {
1297
+ node_impl &SubgraphNode = *OrigIt;
1298
+ node_impl &NodeCopy = **NewIt;
1299
+
1300
+ for (node_impl &NextNode : SubgraphNode.successors ()) {
1301
+ node_impl &Successor = *SubgraphNodesMap.at (&NextNode);
1302
+ NodeCopy.registerSuccessor (Successor);
1307
1303
}
1308
1304
}
1309
1305
1310
1306
// Collect input and output nodes for the subgraph
1311
- std::vector<std::shared_ptr< node_impl> > Inputs;
1312
- std::vector<std::shared_ptr< node_impl> > Outputs;
1313
- for (auto &NodeImpl : NewSubgraphNodes) {
1307
+ std::vector<node_impl * > Inputs;
1308
+ std::vector<node_impl * > Outputs;
1309
+ for (std::shared_ptr<node_impl> &NodeImpl : NewSubgraphNodes) {
1314
1310
if (NodeImpl->MPredecessors .size () == 0 ) {
1315
- Inputs.push_back (NodeImpl);
1311
+ Inputs.push_back (&* NodeImpl);
1316
1312
}
1317
1313
if (NodeImpl->MSuccessors .size () == 0 ) {
1318
- Outputs.push_back (NodeImpl);
1314
+ Outputs.push_back (&* NodeImpl);
1319
1315
}
1320
1316
}
1321
1317
@@ -1335,7 +1331,7 @@ void exec_graph_impl::duplicateNodes() {
1335
1331
1336
1332
// Add all input nodes from the subgraph as successors for this node
1337
1333
// instead
1338
- for (auto & Input : Inputs) {
1334
+ for (node_impl * Input : Inputs) {
1339
1335
PredNode.registerSuccessor (*Input);
1340
1336
}
1341
1337
}
@@ -1354,7 +1350,7 @@ void exec_graph_impl::duplicateNodes() {
1354
1350
1355
1351
// Add all Output nodes from the subgraph as predecessors for this node
1356
1352
// instead
1357
- for (auto & Output : Outputs) {
1353
+ for (node_impl * Output : Outputs) {
1358
1354
Output->registerSuccessor (SuccNode);
1359
1355
}
1360
1356
}
@@ -1365,15 +1361,18 @@ void exec_graph_impl::duplicateNodes() {
1365
1361
NewNodes.erase (std::find (NewNodes.begin (), NewNodes.end (), NewNode));
1366
1362
// Also set the iterator to the newly added nodes so we can continue
1367
1363
// iterating over all remaining nodes
1368
- auto InsertIt = NewNodes.insert (OldPositionIt, NewSubgraphNodes.begin (),
1369
- NewSubgraphNodes.end ());
1364
+ auto InsertIt = NewNodes.insert (
1365
+ OldPositionIt, std::make_move_iterator (NewSubgraphNodes.begin ()),
1366
+ std::make_move_iterator (NewSubgraphNodes.end ()));
1370
1367
// Since the new reverse_iterator will be at i - 1 we need to advance it
1371
1368
// when constructing
1372
1369
NewNodeIt = std::make_reverse_iterator (std::next (InsertIt));
1373
1370
}
1374
1371
1375
1372
// Store all the new nodes locally
1376
- MNodeStorage.insert (MNodeStorage.begin (), NewNodes.begin (), NewNodes.end ());
1373
+ MNodeStorage.insert (MNodeStorage.begin (),
1374
+ std::make_move_iterator (NewNodes.begin ()),
1375
+ std::make_move_iterator (NewNodes.end ()));
1377
1376
}
1378
1377
1379
1378
void exec_graph_impl::update (std::shared_ptr<graph_impl> GraphImpl) {
@@ -1438,7 +1437,7 @@ void exec_graph_impl::update(std::shared_ptr<graph_impl> GraphImpl) {
1438
1437
1439
1438
for (uint32_t i = 0 ; i < MNodeStorage.size (); ++i) {
1440
1439
MIDCache.insert (
1441
- std::make_pair (GraphImpl->MNodeStorage [i]->MID , MNodeStorage[i]));
1440
+ std::make_pair (GraphImpl->MNodeStorage [i]->MID , MNodeStorage[i]. get () ));
1442
1441
}
1443
1442
1444
1443
update (GraphImpl->MNodeStorage );
@@ -1711,7 +1710,7 @@ void exec_graph_impl::populateURKernelUpdateStructs(
1711
1710
auto ExecNode = MIDCache.find (Node->MID );
1712
1711
assert (ExecNode != MIDCache.end () && " Node ID was not found in ID cache" );
1713
1712
1714
- auto Command = MCommandMap.find (ExecNode->second . get () );
1713
+ auto Command = MCommandMap.find (ExecNode->second );
1715
1714
assert (Command != MCommandMap.end ());
1716
1715
UpdateDesc.hCommand = Command->second ;
1717
1716
@@ -1741,7 +1740,7 @@ exec_graph_impl::getURUpdatableNodes(
1741
1740
1742
1741
auto ExecNode = MIDCache.find (Node->MID );
1743
1742
assert (ExecNode != MIDCache.end () && " Node ID was not found in ID cache" );
1744
- auto PartitionIndex = MPartitionNodes.find (ExecNode->second . get () );
1743
+ auto PartitionIndex = MPartitionNodes.find (ExecNode->second );
1745
1744
assert (PartitionIndex != MPartitionNodes.end ());
1746
1745
PartitionedNodes[PartitionIndex->second ].push_back (Node);
1747
1746
}
0 commit comments