Skip to content

Commit

Permalink
fix: Multi-threaded fix for get_default_context()
Browse files Browse the repository at this point in the history
Fixes L0 CTS failure in test run with Compute Aggregation Layer
./test_multithread --gtest_filter=GivenMultipleThreadsWhenMaking
TheDeviceMemoryResidentFollowedByEvictAndFreeThenSuccessIsReturned

Related-To: NEO-8927

Signed-off-by: Slawomir Milczarek <[email protected]>
  • Loading branch information
smilczar authored and Jemale committed Feb 23, 2024
1 parent e2f8b74 commit 29ebee7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions utils/utils/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -76,21 +76,19 @@ zes_driver_handle_t get_default_zes_driver() {
}

ze_context_handle_t get_default_context() {
ze_result_t result = ZE_RESULT_SUCCESS;

static std::once_flag contextInitializedFlag = {};
static ze_context_handle_t context = nullptr;

if (context) {
return context;
}

ze_context_desc_t context_desc = {};
context_desc.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
result = zeContextCreate(get_default_driver(), &context_desc, &context);
std::call_once(contextInitializedFlag, [&]() {
ze_result_t result = ZE_RESULT_SUCCESS;
ze_context_desc_t context_desc = {};
context_desc.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
result = zeContextCreate(get_default_driver(), &context_desc, &context);

if (ZE_RESULT_SUCCESS != result) {
throw std::runtime_error("zeContextCreate failed: " + to_string(result));
}
if (ZE_RESULT_SUCCESS != result) {
throw std::runtime_error("zeContextCreate failed: " + to_string(result));
}
});

return context;
}
Expand Down

0 comments on commit 29ebee7

Please sign in to comment.