Skip to content

[SYCL] Do not take any locks in submit for in-order queue #18687

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
merged 1 commit into from
Jun 5, 2025
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
15 changes: 5 additions & 10 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,11 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,

auto requiresPostProcess = SubmitInfo.PostProcessorFunc() || Streams.size();
auto noLastEventPath = !isHostTask && !isGraphSubmission &&
MNoLastEventMode.load(std::memory_order_relaxed) &&
MNoLastEventMode.load(std::memory_order_acquire) &&
!requiresPostProcess;

if (noLastEventPath) {
std::unique_lock<std::mutex> Lock(MMutex);

// Check if we are still in no last event mode. There could
// have been a concurrent submit.
if (MNoLastEventMode.load(std::memory_order_relaxed)) {
return finalizeHandlerInOrderNoEventsUnlocked(Handler);
}
return finalizeHandlerInOrderNoEventsUnlocked(Handler);
}

detail::EventImplPtr EventImpl;
Expand Down Expand Up @@ -751,10 +745,11 @@ ur_native_handle_t queue_impl::getNative(int32_t &NativeHandleDesc) const {
bool queue_impl::queue_empty() const {
// If we have in-order queue with non-empty last event, just check its status.
if (isInOrder()) {
std::lock_guard<std::mutex> Lock(MMutex);
if (MEmpty)
if (MEmpty.load(std::memory_order_acquire))
return true;

std::lock_guard<std::mutex> Lock(MMutex);

if (MDefaultGraphDeps.LastEventPtr &&
!MDefaultGraphDeps.LastEventPtr->isDiscarded())
return MDefaultGraphDeps.LastEventPtr
Expand Down
9 changes: 3 additions & 6 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
detail::EventImplPtr
finalizeHandlerInOrderNoEventsUnlocked(HandlerType &Handler) {
assert(isInOrder());
assert(MGraph.expired());
assert(MDefaultGraphDeps.LastEventPtr == nullptr);
assert(MNoLastEventMode);

MEmpty = false;
MEmpty.store(false, std::memory_order_release);

synchronizeWithExternalEvent(Handler);

Expand Down Expand Up @@ -826,7 +823,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
const CGType Type = getSyclObjImpl(Handler)->MCGType;
std::lock_guard<std::mutex> Lock{MMutex};

MEmpty = false;
MEmpty.store(false, std::memory_order_release);

// The following code supports barrier synchronization if host task is
// involved in the scenario. Native barriers cannot handle host task
Expand Down Expand Up @@ -1048,7 +1045,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
std::atomic<bool> MNoLastEventMode = false;

// Used exclusively in getLastEvent and queue_empty() implementations
bool MEmpty = true;
std::atomic<bool> MEmpty = true;

std::vector<EventImplPtr> MStreamsServiceEvents;
std::mutex MStreamsServiceEventsMutex;
Expand Down