@@ -771,16 +771,28 @@ class partition {
771771 std::unordered_map<sycl::device, ur_exp_command_buffer_handle_t >
772772 MCommandBuffers;
773773 // / 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+
775785 // / True if the graph of this partition is a single path graph
776786 // / and in-order optmization can be applied on it.
777787 bool MIsInOrderGraph = false ;
778788
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;
784796
785797 // / Checks if the graph is single path, i.e. each node has a single successor.
786798 // / @return True if the graph is a single path
@@ -1330,9 +1342,17 @@ class exec_graph_impl {
13301342 // / execution.
13311343 // / @param Queue Command-queue to schedule execution on.
13321344 // / @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 ();
13361356
13371357 // / Turns the internal graph representation into UR command-buffers for a
13381358 // / device.
@@ -1366,13 +1386,17 @@ class exec_graph_impl {
13661386 return MPartitions;
13671387 }
13681388
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+
13691393 // / Checks if the previous submissions of this graph have been completed
13701394 // / This function checks the status of events associated to the previous graph
13711395 // / submissions.
13721396 // / @return true if all previous submissions have been completed, false
13731397 // / otherwise.
13741398 bool previousSubmissionCompleted () const {
1375- for (auto Event : MExecutionEvents ) {
1399+ for (auto Event : MSchedulerDependencies ) {
13761400 if (!Event->isCompleted ()) {
13771401 return false ;
13781402 }
@@ -1447,6 +1471,65 @@ class exec_graph_impl {
14471471 ur_exp_command_buffer_handle_t CommandBuffer,
14481472 std::shared_ptr<node_impl> Node);
14491473
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+
14501533 // / Iterates back through predecessors to find the real dependency.
14511534 // / @param[out] Deps Found dependencies.
14521535 // / @param[in] CurrentNode Node to find dependencies for.
@@ -1541,11 +1624,9 @@ class exec_graph_impl {
15411624 // / List of requirements for enqueueing this command graph, accumulated from
15421625 // / all nodes enqueued to the graph.
15431626 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;
15491630 // / List of the partitions that compose the exec graph.
15501631 std::vector<std::shared_ptr<partition>> MPartitions;
15511632 // / Storage for copies of nodes from the original modifiable graph.
@@ -1554,6 +1635,8 @@ class exec_graph_impl {
15541635 std::unordered_map<std::shared_ptr<node_impl>,
15551636 ur_exp_command_buffer_command_handle_t >
15561637 MCommandMap;
1638+ // / List of partition without any predecessors in this exec graph.
1639+ std::vector<std::weak_ptr<partition>> MRootPartitions;
15571640 // / True if this graph can be updated (set with property::updatable)
15581641 bool MIsUpdatable;
15591642 // / If true, the graph profiling is enabled.
0 commit comments