Skip to content

Commit c4ae460

Browse files
committed
[CUDA] Catch and report bad_alloc errors for event object creation
1 parent 8499b57 commit c4ae460

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

source/adapters/cuda/event.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
283283

284284
std::unique_ptr<ur_event_handle_t_> EventPtr{nullptr};
285285

286-
*phEvent = ur_event_handle_t_::makeWithNative(
287-
hContext, reinterpret_cast<CUevent>(hNativeEvent));
286+
try {
287+
EventPtr =
288+
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeWithNative(
289+
hContext, reinterpret_cast<CUevent>(hNativeEvent)));
290+
} catch (const std::bad_alloc &) {
291+
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
292+
} catch (...) {
293+
return UR_RESULT_ERROR_UNKNOWN;
294+
}
295+
296+
*phEvent = EventPtr.release();
288297

289298
return UR_RESULT_SUCCESS;
290299
}

0 commit comments

Comments
 (0)