Skip to content

[SYCL] Do not lock event_impl when it not shared with other threads #18193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,7 @@ void event_impl::cleanupDependencyEvents() {
MPreparedHostDepsEvents.clear();
}

void event_impl::cleanDepEventsThroughOneLevel() {
std::lock_guard<std::mutex> Lock(MMutex);
void event_impl::cleanDepEventsThroughOneLevelUnlocked() {
for (auto &Event : MPreparedDepsEvents) {
Event->cleanupDependencyEvents();
}
Expand All @@ -580,6 +579,11 @@ void event_impl::cleanDepEventsThroughOneLevel() {
}
}

void event_impl::cleanDepEventsThroughOneLevel() {
std::lock_guard<std::mutex> Lock(MMutex);
cleanDepEventsThroughOneLevelUnlocked();
}

void event_impl::setSubmissionTime() {
if (!MIsProfilingEnabled && !MProfilingTagEvent)
return;
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class event_impl {
/// Cleans dependencies of this event's dependencies.
void cleanDepEventsThroughOneLevel();

/// Cleans dependencies of this event's dependencies w/o locking MMutex.
void cleanDepEventsThroughOneLevelUnlocked();

/// Checks if this event is discarded by SYCL implementation.
///
/// \return true if this event is discarded.
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
ExpandedDepEventImplPtrs.push_back(
detail::getSyclObjImpl(DepEvent));

EventImpl->cleanDepEventsThroughOneLevel();
// EventImpl is local for current thread, no need to lock.
EventImpl->cleanDepEventsThroughOneLevelUnlocked();
}
}

Expand Down
7 changes: 5 additions & 2 deletions sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,11 @@ event handler::finalize() {
LastEventImpl->setEnqueued();
// connect returned event with dependent events
if (!MQueue->isInOrder()) {
LastEventImpl->getPreparedDepsEvents() = impl->CGData.MEvents;
LastEventImpl->cleanDepEventsThroughOneLevel();
// MEvents is not used anymore, so can move.
LastEventImpl->getPreparedDepsEvents() =
std::move(impl->CGData.MEvents);
// LastEventImpl is local for current thread, no need to lock.
LastEventImpl->cleanDepEventsThroughOneLevelUnlocked();
}
}
return MLastEvent;
Expand Down