Skip to content

Commit 11c295a

Browse files
committed
Restore lock and rework test
1 parent 6294da0 commit 11c295a

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

sycl/source/detail/queue_impl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,13 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
349349
!requiresPostProcess;
350350

351351
if (noLastEventPath) {
352-
return finalizeHandlerInOrderNoEventsUnlocked(Handler);
352+
std::unique_lock<std::mutex> Lock(MMutex);
353+
354+
// Check if we are still in no last event mode. There could
355+
// have been a concurrent submit.
356+
if (MNoLastEventMode.load(std::memory_order_relaxed)) {
357+
return finalizeHandlerInOrderNoEventsUnlocked(Handler);
358+
}
353359
}
354360

355361
detail::EventImplPtr EventImpl;

sycl/source/detail/queue_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
754754

755755
if (Event && !Scheduler::CheckEventReadiness(MContext, Event)) {
756756
MDefaultGraphDeps.LastEventPtr = Event;
757-
MNoLastEventMode = false;
757+
MNoLastEventMode.store(false, std::memory_order_relaxed);
758758
}
759759

760760
return Event;

sycl/test-e2e/InorderQueue/in_order_multi_queue_host_task.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
//
99
//===----------------------------------------------------------------------===//
10+
#include <condition_variable>
1011
#include <iostream>
1112

1213
#include <sycl/detail/core.hpp>
@@ -15,7 +16,7 @@
1516

1617
using namespace sycl;
1718

18-
const int dataSize = 1024 * 1024;
19+
const int dataSize = 1024;
1920

2021
int main() {
2122
queue Queue1{property::queue::in_order()};
@@ -25,8 +26,14 @@ int main() {
2526
int *dataB = malloc_host<int>(dataSize, Queue1);
2627
int *dataC = malloc_host<int>(dataSize, Queue1);
2728

29+
bool ready = false;
30+
std::mutex host_task_mtx;
31+
std::condition_variable cv;
32+
2833
auto Event1 = Queue1.submit([&](handler &cgh) {
2934
cgh.host_task([&] {
35+
std::unique_lock<std::mutex> lk(host_task_mtx);
36+
cv.wait(lk, [&] { return ready; });
3037
for (size_t i = 0; i < dataSize; ++i) {
3138
dataA[i] = i;
3239
}
@@ -39,6 +46,12 @@ int main() {
3946
[=](id<1> idx) { dataB[idx[0]] = dataA[idx[0]]; });
4047
});
4148

49+
{
50+
std::unique_lock<std::mutex> lk(host_task_mtx);
51+
ready = true;
52+
}
53+
cv.notify_one();
54+
4255
Queue2.wait();
4356

4457
for (size_t i = 0; i != dataSize; ++i) {

0 commit comments

Comments
 (0)