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