Skip to content

Commit dd7446c

Browse files
[SYCL] Rewrite some E2E tests into unit-tests (#15877)
The main idea behind this (and other PRs I will eventually submit) is that we shouldn't use `SYCL_UR_TRACE` in our unit-tests unless absolutely necessary (like testing shutdown sequence). The reason behind this is the fact that we have unit-tests infrastructure which is more than capable of ensuring that we called the right UR APIs with the right arguments. There is no need to waste our CI time on compiling and running the same test on different devices if we can easily test the same via our UR mock infrastructure.
1 parent 4add105 commit dd7446c

File tree

6 files changed

+119
-160
lines changed

6 files changed

+119
-160
lines changed

sycl/test-e2e/Basic/enqueue_barrier.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

sycl/test-e2e/ESIMD/esimd_check_vc_codegen.cpp

Lines changed: 0 additions & 97 deletions
This file was deleted.

sycl/test-e2e/ProgramManager/multi_device_bundle/compile_link.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: gpu && linux && (opencl || level_zero)
22

33
// RUN: %{build} -o %t.out
4-
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 SYCL_UR_TRACE=2 %{run} %t.out
4+
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 %{run} %t.out
55

66
// Test to check that we can compile and link a kernel bundle for multiple
77
// devices and run the kernel on each device.

sycl/unittests/kernel-and-program/KernelBuildOptions.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,20 @@ TEST(KernelBuildOptions, KernelBundleBasic) {
119119
auto LinkBundle = sycl::link(ObjBundle, ObjBundle.get_devices());
120120
EXPECT_EQ(BuildOpts, "-link-img");
121121
}
122+
123+
TEST(KernelBuildOptions, ESIMDParallelForBasic) {
124+
sycl::unittest::UrMock<> Mock;
125+
sycl::platform Plt = sycl::platform();
126+
setupCommonMockAPIs(Mock);
127+
128+
const sycl::device Dev = Plt.get_devices()[0];
129+
sycl::queue Queue{Dev};
130+
131+
Queue.submit([&](sycl::handler &cgh) {
132+
cgh.parallel_for<BuildOptsTestKernel>(
133+
sycl::range{1024}, [=](sycl::id<1>) /* SYCL_ESIMD_KERNEL */ {});
134+
});
135+
136+
EXPECT_EQ(BuildOpts,
137+
"-compile-img -vc-codegen -disable-finalizer-msg -link-img");
138+
}

sycl/unittests/queue/Barrier.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//==------------------- Barrier.cpp --- queue unit tests -------------------==//
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 <helpers/TestKernel.hpp>
10+
#include <helpers/UrMock.hpp>
11+
12+
#include <gtest/gtest.h>
13+
14+
static unsigned NumOfEventsWaitWithBarrierCalls = 0;
15+
16+
static ur_result_t redefined_urEnqueueEventsWaitWithBarrier(void *) {
17+
NumOfEventsWaitWithBarrierCalls++;
18+
19+
return UR_RESULT_SUCCESS;
20+
}
21+
22+
TEST(Queue, HandlerBarrier) {
23+
sycl::unittest::UrMock<> Mock;
24+
mock::getCallbacks().set_before_callback(
25+
"urEnqueueEventsWaitWithBarrier",
26+
&redefined_urEnqueueEventsWaitWithBarrier);
27+
NumOfEventsWaitWithBarrierCalls = 0;
28+
29+
sycl::queue Q;
30+
31+
Q.submit(
32+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
33+
Q.submit(
34+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
35+
36+
Q.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier(); });
37+
38+
ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
39+
}
40+
41+
TEST(Queue, ExtOneAPISubmitBarrier) {
42+
sycl::unittest::UrMock<> Mock;
43+
mock::getCallbacks().set_before_callback(
44+
"urEnqueueEventsWaitWithBarrier",
45+
&redefined_urEnqueueEventsWaitWithBarrier);
46+
NumOfEventsWaitWithBarrierCalls = 0;
47+
48+
sycl::queue Q;
49+
50+
Q.submit(
51+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
52+
Q.submit(
53+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
54+
55+
Q.ext_oneapi_submit_barrier();
56+
57+
ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
58+
}
59+
60+
TEST(Queue, HandlerBarrierWithWaitList) {
61+
sycl::unittest::UrMock<> Mock;
62+
mock::getCallbacks().set_before_callback(
63+
"urEnqueueEventsWaitWithBarrier",
64+
&redefined_urEnqueueEventsWaitWithBarrier);
65+
NumOfEventsWaitWithBarrierCalls = 0;
66+
67+
sycl::queue Q1;
68+
sycl::queue Q2;
69+
sycl::queue Q3;
70+
71+
auto E1 = Q1.submit(
72+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
73+
auto E2 = Q2.submit(
74+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
75+
76+
Q3.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier({E1, E2}); });
77+
78+
ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
79+
}
80+
81+
TEST(Queue, ExtOneAPISubmitBarrierWithWaitList) {
82+
sycl::unittest::UrMock<> Mock;
83+
mock::getCallbacks().set_before_callback(
84+
"urEnqueueEventsWaitWithBarrier",
85+
&redefined_urEnqueueEventsWaitWithBarrier);
86+
NumOfEventsWaitWithBarrierCalls = 0;
87+
88+
sycl::queue Q1;
89+
sycl::queue Q2;
90+
sycl::queue Q3;
91+
92+
auto E1 = Q1.submit(
93+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
94+
auto E2 = Q2.submit(
95+
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
96+
97+
Q3.ext_oneapi_submit_barrier({E1, E2});
98+
99+
ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
100+
}

sycl/unittests/queue/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ add_sycl_unittest(QueueTests OBJECT
99
InOrderQueue.cpp
1010
InteropRetain.cpp
1111
Properties.cpp
12+
Barrier.cpp
1213
)

0 commit comments

Comments
 (0)