Skip to content

Commit

Permalink
[HIP] Catch and report bad_alloc errors for event object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeWeb committed Mar 4, 2024
1 parent c4ae460 commit 4c3f9ab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions source/adapters/hip/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hipEvent_t>(hNativeEvent));
std::unique_ptr<ur_event_handle_t_> EventPtr{nullptr};

try {
EventPtr =
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeWithNative(
hContext, reinterpret_cast<hipEvent_t>(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;
}

0 comments on commit 4c3f9ab

Please sign in to comment.