Skip to content

Commit

Permalink
Manually check error code from zeDeviceGetRootDevice calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
maarquitos14 committed Jan 9, 2024
1 parent bc711f4 commit 15d2953
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
if (!isCombinedMode) {
ze_device_handle_t RootDev = nullptr;
// Query Root Device
ZE2UR_CALL(zeDeviceGetRootDevice, (D->ZeDevice, &RootDev));
// We cannot use ZE2UR_CALL because under some circumstances this call may
// return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, and ZE2UR_CALL will abort
// because it's not UR_RESULT_SUCCESS. Instead, we use ZE_CALL_NOCHECK and
// we check manually that the result is either ZE_RESULT_SUCCESS or
// ZE_RESULT_ERROR_UNSUPPORTED_FEATURE.
auto errc =
ZE_CALL_NOCHECK(zeDeviceGetRootDevice, (D->ZeDevice, &RootDev));
if (errc != ZE_RESULT_SUCCESS &&
errc != ZE_RESULT_ERROR_UNSUPPORTED_FEATURE)
return ze2urResult(errc);
// For COMPOSITE and FLAT modes, RootDev will always be nullptr. Thus a
// single device returning RootDev != nullptr means we are in COMBINED
// mode.
Expand Down
14 changes: 12 additions & 2 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,18 @@ ur_result_t ur_platform_handle_t_::populateDeviceCacheIfNeeded() {
// through zeDeviceGetRootDevice. We need to cache the card device
// handle too, such that it is readily visible to the
// urDeviceCreateWithNativeHandle.
ze_device_handle_t RootDevice;
ZE2UR_CALL(zeDeviceGetRootDevice, (Device->ZeDevice, &RootDevice));
ze_device_handle_t RootDevice = nullptr;
// We cannot use ZE2UR_CALL because under some circumstances this call may
// return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, and ZE2UR_CALL will abort
// because it's not UR_RESULT_SUCCESS. Instead, we use ZE_CALL_NOCHECK and
// we check manually that the result is either ZE_RESULT_SUCCESS or
// ZE_RESULT_ERROR_UNSUPPORTED_FEATURE.
auto errc = ZE_CALL_NOCHECK(zeDeviceGetRootDevice,
(Device->ZeDevice, &RootDevice));
if (errc != ZE_RESULT_SUCCESS &&
errc != ZE_RESULT_ERROR_UNSUPPORTED_FEATURE)
return ze2urResult(errc);

if (RootDevice) {
if (std::find_if(URDevicesCache.begin(), URDevicesCache.end(),
[&](auto &Dev) {
Expand Down

0 comments on commit 15d2953

Please sign in to comment.