Skip to content

Commit b02b526

Browse files
[SYCL] Make host task state stable in unittest (#13458)
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 71e425f commit b02b526

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sycl/unittests/Extensions/CommandGraph/InOrderQueue.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,16 @@ TEST_F(CommandGraphTest, InOrderQueueWithPreviousHostTask) {
257257
experimental::command_graph<experimental::graph_state::modifiable>
258258
InOrderGraph{InOrderQueue.get_context(), InOrderQueue.get_device()};
259259

260-
auto EventInitial =
261-
InOrderQueue.submit([&](handler &CGH) { CGH.host_task([=]() {}); });
260+
// Event dependency build depends on host task completion. Making it
261+
// predictable with mutex in host task.
262+
std::mutex HostTaskMutex;
263+
std::unique_lock<std::mutex> Lock(HostTaskMutex, std::defer_lock);
264+
Lock.lock();
265+
auto EventInitial = InOrderQueue.submit([&](handler &CGH) {
266+
CGH.host_task([&HostTaskMutex]() {
267+
std::lock_guard<std::mutex> HostTaskLock(HostTaskMutex);
268+
});
269+
});
262270
auto EventInitialImpl = sycl::detail::getSyclObjImpl(EventInitial);
263271

264272
// Record in-order queue with three nodes.
@@ -305,10 +313,12 @@ TEST_F(CommandGraphTest, InOrderQueueWithPreviousHostTask) {
305313

306314
auto EventLastImpl = sycl::detail::getSyclObjImpl(EventLast);
307315
auto WaitList = EventLastImpl->getWaitList();
316+
Lock.unlock();
308317
// Previous task is a host task. Explicit dependency is needed to enforce the
309318
// execution order.
310319
ASSERT_EQ(WaitList.size(), 1lu);
311320
ASSERT_EQ(WaitList[0], EventInitialImpl);
321+
InOrderQueue.wait();
312322
}
313323

314324
TEST_F(CommandGraphTest, InOrderQueueHostTaskAndGraph) {

0 commit comments

Comments
 (0)