@@ -315,51 +315,61 @@ std::vector<char> ur_kernel_handle_t_::getSourceAttributes() const {
315315namespace ur ::level_zero {
316316ur_result_t urKernelCreate (ur_program_handle_t hProgram,
317317 const char *pKernelName,
318- ur_kernel_handle_t *phKernel) {
318+ ur_kernel_handle_t *phKernel) try {
319319 *phKernel = new ur_kernel_handle_t_ (hProgram, pKernelName);
320320 return UR_RESULT_SUCCESS;
321+ } catch (...) {
322+ return exceptionToResult (std::current_exception ());
321323}
322324
323325ur_result_t urKernelGetNativeHandle (ur_kernel_handle_t hKernel,
324- ur_native_handle_t *phNativeKernel) {
326+ ur_native_handle_t *phNativeKernel) try {
325327 // Return the handle of the kernel for the first device
326328 *phNativeKernel =
327329 reinterpret_cast <ur_native_handle_t >(hKernel->getNativeZeHandle ());
328330 return UR_RESULT_SUCCESS;
331+ } catch (...) {
332+ return exceptionToResult (std::current_exception ());
329333}
330334
331335ur_result_t
332336urKernelCreateWithNativeHandle (ur_native_handle_t hNativeKernel,
333337 ur_context_handle_t hContext,
334338 ur_program_handle_t hProgram,
335339 const ur_kernel_native_properties_t *pProperties,
336- ur_kernel_handle_t *phKernel) {
340+ ur_kernel_handle_t *phKernel) try {
337341 if (!hProgram) {
338342 return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
339343 }
340344
341345 *phKernel =
342346 new ur_kernel_handle_t_ (hNativeKernel, hProgram, hContext, pProperties);
343347 return UR_RESULT_SUCCESS;
348+ } catch (...) {
349+ return exceptionToResult (std::current_exception ());
344350}
345351
346352ur_result_t urKernelRetain (
347353 ur_kernel_handle_t hKernel // /< [in] handle for the Kernel to retain
348- ) {
354+ ) try {
349355 hKernel->RefCount .increment ();
350356 return UR_RESULT_SUCCESS;
357+ } catch (...) {
358+ return exceptionToResult (std::current_exception ());
351359}
352360
353361ur_result_t urKernelRelease (
354362 ur_kernel_handle_t hKernel // /< [in] handle for the Kernel to release
355- ) {
363+ ) try {
356364 if (!hKernel->RefCount .decrementAndTest ())
357365 return UR_RESULT_SUCCESS;
358366
359367 hKernel->release ();
360368 delete hKernel;
361369
362370 return UR_RESULT_SUCCESS;
371+ } catch (...) {
372+ return exceptionToResult (std::current_exception ());
363373}
364374
365375ur_result_t urKernelSetArgValue (
@@ -370,11 +380,13 @@ ur_result_t urKernelSetArgValue(
370380 *pProperties, // /< [in][optional] argument properties
371381 const void
372382 *pArgValue // /< [in] argument value represented as matching arg type.
373- ) {
383+ ) try {
374384 TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgValue" );
375385
376386 std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
377387 return hKernel->setArgValue (argIndex, argSize, pProperties, pArgValue);
388+ } catch (...) {
389+ return exceptionToResult (std::current_exception ());
378390}
379391
380392ur_result_t urKernelSetArgPointer (
@@ -384,11 +396,13 @@ ur_result_t urKernelSetArgPointer(
384396 *pProperties, // /< [in][optional] argument properties
385397 const void
386398 *pArgValue // /< [in] argument value represented as matching arg type.
387- ) {
399+ ) try {
388400 TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgPointer" );
389401
390402 std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
391403 return hKernel->setArgPointer (argIndex, pProperties, pArgValue);
404+ } catch (...) {
405+ return exceptionToResult (std::current_exception ());
392406}
393407
394408static ur_mem_handle_t_::device_access_mode_t memAccessFromKernelProperties (
@@ -411,7 +425,7 @@ static ur_mem_handle_t_::device_access_mode_t memAccessFromKernelProperties(
411425ur_result_t
412426urKernelSetArgMemObj (ur_kernel_handle_t hKernel, uint32_t argIndex,
413427 const ur_kernel_arg_mem_obj_properties_t *pProperties,
414- ur_mem_handle_t hArgValue) {
428+ ur_mem_handle_t hArgValue) try {
415429 TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgMemObj" );
416430
417431 std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
@@ -420,19 +434,23 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
420434 {hArgValue, memAccessFromKernelProperties (pProperties), argIndex}));
421435
422436 return UR_RESULT_SUCCESS;
437+ } catch (...) {
438+ return exceptionToResult (std::current_exception ());
423439}
424440
425441ur_result_t
426442urKernelSetArgLocal (ur_kernel_handle_t hKernel, uint32_t argIndex,
427443 size_t argSize,
428- const ur_kernel_arg_local_properties_t *pProperties) {
444+ const ur_kernel_arg_local_properties_t *pProperties) try {
429445 TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgLocal" );
430446
431447 std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
432448
433449 std::ignore = pProperties;
434450
435451 return hKernel->setArgValue (argIndex, argSize, nullptr , nullptr );
452+ } catch (...) {
453+ return exceptionToResult (std::current_exception ());
436454}
437455
438456ur_result_t urKernelSetExecInfo (
@@ -443,13 +461,15 @@ ur_result_t urKernelSetExecInfo(
443461 *pProperties, // /< [in][optional] pointer to execution info properties
444462 const void *pPropValue // /< [in][range(0, propSize)] pointer to memory
445463 // /< location holding the property value.
446- ) {
464+ ) try {
447465 std::ignore = propSize;
448466 std::ignore = pProperties;
449467
450468 std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
451469
452470 return hKernel->setExecInfo (propName, pPropValue);
471+ } catch (...) {
472+ return exceptionToResult (std::current_exception ());
453473}
454474
455475ur_result_t urKernelGetGroupInfo (
@@ -463,7 +483,7 @@ ur_result_t urKernelGetGroupInfo(
463483 // /< Kernel Work Group property.
464484 size_t *pParamValueSizeRet // /< [out][optional] pointer to the actual size
465485 // /< in bytes of data being queried by propName.
466- ) {
486+ ) try {
467487 UrReturnHelper returnValue (paramValueSize, pParamValue, pParamValueSizeRet);
468488
469489 // No locking needed here, we only read const members
@@ -529,6 +549,8 @@ ur_result_t urKernelGetGroupInfo(
529549 }
530550 }
531551 return UR_RESULT_SUCCESS;
552+ } catch (...) {
553+ return exceptionToResult (std::current_exception ());
532554}
533555
534556ur_result_t urKernelGetSubGroupInfo (
@@ -541,7 +563,7 @@ ur_result_t urKernelGetSubGroupInfo(
541563 // /< Kernel SubGroup property.
542564 size_t *pPropSizeRet // /< [out][optional] pointer to the actual size in
543565 // /< bytes of data being queried by propName.
544- ) {
566+ ) try {
545567 UrReturnHelper returnValue (propSize, pPropValue, pPropSizeRet);
546568
547569 auto props = hKernel->getProperties (hDevice);
@@ -560,11 +582,13 @@ ur_result_t urKernelGetSubGroupInfo(
560582 return {};
561583 }
562584 return UR_RESULT_SUCCESS;
585+ } catch (...) {
586+ return exceptionToResult (std::current_exception ());
563587}
564588
565589ur_result_t urKernelGetInfo (ur_kernel_handle_t hKernel,
566590 ur_kernel_info_t paramName, size_t propSize,
567- void *pKernelInfo, size_t *pPropSizeRet) {
591+ void *pKernelInfo, size_t *pPropSizeRet) try {
568592
569593 UrReturnHelper ReturnValue (propSize, pKernelInfo, pPropSizeRet);
570594
@@ -596,5 +620,7 @@ ur_result_t urKernelGetInfo(ur_kernel_handle_t hKernel,
596620 }
597621
598622 return UR_RESULT_SUCCESS;
623+ } catch (...) {
624+ return exceptionToResult (std::current_exception ());
599625}
600626} // namespace ur::level_zero
0 commit comments