Skip to content

Commit 8b64be9

Browse files
committed
[SYCL] Introduce unit test kernel wrapper functions for single_task
1 parent 0f186f6 commit 8b64be9

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//==-- CommandSubmitWrappers.hpp --- -----==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <sycl/event.hpp>
10+
#include <sycl/handler.hpp>
11+
12+
using namespace sycl;
13+
14+
template<typename KernelName, typename KernelType>
15+
event single_task_wrapper(bool Shortcut, queue &Q, const KernelType &KernelFunc) {
16+
if (Shortcut) {
17+
return Q.single_task<KernelName>(KernelFunc);
18+
} else {
19+
return Q.submit([&](handler &cgh) { cgh.single_task<KernelName>(KernelFunc); });
20+
}
21+
}
22+
23+
template<typename KernelName, typename KernelType>
24+
event single_task_wrapper(bool Shortcut, queue &Q, event DepEvent, const KernelType &KernelFunc) {
25+
if (Shortcut) {
26+
return Q.single_task<KernelName>(DepEvent, KernelFunc);
27+
} else {
28+
return Q.submit([&](handler &cgh) {
29+
cgh.depends_on(DepEvent);
30+
cgh.single_task<KernelName>(KernelFunc);
31+
});
32+
}
33+
}

sycl/unittests/scheduler/InOrderQueueDeps.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <helpers/TestKernel.hpp>
1313
#include <helpers/UrMock.hpp>
14+
#include <helpers/CommandSubmitWrappers.hpp>
1415
#include <sycl/usm.hpp>
1516

1617
#include <iostream>
@@ -44,7 +45,7 @@ ur_result_t redefinedEnqueueMemUnmap(void *pParams) {
4445
return UR_RESULT_SUCCESS;
4546
}
4647

47-
TEST_F(SchedulerTest, InOrderQueueDeps) {
48+
TEST_P(SchedulerTest, InOrderQueueDeps) {
4849
sycl::unittest::UrMock<> Mock;
4950
sycl::platform Plt = sycl::platform();
5051
mock::getCallbacks().set_before_callback("urEnqueueMemBufferReadRect",
@@ -95,15 +96,12 @@ ur_result_t redefinedEnqueueEventsWaitWithBarrierExt(void *pParams) {
9596
return UR_RESULT_SUCCESS;
9697
}
9798

98-
sycl::event submitKernel(sycl::queue &Q) {
99-
return Q.submit([&](handler &cgh) { cgh.single_task<TestKernel>([]() {}); });
100-
}
101-
102-
TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
99+
TEST_P(SchedulerTest, InOrderQueueIsolatedDeps) {
103100
// Check that isolated kernels (i.e. those that don't modify the graph)
104101
// are handled properly during filtering.
105102
sycl::unittest::UrMock<> Mock;
106103
sycl::platform Plt = sycl::platform();
104+
bool ShortcutSubmitFunction = GetParam();
107105
mock::getCallbacks().set_before_callback(
108106
"urEnqueueEventsWaitWithBarrierExt",
109107
&redefinedEnqueueEventsWaitWithBarrierExt);
@@ -112,14 +110,17 @@ TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
112110
context Ctx{Plt.get_devices()[0]};
113111
queue Q1{Ctx, default_selector_v, property::queue::in_order()};
114112
{
115-
event E = submitKernel(Q1);
113+
event E = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
114+
Q1, []() {});
116115
Q1.ext_oneapi_submit_barrier({E});
117116
EXPECT_FALSE(BarrierCalled);
118117
}
119118
queue Q2{Ctx, default_selector_v, property::queue::in_order()};
120119
{
121-
event E1 = submitKernel(Q1);
122-
event E2 = submitKernel(Q2);
120+
event E1 = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
121+
Q1, []() {});
122+
event E2 = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
123+
Q2, []() {});
123124
ExpectedEvent = detail::getSyclObjImpl(E2)->getHandle();
124125
Q1.ext_oneapi_submit_barrier({E1, E2});
125126
EXPECT_TRUE(BarrierCalled);
@@ -134,9 +135,10 @@ inline ur_result_t customEnqueueKernelLaunch(void *pParams) {
134135
return UR_RESULT_SUCCESS;
135136
}
136137

137-
TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
138+
TEST_P(SchedulerTest, TwoInOrderQueuesOnSameContext) {
138139
KernelEventListSize.clear();
139140
sycl::unittest::UrMock<> Mock;
141+
bool ShortcutSubmitFunction = GetParam();
140142
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
141143
&customEnqueueKernelLaunch);
142144

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

150-
event EvFirst = InOrderQueueFirst.submit(
151-
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
152-
std::ignore = InOrderQueueSecond.submit([&](sycl::handler &CGH) {
153-
CGH.depends_on(EvFirst);
154-
CGH.single_task<TestKernel>([] {});
155-
});
152+
event EvFirst = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
153+
InOrderQueueFirst, []() {});
154+
std::ignore = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
155+
InOrderQueueSecond, EvFirst, []() {});
156156

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

165-
TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
165+
TEST_P(SchedulerTest, InOrderQueueNoSchedulerPath) {
166166
KernelEventListSize.clear();
167167
sycl::unittest::UrMock<> Mock;
168+
bool ShortcutSubmitFunction = GetParam();
168169
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
169170
&customEnqueueKernelLaunch);
170171

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

176-
event EvFirst = InOrderQueue.submit(
177-
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
178-
std::ignore = InOrderQueue.submit([&](sycl::handler &CGH) {
179-
CGH.depends_on(EvFirst);
180-
CGH.single_task<TestKernel>([] {});
181-
});
177+
event EvFirst = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
178+
InOrderQueue, []() {});
179+
std::ignore = single_task_wrapper<TestKernel>(ShortcutSubmitFunction,
180+
InOrderQueue, EvFirst, []() {});
182181

183182
InOrderQueue.wait();
184183

@@ -190,3 +189,5 @@ TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
190189
}
191190

192191
} // anonymous namespace
192+
193+
INSTANTIATE_TEST_SUITE_P(SchedulerTestInstance, SchedulerTest, testing::Values(true, false));

sycl/unittests/scheduler/SchedulerTest.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <gtest/gtest.h>
1414

15-
class SchedulerTest : public ::testing::Test {
15+
class SchedulerTest : public testing::TestWithParam<bool> {
1616
protected:
1717
sycl::async_handler MAsyncHandler = [](sycl::exception_list ExceptionList) {
1818
for (std::exception_ptr ExceptionPtr : ExceptionList) {

0 commit comments

Comments
 (0)