Skip to content

Commit 16fffbb

Browse files
authored
Remove static result in InitDrivers given first init fails (#242)
- Allow for the first zeInitDrivers to fail, but all following calls to succeed with different init flags. - Updated to v1.19.2 with the init result fix Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 91e2866 commit 16fffbb

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Level zero loader changelog
22

3+
## v1.19.2
4+
* Remove static result in InitDrivers given first init fails
35
## v1.19.1
46
* Fix to Use relative paths for events deadlock detection third party headers
57
## v1.19.0

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ message(FATAL_ERROR "Visual Studio Compiler Version >= 1900 Required to build.")
1313
endif()
1414

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

1818
include(GNUInstallDirs)
1919

Diff for: scripts/templates/libapi.cpp.mako

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ ${th.make_func_name(n, tags, obj)}(
5555
)
5656
{
5757
%if re.match("Init", obj['name']):
58+
%if re.match("zes", n):
5859
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
59-
%if re.match("zes", n):
6060
std::call_once(${x}_lib::context->initOnceSysMan, [flags]() {
6161
result = ${x}_lib::context->Init(flags, true, nullptr);
6262

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

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

Diff for: source/lib/ze_libapi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ zeInitDrivers(
196196
///< including ::ze_init_driver_type_flag_t combinations.
197197
)
198198
{
199-
static ze_result_t result = ZE_RESULT_SUCCESS;
200-
std::call_once(ze_lib::context->initOnceDrivers, [desc]() {
199+
ze_result_t result = ZE_RESULT_SUCCESS;
200+
std::call_once(ze_lib::context->initOnceDrivers, [desc,&result]() {
201201
result = ze_lib::context->Init(0, false, desc);
202202
return result;
203203
});

Diff for: test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ add_test(NAME tests_both_npu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderP
4141
set_property(TEST tests_both_npu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")
4242
add_test(NAME tests_missing_api COMMAND tests --gtest_filter=*GivenZeInitDriversUnsupportedOnTheDriverWhenCallingZeInitDriversThenUninitializedReturned*)
4343
set_property(TEST tests_missing_api PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")
44+
add_test(NAME tests_multi_call_failure COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithTypesUnsupportedWithFailureThenSupportedTypesThenSuccessReturned*)
45+
set_property(TEST tests_multi_call_failure PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1")
4446

4547
# 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.
4648
if(NOT MSVC)

Diff for: test/loader_api.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ TEST(
4848
}
4949
}
5050

51+
TEST(
52+
LoaderInit,
53+
GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithTypesUnsupportedWithFailureThenSupportedTypesThenSuccessReturned) {
54+
55+
uint32_t pCount = 0;
56+
ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC};
57+
desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_NPU;
58+
desc.pNext = nullptr;
59+
putenv_safe( const_cast<char *>( "ZEL_TEST_NULL_DRIVER_TYPE=GPU" ) );
60+
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInitDrivers(&pCount, nullptr, &desc));
61+
EXPECT_EQ(pCount, 0);
62+
pCount = 0;
63+
desc.flags = UINT32_MAX;
64+
EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc));
65+
EXPECT_GT(pCount, 0);
66+
}
67+
5168
TEST(
5269
LoaderInit,
5370
GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithGPUTypeThenExpectPassWithGPUorAllOnly) {

0 commit comments

Comments
 (0)