@@ -272,18 +272,23 @@ ur_result_t createUrImgFromZeImage(ze_context_handle_t hContext,
272
272
ze_device_handle_t hDevice,
273
273
const ZeStruct<ze_image_desc_t > &ZeImageDesc,
274
274
ur_exp_image_mem_native_handle_t *pImg) {
275
- ze_image_handle_t ZeImage;
276
- ZE2UR_CALL (zeImageCreate, (hContext, hDevice, &ZeImageDesc, &ZeImage));
277
- ZE2UR_CALL (zeContextMakeImageResident, (hContext, hDevice, ZeImage));
275
+ v2::raii::ze_image_handle_t ZeImage;
276
+ try {
277
+ ZE2UR_CALL_THROWS (zeImageCreate,
278
+ (hContext, hDevice, &ZeImageDesc, ZeImage.ptr ()));
279
+ ZE2UR_CALL_THROWS (zeContextMakeImageResident,
280
+ (hContext, hDevice, ZeImage.get ()));
281
+ } catch (...) {
282
+ return exceptionToResult (std::current_exception ());
283
+ }
278
284
279
285
try {
280
286
ur_bindless_mem_handle_t *urImg =
281
- new ur_bindless_mem_handle_t (ZeImage, ZeImageDesc);
287
+ new ur_bindless_mem_handle_t (ZeImage.get (), ZeImageDesc);
288
+ ZeImage.release ();
282
289
*pImg = reinterpret_cast <ur_exp_image_mem_native_handle_t >(urImg);
283
- } catch (const std::bad_alloc &) {
284
- return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
285
290
} catch (...) {
286
- return UR_RESULT_ERROR_UNKNOWN ;
291
+ return exceptionToResult ( std::current_exception ()) ;
287
292
}
288
293
return UR_RESULT_SUCCESS;
289
294
}
@@ -314,7 +319,7 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
314
319
BindlessDesc.flags |= ZE_IMAGE_BINDLESS_EXP_FLAG_SAMPLED_IMAGE;
315
320
}
316
321
317
- ze_image_handle_t ZeImage;
322
+ v2::raii:: ze_image_handle_t ZeImage;
318
323
319
324
ze_memory_allocation_properties_t MemAllocProperties{
320
325
ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES, nullptr ,
@@ -330,9 +335,15 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
330
335
reinterpret_cast <ur_bindless_mem_handle_t *>(hImageMem);
331
336
ze_image_handle_t zeImg1 = urImg->getZeImage ();
332
337
333
- ZE2UR_CALL (zeImageViewCreateExt,
334
- (zeCtx, hDevice->ZeDevice , &ZeImageDesc, zeImg1, &ZeImage));
335
- ZE2UR_CALL (zeContextMakeImageResident, (zeCtx, hDevice->ZeDevice , ZeImage));
338
+ try {
339
+ ZE2UR_CALL_THROWS (
340
+ zeImageViewCreateExt,
341
+ (zeCtx, hDevice->ZeDevice , &ZeImageDesc, zeImg1, ZeImage.ptr ()));
342
+ ZE2UR_CALL_THROWS (zeContextMakeImageResident,
343
+ (zeCtx, hDevice->ZeDevice , ZeImage.get ()));
344
+ } catch (...) {
345
+ return exceptionToResult (std::current_exception ());
346
+ }
336
347
} else if (MemAllocProperties.type == ZE_MEMORY_TYPE_DEVICE ||
337
348
MemAllocProperties.type == ZE_MEMORY_TYPE_HOST ||
338
349
MemAllocProperties.type == ZE_MEMORY_TYPE_SHARED) {
@@ -343,10 +354,14 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
343
354
} else {
344
355
BindlessDesc.pNext = &PitchedDesc;
345
356
}
346
-
347
- ZE2UR_CALL (zeImageCreate,
348
- (zeCtx, hDevice->ZeDevice , &ZeImageDesc, &ZeImage));
349
- ZE2UR_CALL (zeContextMakeImageResident, (zeCtx, hDevice->ZeDevice , ZeImage));
357
+ try {
358
+ ZE2UR_CALL_THROWS (zeImageCreate, (zeCtx, hDevice->ZeDevice , &ZeImageDesc,
359
+ ZeImage.ptr ()));
360
+ ZE2UR_CALL_THROWS (zeContextMakeImageResident,
361
+ (zeCtx, hDevice->ZeDevice , ZeImage.get ()));
362
+ } catch (...) {
363
+ return exceptionToResult (std::current_exception ());
364
+ }
350
365
} else {
351
366
return UR_RESULT_ERROR_INVALID_VALUE;
352
367
}
@@ -367,14 +382,16 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
367
382
uint64_t DeviceOffset{};
368
383
ze_image_handle_t ZeImageTranslated;
369
384
ZE2UR_CALL (zelLoaderTranslateHandle,
370
- (ZEL_HANDLE_IMAGE, ZeImage, (void **)&ZeImageTranslated));
385
+ (ZEL_HANDLE_IMAGE, ZeImage. get () , (void **)&ZeImageTranslated));
371
386
ZE2UR_CALL (zeImageGetDeviceOffsetExpFunctionPtr,
372
387
(ZeImageTranslated, &DeviceOffset));
373
388
*phImage = DeviceOffset;
374
389
375
390
std::shared_lock<ur_shared_mutex> Lock (hDevice->Mutex );
376
- hDevice->ZeOffsetToImageHandleMap [*phImage] = ZeImage;
391
+ hDevice->ZeOffsetToImageHandleMap [*phImage] = ZeImage. get () ;
377
392
Lock.release ();
393
+ ZeImage.release ();
394
+
378
395
return UR_RESULT_SUCCESS;
379
396
}
380
397
0 commit comments