@@ -409,10 +409,9 @@ void graph_impl::markCGMemObjs(
409
409
}
410
410
}
411
411
412
- std::shared_ptr<node_impl> graph_impl::add (nodes_range Deps) {
413
- const std::shared_ptr<node_impl> &NodeImpl = std::make_shared<node_impl>();
414
-
415
- MNodeStorage.push_back (NodeImpl);
412
+ node_impl &graph_impl::add (nodes_range Deps) {
413
+ MNodeStorage.push_back (std::make_shared<node_impl>());
414
+ node_impl &NodeImpl = *MNodeStorage.back ();
416
415
417
416
addDepsToNode (NodeImpl, Deps);
418
417
// Add an event associated with this explicit node for mixed usage
@@ -421,10 +420,9 @@ std::shared_ptr<node_impl> graph_impl::add(nodes_range Deps) {
421
420
return NodeImpl;
422
421
}
423
422
424
- std::shared_ptr<node_impl>
425
- graph_impl::add (std::function<void (handler &)> CGF,
426
- const std::vector<sycl::detail::ArgDesc> &Args,
427
- std::vector<std::shared_ptr<node_impl>> &Deps) {
423
+ node_impl &graph_impl::add (std::function<void (handler &)> CGF,
424
+ const std::vector<sycl::detail::ArgDesc> &Args,
425
+ nodes_range Deps) {
428
426
(void )Args;
429
427
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
430
428
detail::handler_impl HandlerImpl{*this };
@@ -435,7 +433,9 @@ graph_impl::add(std::function<void(handler &)> CGF,
435
433
436
434
// Pass the node deps to the handler so they are available when processing the
437
435
// CGF, need for async_malloc nodes.
438
- Handler.impl ->MNodeDeps = Deps;
436
+ Handler.impl ->MNodeDeps .clear (); // TODO: Is that right?
437
+ for (node_impl &N : Deps)
438
+ Handler.impl ->MNodeDeps .push_back (N.shared_from_this ());
439
439
440
440
#if XPTI_ENABLE_INSTRUMENTATION
441
441
// Save code location if one was set in TLS.
@@ -471,7 +471,7 @@ graph_impl::add(std::function<void(handler &)> CGF,
471
471
: ext::oneapi::experimental::detail::getNodeTypeFromCG (
472
472
Handler.getType ());
473
473
474
- auto NodeImpl =
474
+ node_impl & NodeImpl =
475
475
this ->add (NodeType, std::move (Handler.impl ->MGraphNodeCG ), Deps);
476
476
477
477
// Add an event associated with this explicit node for mixed usage
@@ -489,26 +489,25 @@ graph_impl::add(std::function<void(handler &)> CGF,
489
489
}
490
490
491
491
for (auto &[DynamicParam, ArgIndex] : DynamicParams) {
492
- DynamicParam->registerNode (NodeImpl, ArgIndex);
492
+ DynamicParam->registerNode (NodeImpl. shared_from_this () , ArgIndex);
493
493
}
494
494
495
495
return NodeImpl;
496
496
}
497
497
498
- std::shared_ptr<node_impl>
499
- graph_impl::add (node_type NodeType,
500
- std::shared_ptr<sycl::detail::CG> CommandGroup,
501
- nodes_range Deps) {
498
+ node_impl &graph_impl::add (node_type NodeType,
499
+ std::shared_ptr<sycl::detail::CG> CommandGroup,
500
+ nodes_range Deps) {
502
501
503
502
// A unique set of dependencies obtained by checking requirements and events
504
503
std::set<std::shared_ptr<node_impl>> UniqueDeps = getCGEdges (CommandGroup);
505
504
506
505
// Track and mark the memory objects being used by the graph.
507
506
markCGMemObjs (CommandGroup);
508
507
509
- const std::shared_ptr<node_impl> &NodeImpl =
510
- std::make_shared<node_impl>(NodeType, std::move (CommandGroup));
511
- MNodeStorage.push_back (NodeImpl );
508
+ MNodeStorage. push_back (
509
+ std::make_shared<node_impl>(NodeType, std::move (CommandGroup))) ;
510
+ node_impl &NodeImpl = * MNodeStorage.back ( );
512
511
513
512
// Add any deps determined from requirements and events into the dependency
514
513
// list
@@ -517,16 +516,18 @@ graph_impl::add(node_type NodeType,
517
516
518
517
if (NodeType == node_type::async_free) {
519
518
auto AsyncFreeCG =
520
- static_cast <CGAsyncFree *>(NodeImpl-> MCommandGroup .get ());
519
+ static_cast <CGAsyncFree *>(NodeImpl. MCommandGroup .get ());
521
520
// If this is an async free node mark that it is now available for reuse,
522
521
// and pass the async free node for tracking.
523
- MGraphMemPool.markAllocationAsAvailable (AsyncFreeCG->getPtr (), NodeImpl);
522
+ MGraphMemPool.markAllocationAsAvailable (AsyncFreeCG->getPtr (),
523
+ // TODO: use raw
524
+ NodeImpl.shared_from_this ());
524
525
}
525
526
526
527
return NodeImpl;
527
528
}
528
529
529
- std::shared_ptr< node_impl>
530
+ node_impl&
530
531
graph_impl::add (std::shared_ptr<dynamic_command_group_impl> &DynCGImpl,
531
532
nodes_range Deps) {
532
533
// Set of Dependent nodes based on CG event and accessor dependencies.
@@ -551,15 +552,14 @@ graph_impl::add(std::shared_ptr<dynamic_command_group_impl> &DynCGImpl,
551
552
const auto &ActiveKernel = DynCGImpl->getActiveCG ();
552
553
node_type NodeType =
553
554
ext::oneapi::experimental::detail::getNodeTypeFromCG (DynCGImpl->MCGType );
554
- std::shared_ptr<detail::node_impl> NodeImpl =
555
- add (NodeType, ActiveKernel, Deps);
555
+ detail::node_impl &NodeImpl = add (NodeType, ActiveKernel, Deps);
556
556
557
557
// Add an event associated with this explicit node for mixed usage
558
558
addEventForNode (sycl::detail::event_impl::create_completed_host_event (),
559
559
NodeImpl);
560
560
561
561
// Track the dynamic command-group used inside the node object
562
- DynCGImpl->MNodes .push_back (NodeImpl);
562
+ DynCGImpl->MNodes .push_back (NodeImpl. shared_from_this () );
563
563
564
564
return NodeImpl;
565
565
}
@@ -652,7 +652,7 @@ void graph_impl::makeEdge(std::shared_ptr<node_impl> Src,
652
652
bool DestWasGraphRoot = Dest->MPredecessors .size () == 0 ;
653
653
654
654
// We need to add the edges first before checking for cycles
655
- Src->registerSuccessor (Dest);
655
+ Src->registerSuccessor (* Dest);
656
656
657
657
bool DestLostRootStatus = DestWasGraphRoot && Dest->MPredecessors .size () == 1 ;
658
658
if (DestLostRootStatus) {
@@ -1265,7 +1265,7 @@ void exec_graph_impl::duplicateNodes() {
1265
1265
// Look through all the original node successors, find their copies and
1266
1266
// register those as successors with the current copied node
1267
1267
for (node_impl &NextNode : OriginalNode->successors ()) {
1268
- auto Successor = NodesMap.at (NextNode.shared_from_this ());
1268
+ node_impl & Successor = * NodesMap.at (NextNode.shared_from_this ());
1269
1269
NodeCopy->registerSuccessor (Successor);
1270
1270
}
1271
1271
}
@@ -1307,7 +1307,7 @@ void exec_graph_impl::duplicateNodes() {
1307
1307
auto NodeCopy = NewSubgraphNodes[i];
1308
1308
1309
1309
for (node_impl &NextNode : SubgraphNode->successors ()) {
1310
- auto Successor = SubgraphNodesMap.at (NextNode.shared_from_this ());
1310
+ node_impl & Successor = * SubgraphNodesMap.at (NextNode.shared_from_this ());
1311
1311
NodeCopy->registerSuccessor (Successor);
1312
1312
}
1313
1313
}
@@ -1341,7 +1341,7 @@ void exec_graph_impl::duplicateNodes() {
1341
1341
// Add all input nodes from the subgraph as successors for this node
1342
1342
// instead
1343
1343
for (auto &Input : Inputs) {
1344
- PredNode.registerSuccessor (Input);
1344
+ PredNode.registerSuccessor (* Input);
1345
1345
}
1346
1346
}
1347
1347
@@ -1360,7 +1360,7 @@ void exec_graph_impl::duplicateNodes() {
1360
1360
// Add all Output nodes from the subgraph as predecessors for this node
1361
1361
// instead
1362
1362
for (auto &Output : Outputs) {
1363
- Output->registerSuccessor (SuccNode. shared_from_this () );
1363
+ Output->registerSuccessor (SuccNode);
1364
1364
}
1365
1365
}
1366
1366
@@ -1843,38 +1843,25 @@ node modifiable_command_graph::addImpl(dynamic_command_group &DynCGF,
1843
1843
" dynamic command-group." );
1844
1844
}
1845
1845
1846
- std::vector<std::shared_ptr<detail::node_impl>> DepImpls;
1847
- for (auto &D : Deps) {
1848
- DepImpls.push_back (sycl::detail::getSyclObjImpl (D));
1849
- }
1850
-
1851
1846
graph_impl::WriteLock Lock (impl->MMutex );
1852
- std::shared_ptr< detail::node_impl> NodeImpl = impl->add (DynCGFImpl, DepImpls );
1853
- return sycl::detail::createSyclObjFromImpl<node>(std::move ( NodeImpl) );
1847
+ detail::node_impl & NodeImpl = impl->add (DynCGFImpl, Deps );
1848
+ return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1854
1849
}
1855
1850
1856
1851
node modifiable_command_graph::addImpl (const std::vector<node> &Deps) {
1857
1852
impl->throwIfGraphRecordingQueue (" Explicit API \" Add()\" function" );
1858
- std::vector<std::shared_ptr<detail::node_impl>> DepImpls;
1859
- for (auto &D : Deps) {
1860
- DepImpls.push_back (sycl::detail::getSyclObjImpl (D));
1861
- }
1862
1853
1863
1854
graph_impl::WriteLock Lock (impl->MMutex );
1864
- std::shared_ptr< detail::node_impl> NodeImpl = impl->add (DepImpls );
1865
- return sycl::detail::createSyclObjFromImpl<node>(std::move ( NodeImpl) );
1855
+ detail::node_impl & NodeImpl = impl->add (Deps );
1856
+ return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1866
1857
}
1867
1858
1868
1859
node modifiable_command_graph::addImpl (std::function<void (handler &)> CGF,
1869
1860
const std::vector<node> &Deps) {
1870
1861
impl->throwIfGraphRecordingQueue (" Explicit API \" Add()\" function" );
1871
- std::vector<std::shared_ptr<detail::node_impl>> DepImpls;
1872
- for (auto &D : Deps) {
1873
- DepImpls.push_back (sycl::detail::getSyclObjImpl (D));
1874
- }
1875
1862
1876
- std::shared_ptr< detail::node_impl> NodeImpl = impl->add (CGF, {}, DepImpls );
1877
- return sycl::detail::createSyclObjFromImpl<node>(std::move ( NodeImpl) );
1863
+ detail::node_impl & NodeImpl = impl->add (CGF, {}, Deps );
1864
+ return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1878
1865
}
1879
1866
1880
1867
void modifiable_command_graph::addGraphLeafDependencies (node Node) {
0 commit comments