Skip to content

Commit b0f584c

Browse files
[SYCL][Docs] Make external events wait with queue (#12766)
This commit adds the behavior to ext_oneapi_set_external_event that it is also waited on when the queue is waited on. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 343d953 commit b0f584c

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_in_order_queue_events.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ This is equivalent to calling `handler::depends_on()` in a command submission
140140
with the `externalEvent` from the most recent call to this member function since
141141
the previous command submission to the same queue.
142142

143+
If `queue::wait()` or `queue::wait_and_throw()` is called prior to any command
144+
submission following a call to this member function, `externalEvent.wait()` is
145+
called and `externalEvent` will not be a dependency on the next command
146+
submitted to the queue.
147+
143148
Calls to this member function throw a `sycl::exception` with `errc::invalid` if
144149
the queue does not have the `property::queue::in_order` property.
145150

sycl/source/detail/queue_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ void queue_impl::wait(const detail::code_location &CodeLoc) {
516516
for (const EventImplPtr &Event : StreamsServiceEvents)
517517
Event->wait(Event);
518518

519+
// If there is an external event set, we need to wait on it.
520+
std::optional<event> ExternalEvent = popExternalEvent();
521+
if (ExternalEvent)
522+
ExternalEvent->wait();
523+
519524
#ifdef XPTI_ENABLE_INSTRUMENTATION
520525
instrumentationEpilog(TelemetryEvent, Name, StreamID, IId);
521526
#endif

sycl/test-e2e/InOrderEventsExt/set_external_event.cpp

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88

99
constexpr size_t N = 1024;
1010

11-
int main() {
12-
sycl::context Ctx;
13-
sycl::device Dev = Ctx.get_devices()[0];
14-
15-
sycl::queue Q1{Ctx, Dev, {sycl::property::queue::in_order{}}};
16-
sycl::queue Q2{Ctx, Dev, {sycl::property::queue::in_order{}}};
11+
int check_work(sycl::queue &Q1, sycl::queue &Q2) {
12+
std::cout << "Checking ext_oneapi_set_external_event for a workload."
13+
<< std::endl;
1714

1815
sycl::buffer<int> DevDataBuf{sycl::range{N}};
1916
sycl::accessor DevData{DevDataBuf};
20-
int *HostData = (int *)malloc(N * sizeof(int) * 10);
17+
int *HostData = new int[N * 10];
2118

2219
for (size_t I = 0; I < 10; ++I) {
2320
Q1.fill(DevData, 0);
@@ -52,6 +49,55 @@ int main() {
5249
}
5350
}
5451
}
55-
free(HostData);
52+
delete[] HostData;
53+
return Failures;
54+
}
55+
56+
int check_wait(sycl::queue &Q1, sycl::queue &Q2) {
57+
std::cout << "Checking ext_oneapi_set_external_event with wait on queue."
58+
<< std::endl;
59+
60+
sycl::buffer<int> DevDataBuf{sycl::range{N}};
61+
sycl::accessor DevData{DevDataBuf};
62+
int *HostData = new int[N];
63+
64+
Q1.fill(DevData, 0);
65+
for (size_t I = 0; I < 10; ++I) {
66+
Q1.submit([&](sycl::handler &h) {
67+
h.require(DevData);
68+
h.parallel_for(N, [=](sycl::item<1> Idx) { ++DevData[Idx]; });
69+
});
70+
}
71+
sycl::event E = Q1.copy(DevData, HostData);
72+
73+
Q2.ext_oneapi_set_external_event(E);
74+
Q2.wait_and_throw();
75+
76+
int Failures = 0;
77+
for (size_t I = 0; I < N; ++I) {
78+
int Expected = 10;
79+
int Actual = HostData[I];
80+
if (Expected != Actual) {
81+
std::cout << "Result not matching the expected value at index " << I
82+
<< ": " << Expected << " != " << Actual << std::endl;
83+
++Failures;
84+
}
85+
}
86+
delete[] HostData;
87+
return Failures;
88+
}
89+
90+
int main() {
91+
sycl::context Ctx;
92+
sycl::device Dev = Ctx.get_devices()[0];
93+
94+
sycl::queue Q1{Ctx, Dev, {sycl::property::queue::in_order{}}};
95+
sycl::queue Q2{Ctx, Dev, {sycl::property::queue::in_order{}}};
96+
97+
int Failures = 0;
98+
99+
Failures += check_work(Q1, Q2);
100+
Failures += check_wait(Q1, Q2);
101+
56102
return Failures;
57103
}

0 commit comments

Comments
 (0)