Skip to content

Commit 93b416a

Browse files
committed
[L0 v2] add missing catches to usm functions
1 parent 8f33719 commit 93b416a

File tree

1 file changed

+45
-10
lines changed
  • source/adapters/level_zero/v2

1 file changed

+45
-10
lines changed

source/adapters/level_zero/v2/usm.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,26 +199,37 @@ ur_result_t urUSMPoolCreate(
199199
pPoolDesc, ///< [in] pointer to USM pool descriptor. Can be chained with
200200
///< ::ur_usm_pool_limits_desc_t
201201
ur_usm_pool_handle_t *hPool ///< [out] pointer to USM memory pool
202-
) {
203-
202+
) try {
204203
*hPool = new ur_usm_pool_handle_t_(hContext, pPoolDesc);
205204
return UR_RESULT_SUCCESS;
205+
} catch (umf_result_t e) {
206+
return umf::umf2urResult(e);
207+
} catch (...) {
208+
return exceptionToResult(std::current_exception());
206209
}
207210

208211
ur_result_t
209212
urUSMPoolRetain(ur_usm_pool_handle_t hPool ///< [in] pointer to USM memory pool
210-
) {
213+
) try {
211214
hPool->RefCount.increment();
212215
return UR_RESULT_SUCCESS;
216+
} catch (umf_result_t e) {
217+
return umf::umf2urResult(e);
218+
} catch (...) {
219+
return exceptionToResult(std::current_exception());
213220
}
214221

215222
ur_result_t
216223
urUSMPoolRelease(ur_usm_pool_handle_t hPool ///< [in] pointer to USM memory pool
217-
) {
224+
) try {
218225
if (hPool->RefCount.decrementAndTest()) {
219226
delete hPool;
220227
}
221228
return UR_RESULT_SUCCESS;
229+
} catch (umf_result_t e) {
230+
return umf::umf2urResult(e);
231+
} catch (...) {
232+
return exceptionToResult(std::current_exception());
222233
}
223234

224235
ur_result_t urUSMPoolGetInfo(
@@ -229,7 +240,7 @@ ur_result_t urUSMPoolGetInfo(
229240
///< property
230241
size_t
231242
*pPropSizeRet ///< [out] size in bytes returned in pool property value
232-
) {
243+
) try {
233244
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
234245

235246
switch (propName) {
@@ -243,6 +254,10 @@ ur_result_t urUSMPoolGetInfo(
243254
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
244255
}
245256
}
257+
} catch (umf_result_t e) {
258+
return umf::umf2urResult(e);
259+
} catch (...) {
260+
return exceptionToResult(std::current_exception());
246261
}
247262

248263
ur_result_t urUSMDeviceAlloc(
@@ -255,13 +270,17 @@ ur_result_t urUSMDeviceAlloc(
255270
size_t
256271
size, ///< [in] size in bytes of the USM memory object to be allocated
257272
void **ppRetMem ///< [out] pointer to USM device memory object
258-
) {
273+
) try {
259274
if (!hPool) {
260275
hPool = hContext->getDefaultUSMPool();
261276
}
262277

263278
return hPool->allocate(hContext, hDevice, pUSMDesc, UR_USM_TYPE_DEVICE, size,
264279
ppRetMem);
280+
} catch (umf_result_t e) {
281+
return umf::umf2urResult(e);
282+
} catch (...) {
283+
return exceptionToResult(std::current_exception());
265284
}
266285

267286
ur_result_t urUSMSharedAlloc(
@@ -274,13 +293,17 @@ ur_result_t urUSMSharedAlloc(
274293
size_t
275294
size, ///< [in] size in bytes of the USM memory object to be allocated
276295
void **ppRetMem ///< [out] pointer to USM shared memory object
277-
) {
296+
) try {
278297
if (!hPool) {
279298
hPool = hContext->getDefaultUSMPool();
280299
}
281300

282301
return hPool->allocate(hContext, hDevice, pUSMDesc, UR_USM_TYPE_SHARED, size,
283302
ppRetMem);
303+
} catch (umf_result_t e) {
304+
return umf::umf2urResult(e);
305+
} catch (...) {
306+
return exceptionToResult(std::current_exception());
284307
}
285308

286309
ur_result_t urUSMHostAlloc(
@@ -292,21 +315,29 @@ ur_result_t urUSMHostAlloc(
292315
size_t
293316
size, ///< [in] size in bytes of the USM memory object to be allocated
294317
void **ppRetMem ///< [out] pointer to USM host memory object
295-
) {
318+
) try {
296319
if (!hPool) {
297320
hPool = hContext->getDefaultUSMPool();
298321
}
299322

300323
return hPool->allocate(hContext, nullptr, pUSMDesc, UR_USM_TYPE_HOST, size,
301324
ppRetMem);
325+
} catch (umf_result_t e) {
326+
return umf::umf2urResult(e);
327+
} catch (...) {
328+
return exceptionToResult(std::current_exception());
302329
}
303330

304331
ur_result_t
305332
urUSMFree(ur_context_handle_t hContext, ///< [in] handle of the context object
306333
void *pMem ///< [in] pointer to USM memory object
307-
) {
334+
) try {
308335
std::ignore = hContext;
309336
return umf::umf2urResult(umfFree(pMem));
337+
} catch (umf_result_t e) {
338+
return umf::umf2urResult(e);
339+
} catch (...) {
340+
return exceptionToResult(std::current_exception());
310341
}
311342

312343
ur_result_t urUSMGetMemAllocInfo(
@@ -319,7 +350,7 @@ ur_result_t urUSMGetMemAllocInfo(
319350
void *pPropValue, ///< [out][optional] value of the USM allocation property
320351
size_t *pPropValueSizeRet ///< [out][optional] bytes returned in USM
321352
///< allocation property
322-
) {
353+
) try {
323354
ze_device_handle_t zeDeviceHandle;
324355
ZeStruct<ze_memory_allocation_properties_t> zeMemoryAllocationProperties;
325356

@@ -383,5 +414,9 @@ ur_result_t urUSMGetMemAllocInfo(
383414
}
384415
}
385416
return UR_RESULT_SUCCESS;
417+
} catch (umf_result_t e) {
418+
return umf::umf2urResult(e);
419+
} catch (...) {
420+
return exceptionToResult(std::current_exception());
386421
}
387422
} // namespace ur::level_zero

0 commit comments

Comments
 (0)