Skip to content

Commit 6e8cdb1

Browse files
[SYCL][Graph] Improve handling of the events returned from graph with multiple partitions. (#12870)
Add attached events as dependencies when the graph is resubmitted. Change a class member to a function local variable. --------- Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent bea047d commit 6e8cdb1

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

sycl/source/detail/event_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ class event_impl {
289289
return MEventFromSubmittedExecCommandBuffer;
290290
}
291291

292+
const std::vector<EventImplPtr> &getPostCompleteEvents() const {
293+
return MPostCompleteEvents;
294+
}
295+
292296
protected:
293297
// When instrumentation is enabled emits trace event for event wait begin and
294298
// returns the telemetry event generated for the wait

sycl/source/detail/graph_impl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,9 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
764764
sycl::detail::CG::StorageInitHelper CGData) {
765765
WriteLock Lock(MMutex);
766766

767-
std::vector<sycl::detail::EventImplPtr> PartitionEvents;
767+
// Map of the partitions to their execution events
768+
std::unordered_map<std::shared_ptr<partition>, sycl::detail::EventImplPtr>
769+
PartitionsExecutionEvents;
768770

769771
auto CreateNewEvent([&]() {
770772
auto NewEvent = std::make_shared<sycl::detail::event_impl>(Queue);
@@ -787,7 +789,7 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
787789
}
788790

789791
for (auto const &DepPartition : CurrentPartition->MPredecessors) {
790-
CGData.MEvents.push_back(MPartitionsExecutionEvents[DepPartition]);
792+
CGData.MEvents.push_back(PartitionsExecutionEvents[DepPartition]);
791793
}
792794

793795
auto CommandBuffer =
@@ -819,7 +821,13 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
819821
sycl::backend::ext_oneapi_level_zero) {
820822
Event->wait(Event);
821823
} else {
824+
auto &AttachedEventsList = Event->getPostCompleteEvents();
825+
CGData.MEvents.reserve(AttachedEventsList.size() + 1);
822826
CGData.MEvents.push_back(Event);
827+
// Add events of the previous execution of all graph partitions.
828+
for (auto &AttachedEvent : AttachedEventsList) {
829+
CGData.MEvents.push_back(AttachedEvent);
830+
}
823831
}
824832
++It;
825833
} else {
@@ -929,15 +937,15 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
929937
NewEvent->setStateIncomplete();
930938
NewEvent->getPreparedDepsEvents() = ScheduledEvents;
931939
}
932-
MPartitionsExecutionEvents[CurrentPartition] = NewEvent;
940+
PartitionsExecutionEvents[CurrentPartition] = NewEvent;
933941
}
934942

935943
// Keep track of this execution event so we can make sure it's completed in
936944
// the destructor.
937945
MExecutionEvents.push_back(NewEvent);
938946
// Attach events of previous partitions to ensure that when the returned event
939947
// is complete all execution associated with the graph have been completed.
940-
for (auto const &Elem : MPartitionsExecutionEvents) {
948+
for (auto const &Elem : PartitionsExecutionEvents) {
941949
if (Elem.second != NewEvent) {
942950
NewEvent->attachEventToComplete(Elem.second);
943951
}

sycl/source/detail/graph_impl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,6 @@ class exec_graph_impl {
11901190
std::vector<sycl::detail::EventImplPtr> MExecutionEvents;
11911191
/// List of the partitions that compose the exec graph.
11921192
std::vector<std::shared_ptr<partition>> MPartitions;
1193-
/// Map of the partitions to their execution events
1194-
std::unordered_map<std::shared_ptr<partition>, sycl::detail::EventImplPtr>
1195-
MPartitionsExecutionEvents;
11961193
/// Storage for copies of nodes from the original modifiable graph.
11971194
std::vector<std::shared_ptr<node_impl>> MNodeStorage;
11981195
};

0 commit comments

Comments
 (0)