Skip to content
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

Remove static result in InitDrivers given first init fails #242

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Level zero loader changelog

## v1.19.2
* Remove static result in InitDrivers given first init fails
## v1.19.1
* Fix to Use relative paths for events deadlock detection third party headers
## v1.19.0
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ message(FATAL_ERROR "Visual Studio Compiler Version >= 1900 Required to build.")
endif()

# This project follows semantic versioning (https://semver.org/)
project(level-zero VERSION 1.19.1)
project(level-zero VERSION 1.19.2)

include(GNUInstallDirs)

Expand Down
6 changes: 4 additions & 2 deletions scripts/templates/libapi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ${th.make_func_name(n, tags, obj)}(
)
{
%if re.match("Init", obj['name']):
%if re.match("zes", n):
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
%if re.match("zes", n):
std::call_once(${x}_lib::context->initOnceSysMan, [flags]() {
result = ${x}_lib::context->Init(flags, true, nullptr);

Expand All @@ -81,7 +81,8 @@ ${th.make_func_name(n, tags, obj)}(
}
%else:
%if re.match("InitDrivers", obj['name']):
std::call_once(${x}_lib::context->initOnceDrivers, [desc]() {
${x}_result_t result = ${X}_RESULT_SUCCESS;
std::call_once(${x}_lib::context->initOnceDrivers, [desc,&result]() {
result = ${x}_lib::context->Init(0, false, desc);
return result;
});
Expand Down Expand Up @@ -112,6 +113,7 @@ ${th.make_func_name(n, tags, obj)}(

return result;
%else:
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
std::call_once(${x}_lib::context->initOnce, [flags]() {
result = ${x}_lib::context->Init(flags, false, nullptr);

Expand Down
4 changes: 2 additions & 2 deletions source/lib/ze_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ zeInitDrivers(
///< including ::ze_init_driver_type_flag_t combinations.
)
{
static ze_result_t result = ZE_RESULT_SUCCESS;
std::call_once(ze_lib::context->initOnceDrivers, [desc]() {
ze_result_t result = ZE_RESULT_SUCCESS;
std::call_once(ze_lib::context->initOnceDrivers, [desc,&result]() {
nrspruit marked this conversation as resolved.
Show resolved Hide resolved
result = ze_lib::context->Init(0, false, desc);
return result;
});
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ add_test(NAME tests_both_npu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderP
set_property(TEST tests_both_npu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")
add_test(NAME tests_missing_api COMMAND tests --gtest_filter=*GivenZeInitDriversUnsupportedOnTheDriverWhenCallingZeInitDriversThenUninitializedReturned*)
set_property(TEST tests_missing_api PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")
add_test(NAME tests_multi_call_failure COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithTypesUnsupportedWithFailureThenSupportedTypesThenSuccessReturned*)
set_property(TEST tests_multi_call_failure PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")

# These tests are currently not supported on Windows. The reason is that the std::cerr is not being redirected to a pipe in Windows to be then checked against the expected output.
if(NOT MSVC)
Expand Down
17 changes: 17 additions & 0 deletions test/loader_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ TEST(
}
}

TEST(
LoaderInit,
GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithTypesUnsupportedWithFailureThenSupportedTypesThenSuccessReturned) {

uint32_t pCount = 0;
ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC};
desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_NPU;
desc.pNext = nullptr;
putenv_safe( const_cast<char *>( "ZEL_TEST_NULL_DRIVER_TYPE=GPU" ) );
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInitDrivers(&pCount, nullptr, &desc));
EXPECT_EQ(pCount, 0);
pCount = 0;
desc.flags = UINT32_MAX;
EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc));
EXPECT_GT(pCount, 0);
}

TEST(
LoaderInit,
GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithGPUTypeThenExpectPassWithGPUorAllOnly) {
Expand Down
Loading