From c4ae460f779021aa6840ea47a373f6ac336bc589 Mon Sep 17 00:00:00 2001 From: Georgi Mirazchiyski Date: Thu, 29 Feb 2024 12:35:25 +0000 Subject: [PATCH 1/2] [CUDA] Catch and report bad_alloc errors for event object creation --- source/adapters/cuda/event.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 804b35a9b7..b4705a99d5 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -283,8 +283,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( std::unique_ptr EventPtr{nullptr}; - *phEvent = ur_event_handle_t_::makeWithNative( - hContext, reinterpret_cast(hNativeEvent)); + try { + EventPtr = + std::unique_ptr(ur_event_handle_t_::makeWithNative( + hContext, reinterpret_cast(hNativeEvent))); + } catch (const std::bad_alloc &) { + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } catch (...) { + return UR_RESULT_ERROR_UNKNOWN; + } + + *phEvent = EventPtr.release(); return UR_RESULT_SUCCESS; } From 4c3f9abec336f4833d22ee9f9f6593c653031c16 Mon Sep 17 00:00:00 2001 From: Georgi Mirazchiyski Date: Thu, 29 Feb 2024 12:35:40 +0000 Subject: [PATCH 2/2] [HIP] Catch and report bad_alloc errors for event object creation --- source/adapters/hip/event.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/adapters/hip/event.cpp b/source/adapters/hip/event.cpp index 313212724a..5cf5f98c92 100644 --- a/source/adapters/hip/event.cpp +++ b/source/adapters/hip/event.cpp @@ -330,8 +330,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( ur_event_handle_t *phEvent) { std::ignore = pProperties; - *phEvent = ur_event_handle_t_::makeWithNative( - hContext, reinterpret_cast(hNativeEvent)); + std::unique_ptr EventPtr{nullptr}; + + try { + EventPtr = + std::unique_ptr(ur_event_handle_t_::makeWithNative( + hContext, reinterpret_cast(hNativeEvent))); + } catch (const std::bad_alloc &) { + return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } catch (...) { + return UR_RESULT_ERROR_UNKNOWN; + } + + *phEvent = EventPtr.release(); return UR_RESULT_SUCCESS; }