Skip to content
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: 7 additions & 1 deletion sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,13 @@ queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
!requiresPostProcess;

if (noLastEventPath) {
return finalizeHandlerInOrderNoEventsUnlocked(Handler);
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);
}
}

detail::EventImplPtr EventImpl;
Expand Down
9 changes: 8 additions & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,14 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {

synchronizeWithExternalEvent(Handler);

return parseEvent(Handler.finalize());
auto Event = parseEvent(Handler.finalize());

if (Event && !Scheduler::CheckEventReadiness(*MContext, Event)) {
MDefaultGraphDeps.LastEventPtr = Event;
MNoLastEventMode.store(false, std::memory_order_relaxed);
}

return Event;
}

template <typename HandlerType = handler>
Expand Down
66 changes: 66 additions & 0 deletions sycl/test-e2e/InorderQueue/in_order_multi_queue_host_task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out
//==-------- in_order_multi_queue_host_task.cpp ---------------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <condition_variable>
#include <iostream>

#include <sycl/detail/core.hpp>
#include <sycl/properties/all_properties.hpp>
#include <sycl/usm.hpp>

using namespace sycl;

const int dataSize = 1024;

int main() {
queue Queue1{property::queue::in_order()};
queue Queue2{property::queue::in_order()};

int *dataA = malloc_host<int>(dataSize, Queue1);
int *dataB = malloc_host<int>(dataSize, Queue1);
int *dataC = malloc_host<int>(dataSize, Queue1);

bool ready = false;
std::mutex host_task_mtx;
std::condition_variable cv;

auto Event1 = Queue1.submit([&](handler &cgh) {
cgh.host_task([&] {
std::unique_lock<std::mutex> lk(host_task_mtx);
cv.wait(lk, [&] { return ready; });
for (size_t i = 0; i < dataSize; ++i) {
dataA[i] = i;
}
});
});

Queue2.submit([&](handler &cgh) {
cgh.depends_on(Event1);
cgh.parallel_for(range<1>(dataSize),
[=](id<1> idx) { dataB[idx[0]] = dataA[idx[0]]; });
});

{
std::unique_lock<std::mutex> lk(host_task_mtx);
ready = true;
}
cv.notify_one();

Queue2.wait();

for (size_t i = 0; i != dataSize; ++i) {
if (dataB[i] != i) {
std::cout << "Result mismatches " << dataB[i] << " vs expected " << i
<< " for index " << i << std::endl;
return 1;
}
}

return 0;
}
Loading