Skip to content

[SYCL][L0] Move command list cache usage under mutex #5874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,19 +1108,20 @@ _pi_context::getAvailableCommandList(pi_queue Queue,
// command list is available for reuse.
_pi_result pi_result = PI_OUT_OF_RESOURCES;
ZeStruct<ze_fence_desc_t> ZeFenceDesc;

auto &ZeCommandListCache =
UseCopyEngine
? Queue->Context->ZeCopyCommandListCache[Queue->Device->ZeDevice]
: Queue->Context->ZeComputeCommandListCache[Queue->Device->ZeDevice];

// Initally, we need to check if a command list has already been created
// on this device that is available for use. If so, then reuse that
// Level-Zero Command List and Fence for this PI call.
{
// Make sure to acquire the lock before checking the size, or there
// will be a race condition.
std::lock_guard<std::mutex> lock(Queue->Context->ZeCommandListCacheMutex);
// Under mutex since operator[] does insertion on the first usage for every
// unique ZeDevice.
auto &ZeCommandListCache =
UseCopyEngine
? Queue->Context->ZeCopyCommandListCache[Queue->Device->ZeDevice]
: Queue->Context
->ZeComputeCommandListCache[Queue->Device->ZeDevice];

if (ZeCommandListCache.size() > 0) {
auto &ZeCommandList = ZeCommandListCache.front();
Expand Down