@@ -315,51 +315,61 @@ std::vector<char> ur_kernel_handle_t_::getSourceAttributes() const {
315
315
namespace ur ::level_zero {
316
316
ur_result_t urKernelCreate (ur_program_handle_t hProgram,
317
317
const char *pKernelName,
318
- ur_kernel_handle_t *phKernel) {
318
+ ur_kernel_handle_t *phKernel) try {
319
319
*phKernel = new ur_kernel_handle_t_ (hProgram, pKernelName);
320
320
return UR_RESULT_SUCCESS;
321
+ } catch (...) {
322
+ return exceptionToResult (std::current_exception ());
321
323
}
322
324
323
325
ur_result_t urKernelGetNativeHandle (ur_kernel_handle_t hKernel,
324
- ur_native_handle_t *phNativeKernel) {
326
+ ur_native_handle_t *phNativeKernel) try {
325
327
// Return the handle of the kernel for the first device
326
328
*phNativeKernel =
327
329
reinterpret_cast <ur_native_handle_t >(hKernel->getNativeZeHandle ());
328
330
return UR_RESULT_SUCCESS;
331
+ } catch (...) {
332
+ return exceptionToResult (std::current_exception ());
329
333
}
330
334
331
335
ur_result_t
332
336
urKernelCreateWithNativeHandle (ur_native_handle_t hNativeKernel,
333
337
ur_context_handle_t hContext,
334
338
ur_program_handle_t hProgram,
335
339
const ur_kernel_native_properties_t *pProperties,
336
- ur_kernel_handle_t *phKernel) {
340
+ ur_kernel_handle_t *phKernel) try {
337
341
if (!hProgram) {
338
342
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
339
343
}
340
344
341
345
*phKernel =
342
346
new ur_kernel_handle_t_ (hNativeKernel, hProgram, hContext, pProperties);
343
347
return UR_RESULT_SUCCESS;
348
+ } catch (...) {
349
+ return exceptionToResult (std::current_exception ());
344
350
}
345
351
346
352
ur_result_t urKernelRetain (
347
353
ur_kernel_handle_t hKernel // /< [in] handle for the Kernel to retain
348
- ) {
354
+ ) try {
349
355
hKernel->RefCount .increment ();
350
356
return UR_RESULT_SUCCESS;
357
+ } catch (...) {
358
+ return exceptionToResult (std::current_exception ());
351
359
}
352
360
353
361
ur_result_t urKernelRelease (
354
362
ur_kernel_handle_t hKernel // /< [in] handle for the Kernel to release
355
- ) {
363
+ ) try {
356
364
if (!hKernel->RefCount .decrementAndTest ())
357
365
return UR_RESULT_SUCCESS;
358
366
359
367
hKernel->release ();
360
368
delete hKernel;
361
369
362
370
return UR_RESULT_SUCCESS;
371
+ } catch (...) {
372
+ return exceptionToResult (std::current_exception ());
363
373
}
364
374
365
375
ur_result_t urKernelSetArgValue (
@@ -370,11 +380,13 @@ ur_result_t urKernelSetArgValue(
370
380
*pProperties, // /< [in][optional] argument properties
371
381
const void
372
382
*pArgValue // /< [in] argument value represented as matching arg type.
373
- ) {
383
+ ) try {
374
384
TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgValue" );
375
385
376
386
std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
377
387
return hKernel->setArgValue (argIndex, argSize, pProperties, pArgValue);
388
+ } catch (...) {
389
+ return exceptionToResult (std::current_exception ());
378
390
}
379
391
380
392
ur_result_t urKernelSetArgPointer (
@@ -384,11 +396,13 @@ ur_result_t urKernelSetArgPointer(
384
396
*pProperties, // /< [in][optional] argument properties
385
397
const void
386
398
*pArgValue // /< [in] argument value represented as matching arg type.
387
- ) {
399
+ ) try {
388
400
TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgPointer" );
389
401
390
402
std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
391
403
return hKernel->setArgPointer (argIndex, pProperties, pArgValue);
404
+ } catch (...) {
405
+ return exceptionToResult (std::current_exception ());
392
406
}
393
407
394
408
static ur_mem_handle_t_::device_access_mode_t memAccessFromKernelProperties (
@@ -411,7 +425,7 @@ static ur_mem_handle_t_::device_access_mode_t memAccessFromKernelProperties(
411
425
ur_result_t
412
426
urKernelSetArgMemObj (ur_kernel_handle_t hKernel, uint32_t argIndex,
413
427
const ur_kernel_arg_mem_obj_properties_t *pProperties,
414
- ur_mem_handle_t hArgValue) {
428
+ ur_mem_handle_t hArgValue) try {
415
429
TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgMemObj" );
416
430
417
431
std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
@@ -420,19 +434,23 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
420
434
{hArgValue, memAccessFromKernelProperties (pProperties), argIndex}));
421
435
422
436
return UR_RESULT_SUCCESS;
437
+ } catch (...) {
438
+ return exceptionToResult (std::current_exception ());
423
439
}
424
440
425
441
ur_result_t
426
442
urKernelSetArgLocal (ur_kernel_handle_t hKernel, uint32_t argIndex,
427
443
size_t argSize,
428
- const ur_kernel_arg_local_properties_t *pProperties) {
444
+ const ur_kernel_arg_local_properties_t *pProperties) try {
429
445
TRACK_SCOPE_LATENCY (" ur_kernel_handle_t_::setArgLocal" );
430
446
431
447
std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
432
448
433
449
std::ignore = pProperties;
434
450
435
451
return hKernel->setArgValue (argIndex, argSize, nullptr , nullptr );
452
+ } catch (...) {
453
+ return exceptionToResult (std::current_exception ());
436
454
}
437
455
438
456
ur_result_t urKernelSetExecInfo (
@@ -443,13 +461,15 @@ ur_result_t urKernelSetExecInfo(
443
461
*pProperties, // /< [in][optional] pointer to execution info properties
444
462
const void *pPropValue // /< [in][range(0, propSize)] pointer to memory
445
463
// /< location holding the property value.
446
- ) {
464
+ ) try {
447
465
std::ignore = propSize;
448
466
std::ignore = pProperties;
449
467
450
468
std::scoped_lock<ur_shared_mutex> guard (hKernel->Mutex );
451
469
452
470
return hKernel->setExecInfo (propName, pPropValue);
471
+ } catch (...) {
472
+ return exceptionToResult (std::current_exception ());
453
473
}
454
474
455
475
ur_result_t urKernelGetGroupInfo (
@@ -463,7 +483,7 @@ ur_result_t urKernelGetGroupInfo(
463
483
// /< Kernel Work Group property.
464
484
size_t *pParamValueSizeRet // /< [out][optional] pointer to the actual size
465
485
// /< in bytes of data being queried by propName.
466
- ) {
486
+ ) try {
467
487
UrReturnHelper returnValue (paramValueSize, pParamValue, pParamValueSizeRet);
468
488
469
489
// No locking needed here, we only read const members
@@ -529,6 +549,8 @@ ur_result_t urKernelGetGroupInfo(
529
549
}
530
550
}
531
551
return UR_RESULT_SUCCESS;
552
+ } catch (...) {
553
+ return exceptionToResult (std::current_exception ());
532
554
}
533
555
534
556
ur_result_t urKernelGetSubGroupInfo (
@@ -541,7 +563,7 @@ ur_result_t urKernelGetSubGroupInfo(
541
563
// /< Kernel SubGroup property.
542
564
size_t *pPropSizeRet // /< [out][optional] pointer to the actual size in
543
565
// /< bytes of data being queried by propName.
544
- ) {
566
+ ) try {
545
567
UrReturnHelper returnValue (propSize, pPropValue, pPropSizeRet);
546
568
547
569
auto props = hKernel->getProperties (hDevice);
@@ -560,11 +582,13 @@ ur_result_t urKernelGetSubGroupInfo(
560
582
return {};
561
583
}
562
584
return UR_RESULT_SUCCESS;
585
+ } catch (...) {
586
+ return exceptionToResult (std::current_exception ());
563
587
}
564
588
565
589
ur_result_t urKernelGetInfo (ur_kernel_handle_t hKernel,
566
590
ur_kernel_info_t paramName, size_t propSize,
567
- void *pKernelInfo, size_t *pPropSizeRet) {
591
+ void *pKernelInfo, size_t *pPropSizeRet) try {
568
592
569
593
UrReturnHelper ReturnValue (propSize, pKernelInfo, pPropSizeRet);
570
594
@@ -596,5 +620,7 @@ ur_result_t urKernelGetInfo(ur_kernel_handle_t hKernel,
596
620
}
597
621
598
622
return UR_RESULT_SUCCESS;
623
+ } catch (...) {
624
+ return exceptionToResult (std::current_exception ());
599
625
}
600
626
} // namespace ur::level_zero
0 commit comments