Skip to content

Commit 1be0ad2

Browse files
authored
[SYCL] Kernel submit wrapper functions for unit tests (intel#19884)
The new kernel submit wrapper functions allow to select the submission function type between a standard handler-based function and queue shortcut function. This change allows to increase the test coverage and allows for testing no-handler submission path using existing unit tests. This PR introduces the single_task submission function wrappers, and the use of the wrappers in a single unit tests set, but the goal is to extend the set of wrappers and their usage in unit tests, in the future.
1 parent e8ce925 commit 1be0ad2

File tree

3 files changed

+80
-24
lines changed

3 files changed

+80
-24
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//==-- CommandSubmitWrappers.hpp ----- Wrappers for command submission -----==//
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+
#pragma once
10+
11+
#include <sycl/event.hpp>
12+
#include <sycl/handler.hpp>
13+
14+
namespace sycl {
15+
16+
inline namespace _V1 {
17+
namespace unittest {
18+
19+
// Wrappers introduced in this file allow for running unit tests
20+
// with two command submission types: Using a handler and handler-less
21+
// shortcut functions.
22+
// This increases the test coverage, especially for the cases,
23+
// where the command submission path implementation differes significantly
24+
// between those two models.
25+
26+
template <typename KernelName, typename KernelType>
27+
event single_task_wrapper(bool UseShortcutFunction, queue &Q,
28+
const KernelType &KernelFunc) {
29+
if (UseShortcutFunction) {
30+
return Q.single_task<KernelName>(KernelFunc);
31+
} else {
32+
return Q.submit(
33+
[&](handler &cgh) { cgh.single_task<KernelName>(KernelFunc); });
34+
}
35+
}
36+
37+
template <typename KernelName, typename KernelType>
38+
event single_task_wrapper(bool UseShortcutFunction, queue &Q, event &DepEvent,
39+
const KernelType &KernelFunc) {
40+
if (UseShortcutFunction) {
41+
return Q.single_task<KernelName>(DepEvent, KernelFunc);
42+
} else {
43+
return Q.submit([&](handler &cgh) {
44+
cgh.depends_on(DepEvent);
45+
cgh.single_task<KernelName>(KernelFunc);
46+
});
47+
}
48+
}
49+
} // namespace unittest
50+
} // namespace _V1
51+
} // namespace sycl

sycl/unittests/scheduler/InOrderQueueDeps.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "SchedulerTest.hpp"
1010
#include "SchedulerTestUtils.hpp"
1111

12+
#include <helpers/CommandSubmitWrappers.hpp>
1213
#include <helpers/TestKernel.hpp>
1314
#include <helpers/UrMock.hpp>
1415
#include <sycl/usm.hpp>
@@ -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 UseShortcutFunction = 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 = sycl::unittest::single_task_wrapper<TestKernel>(
114+
UseShortcutFunction, 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 = sycl::unittest::single_task_wrapper<TestKernel>(
121+
UseShortcutFunction, Q1, []() {});
122+
event E2 = sycl::unittest::single_task_wrapper<TestKernel>(
123+
UseShortcutFunction, 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 UseShortcutFunction = 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 = sycl::unittest::single_task_wrapper<TestKernel>(
153+
UseShortcutFunction, InOrderQueueFirst, []() {});
154+
std::ignore = sycl::unittest::single_task_wrapper<TestKernel>(
155+
UseShortcutFunction, 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 UseShortcutFunction = 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 = sycl::unittest::single_task_wrapper<TestKernel>(
178+
UseShortcutFunction, InOrderQueue, []() {});
179+
std::ignore = sycl::unittest::single_task_wrapper<TestKernel>(
180+
UseShortcutFunction, InOrderQueue, EvFirst, []() {});
182181

183182
InOrderQueue.wait();
184183

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

192191
} // anonymous namespace
192+
193+
INSTANTIATE_TEST_SUITE_P(
194+
SchedulerTestInstance, SchedulerTest,
195+
testing::Values(
196+
true,
197+
false)); /* Whether to use the shortcut command submission function */

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)