Skip to content

Commit 5126284

Browse files
[SYCL] Do not lock event_impl when it not shared with other threads (#18193)
The code was added in 64546e7, but locks are superfluous. --------- Signed-off-by: Alexandr Konovalov <[email protected]> Co-authored-by: Marcos Maronas <[email protected]>
1 parent d21bb39 commit 5126284

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

sycl/source/detail/event_impl.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ void event_impl::cleanupDependencyEvents() {
570570
MPreparedHostDepsEvents.clear();
571571
}
572572

573-
void event_impl::cleanDepEventsThroughOneLevel() {
574-
std::lock_guard<std::mutex> Lock(MMutex);
573+
void event_impl::cleanDepEventsThroughOneLevelUnlocked() {
575574
for (auto &Event : MPreparedDepsEvents) {
576575
Event->cleanupDependencyEvents();
577576
}
@@ -580,6 +579,11 @@ void event_impl::cleanDepEventsThroughOneLevel() {
580579
}
581580
}
582581

582+
void event_impl::cleanDepEventsThroughOneLevel() {
583+
std::lock_guard<std::mutex> Lock(MMutex);
584+
cleanDepEventsThroughOneLevelUnlocked();
585+
}
586+
583587
void event_impl::setSubmissionTime() {
584588
if (!MIsProfilingEnabled && !MProfilingTagEvent)
585589
return;

sycl/source/detail/event_impl.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class event_impl {
217217
/// Cleans dependencies of this event's dependencies.
218218
void cleanDepEventsThroughOneLevel();
219219

220+
/// Cleans dependencies of this event's dependencies w/o locking MMutex.
221+
void cleanDepEventsThroughOneLevelUnlocked();
222+
220223
/// Checks if this event is discarded by SYCL implementation.
221224
///
222225
/// \return true if this event is discarded.

sycl/source/detail/queue_impl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ event queue_impl::submitMemOpHelper(const std::shared_ptr<queue_impl> &Self,
442442
ExpandedDepEventImplPtrs.push_back(
443443
detail::getSyclObjImpl(DepEvent));
444444

445-
EventImpl->cleanDepEventsThroughOneLevel();
445+
// EventImpl is local for current thread, no need to lock.
446+
EventImpl->cleanDepEventsThroughOneLevelUnlocked();
446447
}
447448
}
448449

sycl/source/handler.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,11 @@ event handler::finalize() {
572572
LastEventImpl->setEnqueued();
573573
// connect returned event with dependent events
574574
if (!MQueue->isInOrder()) {
575-
LastEventImpl->getPreparedDepsEvents() = impl->CGData.MEvents;
576-
LastEventImpl->cleanDepEventsThroughOneLevel();
575+
// MEvents is not used anymore, so can move.
576+
LastEventImpl->getPreparedDepsEvents() =
577+
std::move(impl->CGData.MEvents);
578+
// LastEventImpl is local for current thread, no need to lock.
579+
LastEventImpl->cleanDepEventsThroughOneLevelUnlocked();
577580
}
578581
}
579582
return MLastEvent;

0 commit comments

Comments
 (0)