Skip to content

Commit 8d247bb

Browse files
[E2E][SYCL] Test for empty command group behavior
We currently have a bug here and ignore some required dependencies. That will be addressed in a separate functional PR.
1 parent e95b34b commit 8d247bb

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// RUN: %{build} -o %t.out %cxx_std_optionc++20
2+
// RUN: %{run} %t.out
3+
4+
#include <sycl/sycl.hpp>
5+
6+
#include <latch>
7+
#include <thread>
8+
9+
using namespace sycl;
10+
11+
void test_host_task_dep() {
12+
queue q;
13+
14+
std::latch start_execution{1};
15+
16+
int x = 0;
17+
18+
auto host_event = q.submit([&](handler &cgh) {
19+
cgh.host_task([&]() {
20+
start_execution.wait();
21+
x = 42;
22+
});
23+
});
24+
25+
auto empty_cg_event =
26+
q.submit([&](handler &cgh) { cgh.depends_on(host_event); });
27+
28+
// FIXME: This should deadlock, but the dependency is ignored currently.
29+
empty_cg_event.wait();
30+
31+
assert(x == 0);
32+
start_execution.count_down();
33+
34+
empty_cg_event.wait();
35+
// FIXME: uncomment once the bug mentioned above is fixed.
36+
// assert(x == 42);
37+
38+
// I'm seeing some weird hang without this:
39+
host_event.wait();
40+
}
41+
42+
void test_device_event_dep() {
43+
queue q;
44+
45+
std::latch start_execution{1};
46+
auto *p = sycl::malloc_shared<int>(1, q);
47+
*p = 0;
48+
49+
auto host_event = q.submit([&](handler &cgh) {
50+
cgh.host_task([&]() {
51+
start_execution.wait();
52+
});
53+
});
54+
auto device_event = q.single_task(host_event, [=]() { *p = 42; });
55+
auto empty_cg_event =
56+
q.submit([&](handler &cgh) { cgh.depends_on(device_event); });
57+
58+
// FIXME: This should deadlock, but the dependency is ignored currently.
59+
empty_cg_event.wait();
60+
61+
assert(*p == 0);
62+
start_execution.count_down();
63+
64+
empty_cg_event.wait();
65+
// FIXME: uncomment once the bug mentioned above is fixed.
66+
// assert(*p == 42);
67+
68+
q.wait();
69+
sycl::free(p, q);
70+
}
71+
72+
void test_accessor_dep() {
73+
queue q;
74+
75+
std::latch start_execution{1};
76+
auto *p = sycl::malloc_shared<int>(1, q);
77+
*p = 0;
78+
79+
auto host_event = q.submit([&](handler &cgh) {
80+
cgh.host_task([&]() {
81+
start_execution.wait();
82+
});
83+
});
84+
85+
sycl::buffer<int, 1> b{1};
86+
auto device_event = q.submit([&](auto &cgh) {
87+
cgh.depends_on(host_event);
88+
sycl::accessor a{b, cgh};
89+
90+
cgh.single_task([=]() {
91+
*p = 42;
92+
a[0] = 42;
93+
});
94+
});
95+
auto empty_cg_event = q.submit([&](handler &cgh) {
96+
sycl::accessor a{b};
97+
// TODO: Clarify with spec people that it should create a dependency indeed.
98+
cgh.require(a);
99+
});
100+
101+
// FIXME: This should deadlock, but the dependency is ignored currently.
102+
empty_cg_event.wait();
103+
104+
assert(*p == 0);
105+
start_execution.count_down();
106+
107+
empty_cg_event.wait();
108+
// FIXME: uncomment once the bug mentioned above is fixed.
109+
// assert(*p == 42);
110+
111+
q.wait();
112+
sycl::free(p, q);
113+
}
114+
115+
int main() {
116+
test_host_task_dep();
117+
test_device_event_dep();
118+
test_accessor_dep();
119+
return 0;
120+
}

0 commit comments

Comments
 (0)