@@ -771,16 +771,28 @@ class partition {
771
771
std::unordered_map<sycl::device, ur_exp_command_buffer_handle_t >
772
772
MCommandBuffers;
773
773
// / List of predecessors to this partition.
774
- std::vector<std::shared_ptr<partition>> MPredecessors;
774
+ std::vector<partition *> MPredecessors;
775
+
776
+ // / List of successors to this partition.
777
+ std::vector<partition *> MSuccessors;
778
+
779
+ // / List of requirements for this partition.
780
+ std::vector<sycl::detail::AccessorImplHost *> MRequirements;
781
+
782
+ // / Storage for accessors which are used by this partition.
783
+ std::vector<AccessorImplPtr> MAccessors;
784
+
775
785
// / True if the graph of this partition is a single path graph
776
786
// / and in-order optmization can be applied on it.
777
787
bool MIsInOrderGraph = false ;
778
788
779
- // / @return True if the partition contains a host task
780
- bool isHostTask () const {
781
- return (MRoots.size () && ((*MRoots.begin ()).lock ()->MCGType ==
782
- sycl::detail::CGType::CodeplayHostTask));
783
- }
789
+ // / True if this partition contains only one node which is a host_task.
790
+ bool MIsHostTask = false ;
791
+
792
+ // Submission event for the partition. Used during enqueue to define
793
+ // dependencies between this partition and its successors. This event is
794
+ // replaced every time the partition is executed.
795
+ EventImplPtr MEvent;
784
796
785
797
// / Checks if the graph is single path, i.e. each node has a single successor.
786
798
// / @return True if the graph is a single path
@@ -1330,9 +1342,17 @@ class exec_graph_impl {
1330
1342
// / execution.
1331
1343
// / @param Queue Command-queue to schedule execution on.
1332
1344
// / @param CGData Command-group data provided by the sycl::handler
1333
- // / @return Event associated with the execution of the graph.
1334
- sycl::event enqueue (sycl::detail::queue_impl &Queue,
1335
- sycl::detail::CG::StorageInitHelper CGData);
1345
+ // / @param EventNeeded Whether an event signalling the completion of this
1346
+ // / operation needs to be returned.
1347
+ // / @return Returns an event if EventNeeded is true. Returns nullptr
1348
+ // / otherwise.
1349
+ EventImplPtr enqueue (sycl::detail::queue_impl &Queue,
1350
+ sycl::detail::CG::StorageInitHelper CGData,
1351
+ bool EventNeeded);
1352
+
1353
+ // / Iterates through all the nodes in the graph to build the list of
1354
+ // / accessor requirements for the whole graph and for each partition.
1355
+ void buildRequirements ();
1336
1356
1337
1357
// / Turns the internal graph representation into UR command-buffers for a
1338
1358
// / device.
@@ -1366,13 +1386,17 @@ class exec_graph_impl {
1366
1386
return MPartitions;
1367
1387
}
1368
1388
1389
+ // / Query whether the graph contains any host-task nodes.
1390
+ // / @return True if the graph contains any host-task nodes. False otherwise.
1391
+ bool containsHostTask () const { return MContainsHostTask; }
1392
+
1369
1393
// / Checks if the previous submissions of this graph have been completed
1370
1394
// / This function checks the status of events associated to the previous graph
1371
1395
// / submissions.
1372
1396
// / @return true if all previous submissions have been completed, false
1373
1397
// / otherwise.
1374
1398
bool previousSubmissionCompleted () const {
1375
- for (auto Event : MExecutionEvents ) {
1399
+ for (auto Event : MSchedulerDependencies ) {
1376
1400
if (!Event->isCompleted ()) {
1377
1401
return false ;
1378
1402
}
@@ -1447,6 +1471,65 @@ class exec_graph_impl {
1447
1471
ur_exp_command_buffer_handle_t CommandBuffer,
1448
1472
std::shared_ptr<node_impl> Node);
1449
1473
1474
+ // / Enqueues a host-task partition (i.e. a partition that contains only a
1475
+ // / single node and that node is a host-task).
1476
+ // / @param Partition The partition to enqueue.
1477
+ // / @param Queue Command-queue to schedule execution on.
1478
+ // / @param CGData Command-group data used for initializing the host-task
1479
+ // / command-group.
1480
+ // / @param EventNeeded Whether an event signalling the completion of this
1481
+ // / operation needs to be returned.
1482
+ // / @return If EventNeeded is true returns the event resulting from enqueueing
1483
+ // / the host-task through the scheduler. Returns nullptr otherwise.
1484
+ EventImplPtr enqueueHostTaskPartition (
1485
+ std::shared_ptr<partition> &Partition, sycl::detail::queue_impl &Queue,
1486
+ sycl::detail::CG::StorageInitHelper CGData, bool EventNeeded);
1487
+
1488
+ // / Enqueues a graph partition that contains no host-tasks using the
1489
+ // / scheduler.
1490
+ // / @param Partition The partition to enqueue.
1491
+ // / @param Queue Command-queue to schedule execution on.
1492
+ // / @param CGData Command-group data used for initializing the command-buffer
1493
+ // / command-group.
1494
+ // / @param EventNeeded Whether an event signalling the completion of this
1495
+ // / operation needs to be returned.
1496
+ // / @return If EventNeeded is true returns the event resulting from enqueueing
1497
+ // / the command-buffer through the scheduler. Returns nullptr otherwise.
1498
+ EventImplPtr enqueuePartitionWithScheduler (
1499
+ std::shared_ptr<partition> &Partition, sycl::detail::queue_impl &Queue,
1500
+ sycl::detail::CG::StorageInitHelper CGData, bool EventNeeded);
1501
+
1502
+ // / Enqueues a graph partition that contains no host-tasks by directly calling
1503
+ // / the unified-runtime API (i.e. avoids scheduler overhead).
1504
+ // / @param Partition The partition to enqueue.
1505
+ // / @param Queue Command-queue to schedule execution on.
1506
+ // / @param WaitEvents List of events to wait on. All the events on this list
1507
+ // / must be safe for scheduler bypass. Only events containing a valid UR event
1508
+ // / handle will be waited for.
1509
+ // / @param EventNeeded Whether an event signalling the completion of this
1510
+ // / operation needs to be returned.
1511
+ // / @return If EventNeeded is true returns the event resulting from enqueueing
1512
+ // / the command-buffer. Returns nullptr otherwise.
1513
+ EventImplPtr enqueuePartitionDirectly (
1514
+ std::shared_ptr<partition> &Partition, sycl::detail::queue_impl &Queue,
1515
+ std::vector<detail::EventImplPtr> &WaitEvents, bool EventNeeded);
1516
+
1517
+ // / Enqueues all the partitions in a graph.
1518
+ // / @param Queue Command-queue to schedule execution on.
1519
+ // / @param CGData Command-group data that contains the dependencies and
1520
+ // / accessor requirements needed to enqueue this graph.
1521
+ // / @param IsCGDataSafeForSchedulerBypass Whether CGData contains any events
1522
+ // / that require enqueuing through the scheduler (e.g. requirements or
1523
+ // / host-task events).
1524
+ // / @param EventNeeded Whether an event signalling the completion of this
1525
+ // / operation needs to be returned.
1526
+ // / @return If EventNeeded is true returns the event resulting from enqueueing
1527
+ // / the command-buffer. Returns nullptr otherwise.
1528
+ EventImplPtr enqueuePartitions (sycl::detail::queue_impl &Queue,
1529
+ sycl::detail::CG::StorageInitHelper &CGData,
1530
+ bool IsCGDataSafeForSchedulerBypass,
1531
+ bool EventNeeded);
1532
+
1450
1533
// / Iterates back through predecessors to find the real dependency.
1451
1534
// / @param[out] Deps Found dependencies.
1452
1535
// / @param[in] CurrentNode Node to find dependencies for.
@@ -1541,11 +1624,9 @@ class exec_graph_impl {
1541
1624
// / List of requirements for enqueueing this command graph, accumulated from
1542
1625
// / all nodes enqueued to the graph.
1543
1626
std::vector<sycl::detail::AccessorImplHost *> MRequirements;
1544
- // / Storage for accessors which are used by this graph, accumulated from
1545
- // / all nodes enqueued to the graph.
1546
- std::vector<sycl::detail::AccessorImplPtr> MAccessors;
1547
- // / List of all execution events returned from command buffer enqueue calls.
1548
- std::vector<sycl::detail::EventImplPtr> MExecutionEvents;
1627
+ // / List of dependencies that enqueue or update commands need to wait on
1628
+ // / when using the scheduler path.
1629
+ std::vector<sycl::detail::EventImplPtr> MSchedulerDependencies;
1549
1630
// / List of the partitions that compose the exec graph.
1550
1631
std::vector<std::shared_ptr<partition>> MPartitions;
1551
1632
// / Storage for copies of nodes from the original modifiable graph.
@@ -1554,6 +1635,8 @@ class exec_graph_impl {
1554
1635
std::unordered_map<std::shared_ptr<node_impl>,
1555
1636
ur_exp_command_buffer_command_handle_t >
1556
1637
MCommandMap;
1638
+ // / List of partition without any predecessors in this exec graph.
1639
+ std::vector<std::weak_ptr<partition>> MRootPartitions;
1557
1640
// / True if this graph can be updated (set with property::updatable)
1558
1641
bool MIsUpdatable;
1559
1642
// / If true, the graph profiling is enabled.
0 commit comments