@@ -5726,17 +5726,28 @@ pi_result _pi_queue::synchronize() {
5726
5726
return PI_SUCCESS;
5727
5727
};
5728
5728
5729
- for (auto &QueueMap : {ComputeQueueGroupsByTID, CopyQueueGroupsByTID})
5730
- for (auto &QueueGroup : QueueMap) {
5731
- if (Device->ImmCommandListUsed ) {
5732
- for (auto ImmCmdList : QueueGroup.second .ImmCmdLists )
5733
- syncImmCmdList (this , ImmCmdList);
5734
- } else {
5735
- for (auto &ZeQueue : QueueGroup.second .ZeQueues )
5736
- if (ZeQueue)
5737
- ZE_CALL (zeHostSynchronize, (ZeQueue));
5729
+ // Do nothing if the queue is empty
5730
+ if (!LastCommandEvent)
5731
+ return PI_SUCCESS;
5732
+
5733
+ // For in-order queue just wait for the last command.
5734
+ if (isInOrderQueue ()) {
5735
+ ZE_CALL (zeHostSynchronize, (LastCommandEvent->ZeEvent ));
5736
+ } else {
5737
+ // Otherwise sync all L0 queues/immediate command-lists.
5738
+ for (auto &QueueMap : {ComputeQueueGroupsByTID, CopyQueueGroupsByTID}) {
5739
+ for (auto &QueueGroup : QueueMap) {
5740
+ if (Device->ImmCommandListUsed ) {
5741
+ for (auto ImmCmdList : QueueGroup.second .ImmCmdLists )
5742
+ syncImmCmdList (this , ImmCmdList);
5743
+ } else {
5744
+ for (auto &ZeQueue : QueueGroup.second .ZeQueues )
5745
+ if (ZeQueue)
5746
+ ZE_CALL (zeHostSynchronize, (ZeQueue));
5747
+ }
5738
5748
}
5739
5749
}
5750
+ }
5740
5751
LastCommandEvent = nullptr ;
5741
5752
5742
5753
// With the entire queue synchronized, the active barriers must be done so we
0 commit comments