Skip to content

[UR][L0 v1/v2 adapter]Handle errors of img functions #18261

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

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Draft
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
21 changes: 19 additions & 2 deletions unified-runtime/source/adapters/level_zero/image_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,15 @@ ur_result_t createUrImgFromZeImage(ze_context_handle_t hContext,
ur_exp_image_mem_native_handle_t *pImg) {
ze_image_handle_t ZeImage;
ZE2UR_CALL(zeImageCreate, (hContext, hDevice, &ZeImageDesc, &ZeImage));
ZE2UR_CALL(zeContextMakeImageResident, (hContext, hDevice, ZeImage));
if (ZeImage == nullptr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually possible for ZeImage to be nullptr if we got SUCCESS from zeImageCreate?

return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
try {
ZE2UR_CALL_THROWS(zeContextMakeImageResident, (hContext, hDevice, ZeImage));
} catch (const ze_result_t &result) {
ZE2UR_CALL(zeImageDestroy, (ZeImage));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of manually calling zeImageDestory (which is error prone) it would be better to use v2::raii:ze_image_handle_t

return UR_RESULT_ERROR_INVALID_OPERATION;
}

try {
ur_bindless_mem_handle_t *urImg =
Expand Down Expand Up @@ -346,7 +354,16 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,

ZE2UR_CALL(zeImageCreate,
(zeCtx, hDevice->ZeDevice, &ZeImageDesc, &ZeImage));
ZE2UR_CALL(zeContextMakeImageResident, (zeCtx, hDevice->ZeDevice, ZeImage));
if (ZeImage == nullptr) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
try {
ZE2UR_CALL_THROWS(zeContextMakeImageResident,
(zeCtx, hDevice->ZeDevice, ZeImage));
} catch (const ze_result_t &result) {
ZE2UR_CALL(zeImageDestroy, (ZeImage));
return UR_RESULT_ERROR_INVALID_OPERATION;
}
} else {
return UR_RESULT_ERROR_INVALID_VALUE;
}
Expand Down