@@ -44,17 +44,19 @@ void event_impl::initContextIfNeeded() {
44
44
45
45
event_impl::~event_impl () {
46
46
try {
47
- if (MEvent)
48
- getPlugin ()->call (urEventRelease, MEvent);
47
+ auto Handle = this ->getHandle ();
48
+ if (Handle )
49
+ getPlugin ()->call (urEventRelease, Handle );
49
50
} catch (std::exception &e) {
50
51
__SYCL_REPORT_EXCEPTION_TO_STREAM (" exception in ~event_impl" , e);
51
52
}
52
53
}
53
54
54
55
void event_impl::waitInternal (bool *Success) {
55
- if (!MIsHostEvent && MEvent) {
56
+ auto Handle = this ->getHandle ();
57
+ if (!MIsHostEvent && Handle ) {
56
58
// Wait for the native event
57
- ur_result_t Err = getPlugin ()->call_nocheck (urEventWait, 1 , &MEvent );
59
+ ur_result_t Err = getPlugin ()->call_nocheck (urEventWait, 1 , &Handle );
58
60
// TODO drop the UR_RESULT_ERROR_UKNOWN from here (this was waiting for
59
61
// https://github.com/oneapi-src/unified-runtime/issues/1459 which is now
60
62
// closed).
@@ -89,7 +91,7 @@ void event_impl::waitInternal(bool *Success) {
89
91
}
90
92
91
93
void event_impl::setComplete () {
92
- if (MIsHostEvent || !MEvent ) {
94
+ if (MIsHostEvent || !this -> getHandle () ) {
93
95
{
94
96
std::unique_lock<std::mutex> lock (MMutex);
95
97
#ifndef NDEBUG
@@ -116,8 +118,11 @@ static uint64_t inline getTimestamp() {
116
118
.count ();
117
119
}
118
120
119
- const ur_event_handle_t &event_impl::getHandleRef () const { return MEvent; }
120
- ur_event_handle_t &event_impl::getHandleRef () { return MEvent; }
121
+ ur_event_handle_t event_impl::getHandle () const { return MEvent.load (); }
122
+
123
+ void event_impl::setHandle (const ur_event_handle_t &UREvent) {
124
+ MEvent.store (UREvent);
125
+ }
121
126
122
127
const ContextImplPtr &event_impl::getContextImpl () {
123
128
initContextIfNeeded ();
@@ -141,7 +146,7 @@ event_impl::event_impl(ur_event_handle_t Event, const context &SyclContext)
141
146
MIsFlushed (true ), MState(HES_Complete) {
142
147
143
148
ur_context_handle_t TempContext;
144
- getPlugin ()->call (urEventGetInfo, MEvent , UR_EVENT_INFO_CONTEXT,
149
+ getPlugin ()->call (urEventGetInfo, this -> getHandle () , UR_EVENT_INFO_CONTEXT,
145
150
sizeof (ur_context_handle_t ), &TempContext, nullptr );
146
151
147
152
if (MContext->getHandleRef () != TempContext) {
@@ -183,7 +188,7 @@ void *event_impl::instrumentationProlog(std::string &Name, int32_t StreamID,
183
188
// Create a string with the event address so it
184
189
// can be associated with other debug data
185
190
xpti::utils::StringHelper SH;
186
- Name = SH.nameWithAddress <ur_event_handle_t >(" event.wait" , MEvent );
191
+ Name = SH.nameWithAddress <ur_event_handle_t >(" event.wait" , this -> getHandle () );
187
192
188
193
// We can emit the wait associated with the graph if the
189
194
// event does not have a command object or associated with
@@ -249,9 +254,10 @@ void event_impl::wait(std::shared_ptr<sycl::detail::event_impl> Self,
249
254
TelemetryEvent = instrumentationProlog (Name, StreamID, IId);
250
255
#endif
251
256
252
- if (MEvent)
253
- // presence of MEvent means the command has been enqueued, so no need to
254
- // go via the slow path event waiting in the scheduler
257
+ auto EventHandle = getHandle ();
258
+ if (EventHandle)
259
+ // presence of the native handle means the command has been enqueued, so no
260
+ // need to go via the slow path event waiting in the scheduler
255
261
waitInternal (Success);
256
262
else if (MCommand)
257
263
detail::Scheduler::getInstance ().waitForEvent (Self, Success);
@@ -294,7 +300,7 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() {
294
300
// For profiling tag events we rely on the submission time reported as
295
301
// the start time has undefined behavior.
296
302
return get_event_profiling_info<info::event_profiling::command_submit>(
297
- this ->getHandleRef (), this ->getPlugin ());
303
+ this ->getHandle (), this ->getPlugin ());
298
304
}
299
305
300
306
// The delay between the submission and the actual start of a CommandBuffer
@@ -311,10 +317,11 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() {
311
317
// made by forcing the re-sync of submit time to start time is less than
312
318
// 0.5ms. These timing values were obtained empirically using an integrated
313
319
// Intel GPU).
314
- if (MEventFromSubmittedExecCommandBuffer && !MIsHostEvent && MEvent) {
320
+ auto Handle = this ->getHandle ();
321
+ if (MEventFromSubmittedExecCommandBuffer && !MIsHostEvent && Handle ) {
315
322
uint64_t StartTime =
316
323
get_event_profiling_info<info::event_profiling::command_start>(
317
- this -> getHandleRef () , this ->getPlugin ());
324
+ Handle , this ->getPlugin ());
318
325
if (StartTime < MSubmitTime)
319
326
MSubmitTime = StartTime;
320
327
}
@@ -326,16 +333,17 @@ uint64_t
326
333
event_impl::get_profiling_info<info::event_profiling::command_start>() {
327
334
checkProfilingPreconditions ();
328
335
if (!MIsHostEvent) {
329
- if (MEvent) {
336
+ auto Handle = getHandle ();
337
+ if (Handle ) {
330
338
auto StartTime =
331
339
get_event_profiling_info<info::event_profiling::command_start>(
332
- this -> getHandleRef () , this ->getPlugin ());
340
+ Handle , this ->getPlugin ());
333
341
if (!MFallbackProfiling) {
334
342
return StartTime;
335
343
} else {
336
344
auto DeviceBaseTime =
337
345
get_event_profiling_info<info::event_profiling::command_submit>(
338
- this -> getHandleRef () , this ->getPlugin ());
346
+ Handle , this ->getPlugin ());
339
347
return MHostBaseTime - DeviceBaseTime + StartTime;
340
348
}
341
349
}
@@ -353,16 +361,17 @@ template <>
353
361
uint64_t event_impl::get_profiling_info<info::event_profiling::command_end>() {
354
362
checkProfilingPreconditions ();
355
363
if (!MIsHostEvent) {
356
- if (MEvent) {
364
+ auto Handle = this ->getHandle ();
365
+ if (Handle ) {
357
366
auto EndTime =
358
367
get_event_profiling_info<info::event_profiling::command_end>(
359
- this -> getHandleRef () , this ->getPlugin ());
368
+ Handle , this ->getPlugin ());
360
369
if (!MFallbackProfiling) {
361
370
return EndTime;
362
371
} else {
363
372
auto DeviceBaseTime =
364
373
get_event_profiling_info<info::event_profiling::command_submit>(
365
- this -> getHandleRef () , this ->getPlugin ());
374
+ Handle , this ->getPlugin ());
366
375
return MHostBaseTime - DeviceBaseTime + EndTime;
367
376
}
368
377
}
@@ -377,8 +386,9 @@ uint64_t event_impl::get_profiling_info<info::event_profiling::command_end>() {
377
386
}
378
387
379
388
template <> uint32_t event_impl::get_info<info::event::reference_count>() {
380
- if (!MIsHostEvent && MEvent) {
381
- return get_event_info<info::event::reference_count>(this ->getHandleRef (),
389
+ auto Handle = this ->getHandle ();
390
+ if (!MIsHostEvent && Handle ) {
391
+ return get_event_info<info::event::reference_count>(Handle ,
382
392
this ->getPlugin ());
383
393
}
384
394
return 0 ;
@@ -392,9 +402,10 @@ event_impl::get_info<info::event::command_execution_status>() {
392
402
393
403
if (!MIsHostEvent) {
394
404
// Command is enqueued and UrEvent is ready
395
- if (MEvent)
405
+ auto Handle = this ->getHandle ();
406
+ if (Handle )
396
407
return get_event_info<info::event::command_execution_status>(
397
- this -> getHandleRef () , this ->getPlugin ());
408
+ Handle , this ->getPlugin ());
398
409
// Command is blocked and not enqueued, UrEvent is not assigned yet
399
410
else if (MCommand)
400
411
return sycl::info::event_command_status::submitted;
@@ -471,17 +482,20 @@ ur_native_handle_t event_impl::getNative() {
471
482
initContextIfNeeded ();
472
483
473
484
auto Plugin = getPlugin ();
474
- if (MIsDefaultConstructed && !MEvent) {
485
+ auto Handle = getHandle ();
486
+ if (MIsDefaultConstructed && !Handle ) {
475
487
auto TempContext = MContext.get ()->getHandleRef ();
476
488
ur_event_native_properties_t NativeProperties{};
489
+ ur_event_handle_t UREvent = nullptr ;
477
490
Plugin->call (urEventCreateWithNativeHandle, 0 , TempContext,
478
- &NativeProperties, &MEvent);
491
+ &NativeProperties, &UREvent);
492
+ this ->setHandle (UREvent);
479
493
}
480
494
if (MContext->getBackend () == backend::opencl)
481
- Plugin->call (urEventRetain, getHandleRef () );
482
- ur_native_handle_t Handle ;
483
- Plugin->call (urEventGetNativeHandle, getHandleRef () , &Handle );
484
- return Handle ;
495
+ Plugin->call (urEventRetain, Handle );
496
+ ur_native_handle_t OutHandle ;
497
+ Plugin->call (urEventGetNativeHandle, Handle , &OutHandle );
498
+ return OutHandle ;
485
499
}
486
500
487
501
std::vector<EventImplPtr> event_impl::getWaitList () {
@@ -505,7 +519,8 @@ std::vector<EventImplPtr> event_impl::getWaitList() {
505
519
void event_impl::flushIfNeeded (const QueueImplPtr &UserQueue) {
506
520
// Some events might not have a native handle underneath even at this point,
507
521
// e.g. those produced by memset with 0 size (no UR call is made).
508
- if (MIsFlushed || !MEvent)
522
+ auto Handle = this ->getHandle ();
523
+ if (MIsFlushed || !Handle )
509
524
return ;
510
525
511
526
QueueImplPtr Queue = MQueue.lock ();
@@ -520,7 +535,7 @@ void event_impl::flushIfNeeded(const QueueImplPtr &UserQueue) {
520
535
521
536
// Check if the task for this event has already been submitted.
522
537
ur_event_status_t Status = UR_EVENT_STATUS_QUEUED;
523
- getPlugin ()->call (urEventGetInfo, MEvent ,
538
+ getPlugin ()->call (urEventGetInfo, Handle ,
524
539
UR_EVENT_INFO_COMMAND_EXECUTION_STATUS,
525
540
sizeof (ur_event_status_t ), &Status, nullptr );
526
541
if (Status == UR_EVENT_STATUS_QUEUED) {
0 commit comments