Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions sycl/unittests/helpers/CommandSubmitWrappers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//==-- CommandSubmitWrappers.hpp --- -----==//
//
// 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 <sycl/event.hpp>
#include <sycl/handler.hpp>

using namespace sycl;

template <typename KernelName, typename KernelType>
event single_task_wrapper(bool ShortcutSubmitFunction, queue &Q,
const KernelType &KernelFunc) {
if (ShortcutSubmitFunction) {
return Q.single_task<KernelName>(KernelFunc);
} else {
return Q.submit(
[&](handler &cgh) { cgh.single_task<KernelName>(KernelFunc); });
}
}

template <typename KernelName, typename KernelType>
event single_task_wrapper(bool ShortcutSubmitFunction, queue &Q, event DepEvent,
const KernelType &KernelFunc) {
if (ShortcutSubmitFunction) {
return Q.single_task<KernelName>(DepEvent, KernelFunc);
} else {
return Q.submit([&](handler &cgh) {
cgh.depends_on(DepEvent);
cgh.single_task<KernelName>(KernelFunc);
});
}
}
48 changes: 25 additions & 23 deletions sycl/unittests/scheduler/InOrderQueueDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "SchedulerTest.hpp"
#include "SchedulerTestUtils.hpp"

#include <helpers/CommandSubmitWrappers.hpp>
#include <helpers/TestKernel.hpp>
#include <helpers/UrMock.hpp>
#include <sycl/usm.hpp>
Expand Down Expand Up @@ -44,7 +45,7 @@ ur_result_t redefinedEnqueueMemUnmap(void *pParams) {
return UR_RESULT_SUCCESS;
}

TEST_F(SchedulerTest, InOrderQueueDeps) {
TEST_P(SchedulerTest, InOrderQueueDeps) {
sycl::unittest::UrMock<> Mock;
sycl::platform Plt = sycl::platform();
mock::getCallbacks().set_before_callback("urEnqueueMemBufferReadRect",
Expand Down Expand Up @@ -95,15 +96,12 @@ ur_result_t redefinedEnqueueEventsWaitWithBarrierExt(void *pParams) {
return UR_RESULT_SUCCESS;
}

sycl::event submitKernel(sycl::queue &Q) {
return Q.submit([&](handler &cgh) { cgh.single_task<TestKernel>([]() {}); });
}

TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
TEST_P(SchedulerTest, InOrderQueueIsolatedDeps) {
// Check that isolated kernels (i.e. those that don't modify the graph)
// are handled properly during filtering.
sycl::unittest::UrMock<> Mock;
sycl::platform Plt = sycl::platform();
bool ShortcutSubmitFunction = GetParam();
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrierExt",
&redefinedEnqueueEventsWaitWithBarrierExt);
Expand All @@ -112,14 +110,17 @@ TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
context Ctx{Plt.get_devices()[0]};
queue Q1{Ctx, default_selector_v, property::queue::in_order()};
{
event E = submitKernel(Q1);
event E =
single_task_wrapper<TestKernel>(ShortcutSubmitFunction, Q1, []() {});
Q1.ext_oneapi_submit_barrier({E});
EXPECT_FALSE(BarrierCalled);
}
queue Q2{Ctx, default_selector_v, property::queue::in_order()};
{
event E1 = submitKernel(Q1);
event E2 = submitKernel(Q2);
event E1 =
single_task_wrapper<TestKernel>(ShortcutSubmitFunction, Q1, []() {});
event E2 =
single_task_wrapper<TestKernel>(ShortcutSubmitFunction, Q2, []() {});
ExpectedEvent = detail::getSyclObjImpl(E2)->getHandle();
Q1.ext_oneapi_submit_barrier({E1, E2});
EXPECT_TRUE(BarrierCalled);
Expand All @@ -134,9 +135,10 @@ inline ur_result_t customEnqueueKernelLaunch(void *pParams) {
return UR_RESULT_SUCCESS;
}

TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
TEST_P(SchedulerTest, TwoInOrderQueuesOnSameContext) {
KernelEventListSize.clear();
sycl::unittest::UrMock<> Mock;
bool ShortcutSubmitFunction = GetParam();
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
&customEnqueueKernelLaunch);

Expand All @@ -147,12 +149,10 @@ TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
queue InOrderQueueSecond{Ctx, default_selector_v,
property::queue::in_order()};

event EvFirst = InOrderQueueFirst.submit(
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
std::ignore = InOrderQueueSecond.submit([&](sycl::handler &CGH) {
CGH.depends_on(EvFirst);
CGH.single_task<TestKernel>([] {});
});
event EvFirst = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
InOrderQueueFirst, []() {});
std::ignore = single_task_wrapper<TestKernel>(
ShortcutSubmitFunction, InOrderQueueSecond, EvFirst, []() {});

InOrderQueueFirst.wait();
InOrderQueueSecond.wait();
Expand All @@ -162,9 +162,10 @@ TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
EXPECT_EQ(KernelEventListSize[1] /*EventsCount*/, 1u);
}

TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
TEST_P(SchedulerTest, InOrderQueueNoSchedulerPath) {
KernelEventListSize.clear();
sycl::unittest::UrMock<> Mock;
bool ShortcutSubmitFunction = GetParam();
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
&customEnqueueKernelLaunch);

Expand All @@ -173,12 +174,10 @@ TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
context Ctx{Plt};
queue InOrderQueue{Ctx, default_selector_v, property::queue::in_order()};

event EvFirst = InOrderQueue.submit(
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
std::ignore = InOrderQueue.submit([&](sycl::handler &CGH) {
CGH.depends_on(EvFirst);
CGH.single_task<TestKernel>([] {});
});
event EvFirst = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
InOrderQueue, []() {});
std::ignore = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
InOrderQueue, EvFirst, []() {});

InOrderQueue.wait();

Expand All @@ -190,3 +189,6 @@ TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
}

} // anonymous namespace

INSTANTIATE_TEST_SUITE_P(SchedulerTestInstance, SchedulerTest,
testing::Values(true, false));
2 changes: 1 addition & 1 deletion sycl/unittests/scheduler/SchedulerTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <gtest/gtest.h>

class SchedulerTest : public ::testing::Test {
class SchedulerTest : public testing::TestWithParam<bool> {
protected:
sycl::async_handler MAsyncHandler = [](sycl::exception_list ExceptionList) {
for (std::exception_ptr ExceptionPtr : ExceptionList) {
Expand Down
Loading