From 78947c1a1c61255f5bb44d36ccf6bf18394b7762 Mon Sep 17 00:00:00 2001 From: Georgi Mirazchiyski Date: Mon, 12 Aug 2024 13:29:56 +0100 Subject: [PATCH] [Cuda] Reintroduce catching and reporting of bad_alloc for event object creation Reintroduces the changes from commit c4ae460, which were reverted in related merged commit 1b4a8b8 due to being mistakenly deleted and omitted on rebasing. --- 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 42f3e634e6..a6c2208e8f 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -290,8 +290,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; }