Skip to content

Commit

Permalink
[SYCL][Graph] Improve handling of the events returned from graph with…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
mfrancepillois and steffenlarsen committed Mar 5, 2024
1 parent bea047d commit 6e8cdb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ class event_impl {
return MEventFromSubmittedExecCommandBuffer;
}

const std::vector<EventImplPtr> &getPostCompleteEvents() const {
return MPostCompleteEvents;
}

protected:
// When instrumentation is enabled emits trace event for event wait begin and
// returns the telemetry event generated for the wait
Expand Down
16 changes: 12 additions & 4 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,9 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
sycl::detail::CG::StorageInitHelper CGData) {
WriteLock Lock(MMutex);

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

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

for (auto const &DepPartition : CurrentPartition->MPredecessors) {
CGData.MEvents.push_back(MPartitionsExecutionEvents[DepPartition]);
CGData.MEvents.push_back(PartitionsExecutionEvents[DepPartition]);
}

auto CommandBuffer =
Expand Down Expand Up @@ -819,7 +821,13 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
sycl::backend::ext_oneapi_level_zero) {
Event->wait(Event);
} else {
auto &AttachedEventsList = Event->getPostCompleteEvents();
CGData.MEvents.reserve(AttachedEventsList.size() + 1);
CGData.MEvents.push_back(Event);
// Add events of the previous execution of all graph partitions.
for (auto &AttachedEvent : AttachedEventsList) {
CGData.MEvents.push_back(AttachedEvent);
}
}
++It;
} else {
Expand Down Expand Up @@ -929,15 +937,15 @@ exec_graph_impl::enqueue(const std::shared_ptr<sycl::detail::queue_impl> &Queue,
NewEvent->setStateIncomplete();
NewEvent->getPreparedDepsEvents() = ScheduledEvents;
}
MPartitionsExecutionEvents[CurrentPartition] = NewEvent;
PartitionsExecutionEvents[CurrentPartition] = NewEvent;
}

// Keep track of this execution event so we can make sure it's completed in
// the destructor.
MExecutionEvents.push_back(NewEvent);
// Attach events of previous partitions to ensure that when the returned event
// is complete all execution associated with the graph have been completed.
for (auto const &Elem : MPartitionsExecutionEvents) {
for (auto const &Elem : PartitionsExecutionEvents) {
if (Elem.second != NewEvent) {
NewEvent->attachEventToComplete(Elem.second);
}
Expand Down
3 changes: 0 additions & 3 deletions sycl/source/detail/graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,6 @@ class exec_graph_impl {
std::vector<sycl::detail::EventImplPtr> MExecutionEvents;
/// List of the partitions that compose the exec graph.
std::vector<std::shared_ptr<partition>> MPartitions;
/// Map of the partitions to their execution events
std::unordered_map<std::shared_ptr<partition>, sycl::detail::EventImplPtr>
MPartitionsExecutionEvents;
/// Storage for copies of nodes from the original modifiable graph.
std::vector<std::shared_ptr<node_impl>> MNodeStorage;
};
Expand Down

0 comments on commit 6e8cdb1

Please sign in to comment.