Skip to content

[SYCL] Add unit tests for concurrently adding host tasks #19150

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

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Draft
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
76 changes: 76 additions & 0 deletions sycl/unittests/scheduler/HostTaskAndBarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "../thread_safety/ThreadUtils.h"
#include "SchedulerTest.hpp"
#include "SchedulerTestUtils.hpp"

Expand Down Expand Up @@ -403,4 +404,79 @@ TEST_F(BarrierHandlingWithHostTask,
}
}

TEST_F(BarrierHandlingWithHostTask, ConcurentHostTaskSubmission) {

size_t ThreadCount = 20;

Barrier b(ThreadCount);
{
auto testLambda = [&](std::size_t threadId) {
b.wait();

// Subit host tasks with no barrier.
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
EXPECT_EQ(HostTaskWaitList.size(), 0u);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);
};

ThreadPool MPool(ThreadCount, testLambda);
}

MainLock.unlock();
QueueDevImpl->wait();
}

TEST_F(BarrierHandlingWithHostTask, ConcurentHostAndKernelTaskSubmission) {

size_t ThreadCount = 1;

Barrier b(ThreadCount);
{
auto testLambda = [&](std::size_t threadId) {

if (threadId == 0) {
// Thread 0 will execute this.
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK, false);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
EXPECT_EQ(HostTaskWaitList.size(), 0u);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);

sycl::event BarrierEvent = AddTask(TestCGType::BARRIER);
EventImplPtr BarrierEventImpl = sycl::detail::getSyclObjImpl(BarrierEvent);
auto BarrierWaitList = BarrierEventImpl->getWaitList();
ASSERT_EQ(BarrierWaitList.size(), 1u);
EXPECT_EQ(BarrierEventImpl->isEnqueued(), false);

MainLock.unlock();
QueueDevImpl->wait();

sycl::event KernelEvent = AddTask(TestCGType::KERNEL_TASK);
EventImplPtr KernelEventImpl = sycl::detail::getSyclObjImpl(KernelEvent);
auto KernelWaitList = KernelEventImpl->getWaitList();
ASSERT_EQ(KernelWaitList.size(), 0u);
EXPECT_EQ(KernelEventImpl->isEnqueued(), true);
}

// Sync all threads.
b.wait();

// Submit host tasks with no barrier.
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK, false);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
EXPECT_EQ(HostTaskWaitList.size(), 0u);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);

};

ThreadPool MPool(ThreadCount, testLambda);
}

QueueDevImpl->wait();
}


} // namespace
Loading