diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index f0908eb9742b5..2e8c6abb24eae 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -570,8 +570,7 @@ void event_impl::cleanupDependencyEvents() { MPreparedHostDepsEvents.clear(); } -void event_impl::cleanDepEventsThroughOneLevel() { - std::lock_guard Lock(MMutex); +void event_impl::cleanDepEventsThroughOneLevelUnlocked() { for (auto &Event : MPreparedDepsEvents) { Event->cleanupDependencyEvents(); } @@ -580,6 +579,11 @@ void event_impl::cleanDepEventsThroughOneLevel() { } } +void event_impl::cleanDepEventsThroughOneLevel() { + std::lock_guard Lock(MMutex); + cleanDepEventsThroughOneLevelUnlocked(); +} + void event_impl::setSubmissionTime() { if (!MIsProfilingEnabled && !MProfilingTagEvent) return; diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index e07098200b57d..b9e75ca0811df 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -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. diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index ef00ec1a8fb9c..07a6854df7dfb 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -439,7 +439,8 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr &Self, ExpandedDepEventImplPtrs.push_back( detail::getSyclObjImpl(DepEvent)); - EventImpl->cleanDepEventsThroughOneLevel(); + // EventImpl is local for current thread, no need to lock. + EventImpl->cleanDepEventsThroughOneLevelUnlocked(); } } diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 586dd85ba25a2..73843ccc9ca1d 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -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;