Skip to content

Commit

Permalink
[L0] Add compare and swap for setting the LastCommandEvent in all cases
Browse files Browse the repository at this point in the history
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit committed Jun 13, 2024
1 parent 6db9291 commit 5df64a3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,7 @@ ur_result_t ur_queue_handle_t_::synchronize() {
// If event is discarded then it can be in reset state or underlying level
// zero handle can have device scope, so we can't synchronize the last
// event.
auto savedLastCommandEvent = LastCommandEvent;
if (isInOrderQueue() && !LastCommandEvent->IsDiscarded) {
ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent));

Expand Down Expand Up @@ -1737,7 +1738,14 @@ ur_result_t ur_queue_handle_t_::synchronize() {
}
}
}
LastCommandEvent = nullptr;
// If the current version of the LastCommandEvent == savedLastCommandEvent,
// then LastCommandEvent = nullptr; Otherwise, if LastCommandEvent !=
// savedLastCommandEvent, then LastCommandEvent is unchanged.
std::atomic<ur_event_handle_t> LastCommandEventAtomic = LastCommandEvent;
if (LastCommandEventAtomic.compare_exchange_strong(savedLastCommandEvent,
nullptr)) {
LastCommandEvent = LastCommandEventAtomic.load();
}
}

// Since all timestamp recordings should have finished with the
Expand Down

0 comments on commit 5df64a3

Please sign in to comment.