Skip to content

Commit

Permalink
Merge pull request #2396 from kswiecicki/init-results-fix
Browse files Browse the repository at this point in the history
[L0] Add nullopt check before init results access
  • Loading branch information
callumfare authored Nov 29, 2024
2 parents d8d8ee9 + 46832df commit eb076da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ Behavior Summary:
*/
ur_adapter_handle_t_::ur_adapter_handle_t_()
: logger(logger::get_logger("level_zero")) {
ZeInitDriversResult = ZE_RESULT_ERROR_UNINITIALIZED;
ZeInitResult = ZE_RESULT_ERROR_UNINITIALIZED;
ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;

if (UrL0Debug & UR_L0_DEBUG_BASIC) {
logger.setLegacySink(std::make_unique<ur_legacy_sink>());
Expand Down Expand Up @@ -331,9 +334,8 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
logger::debug("\nzeInit with flags value of {}\n",
static_cast<int>(L0InitFlags));
GlobalAdapter->ZeInitResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags));
if (*GlobalAdapter->ZeInitResult != ZE_RESULT_SUCCESS) {
logger::debug("\nzeInit failed with {}\n",
*GlobalAdapter->ZeInitResult);
if (GlobalAdapter->ZeInitResult != ZE_RESULT_SUCCESS) {
logger::debug("\nzeInit failed with {}\n", GlobalAdapter->ZeInitResult);
}

bool useInitDrivers = false;
Expand Down Expand Up @@ -376,17 +378,17 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
ZE_CALL_NOCHECK(GlobalAdapter->initDriversFunctionPtr,
(&GlobalAdapter->ZeInitDriversCount, nullptr,
&GlobalAdapter->InitDriversDesc));
if (*GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS) {
if (GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS) {
GlobalAdapter->InitDriversSupported = true;
} else {
logger::debug("\nzeInitDrivers failed with {}\n",
*GlobalAdapter->ZeInitDriversResult);
GlobalAdapter->ZeInitDriversResult);
}
}
}

if (*GlobalAdapter->ZeInitResult == ZE_RESULT_SUCCESS ||
*GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS) {
if (GlobalAdapter->ZeInitResult == ZE_RESULT_SUCCESS ||
GlobalAdapter->ZeInitDriversResult == ZE_RESULT_SUCCESS) {
GlobalAdapter->ZeResult = ZE_RESULT_SUCCESS;
} else {
GlobalAdapter->ZeResult = ZE_RESULT_ERROR_UNINITIALIZED;
Expand Down Expand Up @@ -450,7 +452,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
GlobalAdapter->ZesResult = ZE_RESULT_ERROR_UNINITIALIZED;
}

ur_result_t err = initPlatforms(platforms, *GlobalAdapter->ZesResult);
ur_result_t err = initPlatforms(platforms, GlobalAdapter->ZesResult);
if (err == UR_RESULT_SUCCESS) {
result = std::move(platforms);
} else {
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/level_zero/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ struct ur_adapter_handle_t_ {
uint32_t ZeInitDriversCount = 0;
bool InitDriversSupported = false;

std::optional<ze_result_t> ZeInitDriversResult;
std::optional<ze_result_t> ZeInitResult;
ze_result_t ZeInitDriversResult;
ze_result_t ZeInitResult;
ze_result_t ZesResult;
std::optional<ze_result_t> ZeResult;
std::optional<ze_result_t> ZesResult;
ZeCache<Result<PlatformVec>> PlatformCache;
logger::Logger &logger;
HMODULE processHandle = nullptr;
Expand Down

0 comments on commit eb076da

Please sign in to comment.