77// ===----------------------------------------------------------------------===//
88// Tests the behavior of enqueue free functions when events can be discarded.
99
10+ #include " detail/event_impl.hpp"
11+ #include " detail/queue_impl.hpp"
1012#include " sycl/platform.hpp"
1113#include < helpers/TestKernel.hpp>
1214#include < helpers/UrMock.hpp>
@@ -107,6 +109,13 @@ class EnqueueFunctionsEventsTests : public ::testing::Test {
107109 queue Q;
108110};
109111
112+ inline void CheckLastEventDiscarded (sycl::queue &Q) {
113+ auto QueueImplPtr = sycl::detail::getSyclObjImpl (Q);
114+ event LastEvent = QueueImplPtr->getLastEvent ();
115+ auto LastEventImplPtr = sycl::detail::getSyclObjImpl (LastEvent);
116+ ASSERT_TRUE (LastEventImplPtr->isDiscarded ());
117+ }
118+
110119TEST_F (EnqueueFunctionsEventsTests, SubmitSingleTaskNoEvent) {
111120 mock::getCallbacks ().set_replace_callback (" urEnqueueKernelLaunch" ,
112121 &redefined_urEnqueueKernelLaunch);
@@ -116,6 +125,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskNoEvent) {
116125 });
117126
118127 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
128+
129+ CheckLastEventDiscarded (Q);
119130}
120131
121132TEST_F (EnqueueFunctionsEventsTests, SingleTaskShortcutNoEvent) {
@@ -125,6 +136,8 @@ TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutNoEvent) {
125136 oneapiext::single_task<TestKernel<>>(Q, []() {});
126137
127138 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
139+
140+ CheckLastEventDiscarded (Q);
128141}
129142
130143TEST_F (EnqueueFunctionsEventsTests, SubmitSingleTaskKernelNoEvent) {
@@ -144,6 +157,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitSingleTaskKernelNoEvent) {
144157 [&](handler &CGH) { oneapiext::single_task (CGH, Kernel); });
145158
146159 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
160+
161+ CheckLastEventDiscarded (Q);
147162}
148163
149164TEST_F (EnqueueFunctionsEventsTests, SingleTaskShortcutKernelNoEvent) {
@@ -163,6 +178,8 @@ TEST_F(EnqueueFunctionsEventsTests, SingleTaskShortcutKernelNoEvent) {
163178 oneapiext::single_task (Q, Kernel);
164179
165180 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
181+
182+ CheckLastEventDiscarded (Q);
166183}
167184
168185TEST_F (EnqueueFunctionsEventsTests, SubmitRangeParallelForNoEvent) {
@@ -174,6 +191,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForNoEvent) {
174191 });
175192
176193 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
194+
195+ CheckLastEventDiscarded (Q);
177196}
178197
179198TEST_F (EnqueueFunctionsEventsTests, RangeParallelForShortcutNoEvent) {
@@ -183,6 +202,8 @@ TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutNoEvent) {
183202 oneapiext::parallel_for<TestKernel<>>(Q, range<1 >{32 }, [](item<1 >) {});
184203
185204 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
205+
206+ CheckLastEventDiscarded (Q);
186207}
187208
188209TEST_F (EnqueueFunctionsEventsTests, SubmitRangeParallelForKernelNoEvent) {
@@ -203,6 +224,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitRangeParallelForKernelNoEvent) {
203224 });
204225
205226 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
227+
228+ CheckLastEventDiscarded (Q);
206229}
207230
208231TEST_F (EnqueueFunctionsEventsTests, RangeParallelForShortcutKernelNoEvent) {
@@ -222,6 +245,8 @@ TEST_F(EnqueueFunctionsEventsTests, RangeParallelForShortcutKernelNoEvent) {
222245 oneapiext::parallel_for (Q, range<1 >{32 }, Kernel);
223246
224247 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
248+
249+ CheckLastEventDiscarded (Q);
225250}
226251
227252TEST_F (EnqueueFunctionsEventsTests, SubmitNDLaunchNoEvent) {
@@ -234,6 +259,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchNoEvent) {
234259 });
235260
236261 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
262+
263+ CheckLastEventDiscarded (Q);
237264}
238265
239266TEST_F (EnqueueFunctionsEventsTests, NDLaunchShortcutNoEvent) {
@@ -244,6 +271,8 @@ TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutNoEvent) {
244271 [](nd_item<1 >) {});
245272
246273 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
274+
275+ CheckLastEventDiscarded (Q);
247276}
248277
249278TEST_F (EnqueueFunctionsEventsTests, SubmitNDLaunchKernelNoEvent) {
@@ -264,6 +293,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitNDLaunchKernelNoEvent) {
264293 });
265294
266295 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
296+
297+ CheckLastEventDiscarded (Q);
267298}
268299
269300TEST_F (EnqueueFunctionsEventsTests, NDLaunchShortcutKernelNoEvent) {
@@ -283,6 +314,8 @@ TEST_F(EnqueueFunctionsEventsTests, NDLaunchShortcutKernelNoEvent) {
283314 oneapiext::nd_launch (Q, nd_range<1 >{range<1 >{32 }, range<1 >{32 }}, Kernel);
284315
285316 ASSERT_EQ (counter_urEnqueueKernelLaunch, size_t {1 });
317+
318+ CheckLastEventDiscarded (Q);
286319}
287320
288321TEST_F (EnqueueFunctionsEventsTests, SubmitMemcpyNoEvent) {
@@ -299,6 +332,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemcpyNoEvent) {
299332
300333 ASSERT_EQ (counter_urUSMEnqueueMemcpy, size_t {1 });
301334
335+ CheckLastEventDiscarded (Q);
336+
302337 free (Src, Q);
303338 free (Dst, Q);
304339}
@@ -315,6 +350,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemcpyShortcutNoEvent) {
315350
316351 ASSERT_EQ (counter_urUSMEnqueueMemcpy, size_t {1 });
317352
353+ CheckLastEventDiscarded (Q);
354+
318355 free (Src, Q);
319356 free (Dst, Q);
320357}
@@ -332,6 +369,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitCopyNoEvent) {
332369
333370 ASSERT_EQ (counter_urUSMEnqueueMemcpy, size_t {1 });
334371
372+ CheckLastEventDiscarded (Q);
373+
335374 free (Src, Q);
336375 free (Dst, Q);
337376}
@@ -348,6 +387,8 @@ TEST_F(EnqueueFunctionsEventsTests, CopyShortcutNoEvent) {
348387
349388 ASSERT_EQ (counter_urUSMEnqueueMemcpy, size_t {1 });
350389
390+ CheckLastEventDiscarded (Q);
391+
351392 free (Src, Q);
352393 free (Dst, Q);
353394}
@@ -365,6 +406,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemsetNoEvent) {
365406
366407 ASSERT_EQ (counter_urUSMEnqueueFill, size_t {1 });
367408
409+ CheckLastEventDiscarded (Q);
410+
368411 free (Dst, Q);
369412}
370413
@@ -379,6 +422,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemsetShortcutNoEvent) {
379422
380423 ASSERT_EQ (counter_urUSMEnqueueFill, size_t {1 });
381424
425+ CheckLastEventDiscarded (Q);
426+
382427 free (Dst, Q);
383428}
384429
@@ -394,6 +439,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitPrefetchNoEvent) {
394439
395440 ASSERT_EQ (counter_urUSMEnqueuePrefetch, size_t {1 });
396441
442+ CheckLastEventDiscarded (Q);
443+
397444 free (Dst, Q);
398445}
399446
@@ -408,6 +455,8 @@ TEST_F(EnqueueFunctionsEventsTests, PrefetchShortcutNoEvent) {
408455
409456 ASSERT_EQ (counter_urUSMEnqueuePrefetch, size_t {1 });
410457
458+ CheckLastEventDiscarded (Q);
459+
411460 free (Dst, Q);
412461}
413462
@@ -424,6 +473,8 @@ TEST_F(EnqueueFunctionsEventsTests, SubmitMemAdviseNoEvent) {
424473
425474 ASSERT_EQ (counter_urUSMEnqueueMemAdvise, size_t {1 });
426475
476+ CheckLastEventDiscarded (Q);
477+
427478 free (Dst, Q);
428479}
429480
@@ -438,6 +489,8 @@ TEST_F(EnqueueFunctionsEventsTests, MemAdviseShortcutNoEvent) {
438489
439490 ASSERT_EQ (counter_urUSMEnqueueMemAdvise, size_t {1 });
440491
492+ CheckLastEventDiscarded (Q);
493+
441494 free (Dst, Q);
442495}
443496
0 commit comments