@@ -1228,7 +1228,15 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
1228
1228
// either that no command has ever been issued to the queue
1229
1229
// or it means that the LastCommandEvent has been signalled and
1230
1230
// therefore that this Queue is idle.
1231
- bool CurrentlyEmpty = this ->LastCommandEvent == nullptr ;
1231
+ //
1232
+ // NOTE: this behavior adds some flakyness to the batching
1233
+ // since last command's event may or may not be completed by the
1234
+ // time we get here depending on timings and system/gpu load.
1235
+ // So, disable it for modes where we print PI traces. Printing
1236
+ // traces incurs much different timings than real execution
1237
+ // ansyway, and many regression tests use it.
1238
+ //
1239
+ bool CurrentlyEmpty = !PrintPiTrace && this ->LastCommandEvent == nullptr ;
1232
1240
1233
1241
// The list can be empty if command-list only contains signals of proxy
1234
1242
// events.
@@ -1436,6 +1444,23 @@ _pi_queue::getZeCopyCommandQueue(int *CopyQueueIndex,
1436
1444
return ZeCopyCommandQueue;
1437
1445
}
1438
1446
1447
+ pi_result _pi_queue::executeOpenCommandListWithEvent (pi_event Event) {
1448
+ // TODO: see if we can reliably tell if the event is copy or compute.
1449
+ // Meanwhile check both open command-lists.
1450
+ using IsCopy = bool ;
1451
+ if (hasOpenCommandList (IsCopy{false }) &&
1452
+ ComputeCommandBatch.OpenCommandList ->first == Event->ZeCommandList ) {
1453
+ if (auto Res = executeOpenCommandList (IsCopy{false }))
1454
+ return Res;
1455
+ }
1456
+ if (hasOpenCommandList (IsCopy{true }) &&
1457
+ CopyCommandBatch.OpenCommandList ->first == Event->ZeCommandList ) {
1458
+ if (auto Res = executeOpenCommandList (IsCopy{true }))
1459
+ return Res;
1460
+ }
1461
+ return PI_SUCCESS;
1462
+ }
1463
+
1439
1464
pi_result _pi_queue::executeOpenCommandList (bool IsCopy) {
1440
1465
auto &CommandBatch = IsCopy ? CopyCommandBatch : ComputeCommandBatch;
1441
1466
// If there are any commands still in the open command list for this
@@ -4797,23 +4822,7 @@ pi_result piEventGetInfo(pi_event Event, pi_event_info ParamName,
4797
4822
if (Event->Queue ) {
4798
4823
// Lock automatically releases when this goes out of scope.
4799
4824
std::lock_guard<std::mutex> lock (Event->Queue ->PiQueueMutex );
4800
-
4801
- // Only do the execute of the open command list if the event that
4802
- // is being queried and event that is to be signalled by something
4803
- // currently in that open command list.
4804
- using IsCopy = bool ;
4805
- if (Event->Queue ->hasOpenCommandList (IsCopy{false }) &&
4806
- Event->Queue ->ComputeCommandBatch .OpenCommandList ->first ==
4807
- Event->ZeCommandList ) {
4808
- if (auto Res = Event->Queue ->executeOpenCommandList (IsCopy{false }))
4809
- return Res;
4810
- }
4811
- if (Event->Queue ->hasOpenCommandList (IsCopy{true }) &&
4812
- Event->Queue ->CopyCommandBatch .OpenCommandList ->first ==
4813
- Event->ZeCommandList ) {
4814
- if (auto Res = Event->Queue ->executeOpenCommandList (IsCopy{true }))
4815
- return Res;
4816
- }
4825
+ Event->Queue ->executeOpenCommandListWithEvent (Event);
4817
4826
}
4818
4827
4819
4828
// Make sure that we query a host-visible event only.
@@ -5145,6 +5154,14 @@ pi_result piextEventGetNativeHandle(pi_event Event,
5145
5154
5146
5155
auto *ZeEvent = pi_cast<ze_event_handle_t *>(NativeHandle);
5147
5156
*ZeEvent = Event->ZeEvent ;
5157
+
5158
+ // Event can potentially be in an open command-list, make sure that
5159
+ // it is submitted for execution to avoid potential deadlock if
5160
+ // interop app is going to wait for it.
5161
+ if (Event->Queue ) {
5162
+ std::lock_guard<std::mutex> lock (Event->Queue ->PiQueueMutex );
5163
+ Event->Queue ->executeOpenCommandListWithEvent (Event);
5164
+ }
5148
5165
return PI_SUCCESS;
5149
5166
}
5150
5167
0 commit comments