@@ -75,7 +75,7 @@ urToHipImageChannelFormat(ur_image_channel_type_t image_channel_type,
7575 size_t pixel_size_bytes = 0 ;
7676 unsigned int num_channels = 0 ;
7777 unsigned int normalized_dtype_flag = 0 ;
78- UR_CHECK_ERROR (urCalculateNumChannels (image_channel_order, &num_channels));
78+ UR_CALL (urCalculateNumChannels (image_channel_order, &num_channels));
7979
8080 switch (image_channel_type) {
8181#define CASE (FROM, TO, SIZE, NORM ) \
@@ -293,8 +293,15 @@ urBindlessImagesUnsampledImageHandleDestroyExp(
293293 hDevice) != hContext->getDevices ().end (),
294294 UR_RESULT_ERROR_INVALID_CONTEXT);
295295
296- UR_CHECK_ERROR (
297- hipDestroySurfaceObject (reinterpret_cast <hipSurfaceObject_t>(hImage)));
296+ try {
297+ UR_CHECK_ERROR (
298+ hipDestroySurfaceObject (reinterpret_cast <hipSurfaceObject_t>(hImage)));
299+ } catch (ur_result_t error) {
300+ return error;
301+ } catch (...) {
302+ return UR_RESULT_ERROR_UNKNOWN;
303+ }
304+
298305 return UR_RESULT_SUCCESS;
299306}
300307
@@ -306,9 +313,15 @@ urBindlessImagesSampledImageHandleDestroyExp(
306313 hContext->getDevices ().end (),
307314 hDevice) != hContext->getDevices ().end (),
308315 UR_RESULT_ERROR_INVALID_CONTEXT);
316+ try {
317+ UR_CHECK_ERROR (
318+ hipTexObjectDestroy (reinterpret_cast <hipTextureObject_t>(hImage)));
319+ } catch (ur_result_t error) {
320+ return error;
321+ } catch (...) {
322+ return UR_RESULT_ERROR_UNKNOWN;
323+ }
309324
310- UR_CHECK_ERROR (
311- hipTexObjectDestroy (reinterpret_cast <hipTextureObject_t>(hImage)));
312325 return UR_RESULT_SUCCESS;
313326}
314327
@@ -324,12 +337,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageAllocateExp(
324337 // Populate descriptor
325338 HIP_ARRAY3D_DESCRIPTOR array_desc = {};
326339
327- UR_CHECK_ERROR (urCalculateNumChannels (pImageFormat->channelOrder ,
328- &array_desc.NumChannels ));
340+ UR_CALL (urCalculateNumChannels (pImageFormat->channelOrder ,
341+ &array_desc.NumChannels ));
329342
330- UR_CHECK_ERROR (urToHipImageChannelFormat (
331- pImageFormat-> channelType , pImageFormat->channelOrder , &array_desc. Format ,
332- nullptr , nullptr ));
343+ UR_CALL (urToHipImageChannelFormat (pImageFormat-> channelType ,
344+ pImageFormat->channelOrder ,
345+ &array_desc. Format , nullptr , nullptr ));
333346
334347 array_desc.Flags = 0 ; // No flags required
335348 array_desc.Width = pImageDesc->width ;
@@ -377,12 +390,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageAllocateExp(
377390 reinterpret_cast <ur_exp_image_mem_native_handle_t >(ImageArray);
378391 } catch (ur_result_t Err) {
379392 if (ImageArray) {
380- UR_CHECK_ERROR ( hipArrayDestroy (ImageArray) );
393+ ( void ) hipArrayDestroy (ImageArray);
381394 }
382395 return Err;
383396 } catch (...) {
384397 if (ImageArray) {
385- UR_CHECK_ERROR ( hipArrayDestroy (ImageArray) );
398+ ( void ) hipArrayDestroy (ImageArray);
386399 }
387400 return UR_RESULT_ERROR_UNKNOWN;
388401 }
@@ -398,12 +411,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageAllocateExp(
398411 reinterpret_cast <ur_exp_image_mem_native_handle_t >(mip_array);
399412 } catch (ur_result_t Err) {
400413 if (mip_array) {
401- UR_CHECK_ERROR ( hipMipmappedArrayDestroy (mip_array) );
414+ ( void ) hipMipmappedArrayDestroy (mip_array);
402415 }
403416 return Err;
404417 } catch (...) {
405418 if (mip_array) {
406- UR_CHECK_ERROR ( hipMipmappedArrayDestroy (mip_array) );
419+ ( void ) hipMipmappedArrayDestroy (mip_array);
407420 }
408421 return UR_RESULT_ERROR_UNKNOWN;
409422 }
@@ -444,14 +457,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesUnsampledImageCreateExp(
444457 UR_RESULT_ERROR_INVALID_CONTEXT);
445458
446459 unsigned int NumChannels = 0 ;
447- UR_CHECK_ERROR (
448- urCalculateNumChannels (pImageFormat->channelOrder , &NumChannels));
460+ UR_CALL (urCalculateNumChannels (pImageFormat->channelOrder , &NumChannels));
449461
450462 hipArray_Format format;
451463 size_t PixelSizeBytes;
452- UR_CHECK_ERROR (urToHipImageChannelFormat (pImageFormat->channelType ,
453- pImageFormat->channelOrder , &format,
454- &PixelSizeBytes, nullptr ));
464+ UR_CALL (urToHipImageChannelFormat (pImageFormat->channelType ,
465+ pImageFormat->channelOrder , &format,
466+ &PixelSizeBytes, nullptr ));
455467
456468 try {
457469
@@ -491,15 +503,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp(
491503 ScopedDevice Active (hDevice);
492504
493505 unsigned int NumChannels = 0 ;
494- UR_CHECK_ERROR (
495- urCalculateNumChannels (pImageFormat->channelOrder , &NumChannels));
506+ UR_CALL (urCalculateNumChannels (pImageFormat->channelOrder , &NumChannels));
496507
497508 hipArray_Format format;
498509 size_t PixelSizeBytes;
499510 unsigned int normalized_dtype_flag;
500- UR_CHECK_ERROR (urToHipImageChannelFormat (
501- pImageFormat-> channelType , pImageFormat->channelOrder , &format,
502- &PixelSizeBytes, &normalized_dtype_flag));
511+ UR_CALL (urToHipImageChannelFormat (pImageFormat-> channelType ,
512+ pImageFormat->channelOrder , &format,
513+ &PixelSizeBytes, &normalized_dtype_flag));
503514
504515 try {
505516 HIP_RESOURCE_DESC image_res_desc = {};
@@ -583,14 +594,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
583594 unsigned int NumChannels = 0 ;
584595 size_t PixelSizeBytes = 0 ;
585596
586- UR_CHECK_ERROR (
587- urCalculateNumChannels (pSrcImageFormat->channelOrder , &NumChannels));
597+ UR_CALL (urCalculateNumChannels (pSrcImageFormat->channelOrder , &NumChannels));
588598
589599 // We need to get this now in bytes for calculating the total image size
590600 // later.
591- UR_CHECK_ERROR (urToHipImageChannelFormat (pSrcImageFormat->channelType ,
592- pSrcImageFormat->channelOrder ,
593- nullptr , &PixelSizeBytes, nullptr ));
601+ UR_CALL (urToHipImageChannelFormat (pSrcImageFormat->channelType ,
602+ pSrcImageFormat->channelOrder , nullptr ,
603+ &PixelSizeBytes, nullptr ));
594604
595605 try {
596606 ScopedDevice Active (hQueue->getDevice ());
@@ -927,21 +937,27 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageGetInfoExp(
927937 // ROCm 5.6.0, so we can't query image array information for older versions.
928938#if HIP_VERSION >= 50600000
929939 unsigned int memType{};
930- UR_CHECK_ERROR (
940+ hipError_t Err =
931941 hipPointerGetAttribute (&memType, HIP_POINTER_ATTRIBUTE_MEMORY_TYPE,
932- reinterpret_cast <hipDeviceptr_t>(hImageMem)));
942+ reinterpret_cast <hipDeviceptr_t>(hImageMem));
943+ if (Err != hipSuccess) {
944+ return mapErrorUR (Err);
945+ }
933946 UR_ASSERT (memType == hipMemoryTypeArray, UR_RESULT_ERROR_INVALID_VALUE);
934947
935948 hipArray_t ImageArray;
936949 // If hipMipmappedArrayGetLevel failed, hImageMem is already hipArray_t.
937- if (hipError_t Err = hipMipmappedArrayGetLevel (
938- &ImageArray, reinterpret_cast <hipMipmappedArray_t>(hImageMem), 0 );
939- Err != hipSuccess) {
950+ Err = hipMipmappedArrayGetLevel (
951+ &ImageArray, reinterpret_cast <hipMipmappedArray_t>(hImageMem), 0 );
952+ if ( Err != hipSuccess) {
940953 ImageArray = reinterpret_cast <hipArray_t>(hImageMem);
941954 }
942955
943956 HIP_ARRAY3D_DESCRIPTOR ArrayDesc;
944- UR_CHECK_ERROR (hipArray3DGetDescriptor (&ArrayDesc, ImageArray));
957+ Err = hipArray3DGetDescriptor (&ArrayDesc, ImageArray);
958+ if (Err != hipSuccess) {
959+ return mapErrorUR (Err);
960+ }
945961
946962 switch (propName) {
947963 case UR_IMAGE_INFO_WIDTH:
@@ -971,7 +987,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageGetInfoExp(
971987 case UR_IMAGE_INFO_FORMAT: {
972988 ur_image_channel_type_t ChannelType{};
973989 ur_image_channel_order_t ChannelOrder{};
974- UR_CHECK_ERROR (hipToUrImageChannelFormat (ArrayDesc.Format , &ChannelType));
990+ UR_CALL (hipToUrImageChannelFormat (ArrayDesc.Format , &ChannelType));
975991 // HIP does not have a notion of channel "order" in the same way that
976992 // SYCL 1.2.1 does.
977993 switch (ArrayDesc.NumChannels ) {
0 commit comments