@@ -956,7 +956,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking,
956
956
EnqueueResultT (EnqueueResultT::SyclEnqueueFailed, this , Res);
957
957
else {
958
958
MEvent->setEnqueued ();
959
- if (MShouldCompleteEventIfPossible &&
959
+ if (MShouldCompleteEventIfPossible && !MEvent-> isDiscarded () &&
960
960
(MEvent->isHost () || MEvent->getHandle () == nullptr ))
961
961
MEvent->setComplete ();
962
962
@@ -3075,6 +3075,13 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3075
3075
ur_event_handle_t *Event = DiscardUrEvent ? nullptr : &UREvent;
3076
3076
detail::EventImplPtr EventImpl = DiscardUrEvent ? nullptr : MEvent;
3077
3077
3078
+ auto SetEventHandleOrDiscard = [&]() {
3079
+ if (Event)
3080
+ MEvent->setHandle (*Event);
3081
+ else
3082
+ MEvent->setStateDiscarded ();
3083
+ };
3084
+
3078
3085
switch (MCommandGroup->getType ()) {
3079
3086
3080
3087
case CGType::UpdateHost: {
@@ -3209,8 +3216,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3209
3216
Result != UR_RESULT_SUCCESS)
3210
3217
return Result;
3211
3218
3212
- if (Event)
3213
- MEvent->setHandle (*Event);
3219
+ SetEventHandleOrDiscard ();
3214
3220
return UR_RESULT_SUCCESS;
3215
3221
}
3216
3222
case CGType::FillUSM: {
@@ -3221,8 +3227,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3221
3227
Result != UR_RESULT_SUCCESS)
3222
3228
return Result;
3223
3229
3224
- if (Event)
3225
- MEvent->setHandle (*Event);
3230
+ SetEventHandleOrDiscard ();
3226
3231
return UR_RESULT_SUCCESS;
3227
3232
}
3228
3233
case CGType::PrefetchUSM: {
@@ -3233,8 +3238,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3233
3238
Result != UR_RESULT_SUCCESS)
3234
3239
return Result;
3235
3240
3236
- if (Event)
3237
- MEvent->setHandle (*Event);
3241
+ SetEventHandleOrDiscard ();
3238
3242
return UR_RESULT_SUCCESS;
3239
3243
}
3240
3244
case CGType::AdviseUSM: {
@@ -3246,8 +3250,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3246
3250
Result != UR_RESULT_SUCCESS)
3247
3251
return Result;
3248
3252
3249
- if (Event)
3250
- MEvent->setHandle (*Event);
3253
+ SetEventHandleOrDiscard ();
3251
3254
return UR_RESULT_SUCCESS;
3252
3255
}
3253
3256
case CGType::Copy2DUSM: {
@@ -3259,8 +3262,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3259
3262
Result != UR_RESULT_SUCCESS)
3260
3263
return Result;
3261
3264
3262
- if (Event)
3263
- MEvent->setHandle (*Event);
3265
+ SetEventHandleOrDiscard ();
3264
3266
return UR_RESULT_SUCCESS;
3265
3267
}
3266
3268
case CGType::Fill2DUSM: {
@@ -3272,8 +3274,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3272
3274
Result != UR_RESULT_SUCCESS)
3273
3275
return Result;
3274
3276
3275
- if (Event)
3276
- MEvent->setHandle (*Event);
3277
+ SetEventHandleOrDiscard ();
3277
3278
return UR_RESULT_SUCCESS;
3278
3279
}
3279
3280
case CGType::Memset2DUSM: {
@@ -3285,8 +3286,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3285
3286
Result != UR_RESULT_SUCCESS)
3286
3287
return Result;
3287
3288
3288
- if (Event)
3289
- MEvent->setHandle (*Event);
3289
+ SetEventHandleOrDiscard ();
3290
3290
return UR_RESULT_SUCCESS;
3291
3291
}
3292
3292
case CGType::CodeplayHostTask: {
@@ -3426,8 +3426,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3426
3426
MQueue->getAdapter ()->call <UrApiKind::urEnqueueNativeCommandExp>(
3427
3427
MQueue->getHandleRef (), InteropFreeFunc, &CustomOpData, ReqMems.size (),
3428
3428
ReqMems.data (), nullptr , RawEvents.size (), RawEvents.data (), Event);
3429
- if (Event)
3430
- MEvent->setHandle (*Event);
3429
+ SetEventHandleOrDiscard ();
3431
3430
return UR_RESULT_SUCCESS;
3432
3431
}
3433
3432
case CGType::Barrier: {
@@ -3437,8 +3436,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3437
3436
MEvent->setHostEnqueueTime ();
3438
3437
Adapter->call <UrApiKind::urEnqueueEventsWaitWithBarrier>(
3439
3438
MQueue->getHandleRef (), 0 , nullptr , Event);
3440
- if (Event)
3441
- MEvent->setHandle (*Event);
3439
+ SetEventHandleOrDiscard ();
3442
3440
return UR_RESULT_SUCCESS;
3443
3441
}
3444
3442
case CGType::BarrierWaitlist: {
@@ -3455,8 +3453,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3455
3453
MEvent->setHostEnqueueTime ();
3456
3454
Adapter->call <UrApiKind::urEnqueueEventsWaitWithBarrier>(
3457
3455
MQueue->getHandleRef (), UrEvents.size (), &UrEvents[0 ], Event);
3458
- if (Event)
3459
- MEvent->setHandle (*Event);
3456
+ SetEventHandleOrDiscard ();
3460
3457
return UR_RESULT_SUCCESS;
3461
3458
}
3462
3459
case CGType::ProfilingTag: {
@@ -3503,8 +3500,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3503
3500
Adapter->call <UrApiKind::urEventRelease>(PostTimestampBarrierEvent);
3504
3501
}
3505
3502
3506
- if (Event)
3507
- MEvent->setHandle (*Event);
3503
+ SetEventHandleOrDiscard ();
3508
3504
return UR_RESULT_SUCCESS;
3509
3505
}
3510
3506
case CGType::CopyToDeviceGlobal: {
@@ -3517,8 +3513,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3517
3513
Result != UR_RESULT_SUCCESS)
3518
3514
return Result;
3519
3515
3520
- if (Event)
3521
- MEvent->setHandle (*Event);
3516
+ SetEventHandleOrDiscard ();
3522
3517
return UR_RESULT_SUCCESS;
3523
3518
}
3524
3519
case CGType::CopyFromDeviceGlobal: {
@@ -3532,8 +3527,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3532
3527
Result != UR_RESULT_SUCCESS)
3533
3528
return Result;
3534
3529
3535
- if (Event)
3536
- MEvent->setHandle (*Event);
3530
+ SetEventHandleOrDiscard ();
3537
3531
return UR_RESULT_SUCCESS;
3538
3532
}
3539
3533
case CGType::ReadWriteHostPipe: {
@@ -3564,8 +3558,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3564
3558
CmdBufferCG->MCommandBuffer , MQueue->getHandleRef (),
3565
3559
RawEvents.size (), RawEvents.empty () ? nullptr : &RawEvents[0 ],
3566
3560
Event);
3567
- if (Event)
3568
- MEvent->setHandle (*Event);
3561
+ SetEventHandleOrDiscard ();
3569
3562
3570
3563
return Err;
3571
3564
}
@@ -3581,8 +3574,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
3581
3574
Result != UR_RESULT_SUCCESS)
3582
3575
return Result;
3583
3576
3584
- if (Event)
3585
- MEvent->setHandle (*Event);
3577
+ SetEventHandleOrDiscard ();
3586
3578
3587
3579
return UR_RESULT_SUCCESS;
3588
3580
}
0 commit comments