@@ -164,8 +164,18 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
164164 UrReturnHelper ReturnValue (propValueSize, pPropValue, pPropValueSizeRet);
165165
166166 switch (propName) {
167- case UR_EVENT_INFO_COMMAND_QUEUE:
167+ case UR_EVENT_INFO_COMMAND_QUEUE: {
168+ // If the runtime owns the native handle, we have reference to the queue.
169+ // Otherwise, the event handle comes from an interop API with no RT refs.
170+ if (!hEvent->getQueue ()) {
171+ setErrorMessage (" Command queue info cannot be queried for the event. The "
172+ " event object was created from a native event and has no "
173+ " valid reference to a command queue." ,
174+ UR_RESULT_ERROR_INVALID_VALUE);
175+ return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
176+ }
168177 return ReturnValue (hEvent->getQueue ());
178+ }
169179 case UR_EVENT_INFO_COMMAND_TYPE:
170180 return ReturnValue (hEvent->getCommandType ());
171181 case UR_EVENT_INFO_REFERENCE_COUNT:
@@ -280,17 +290,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
280290
281291 std::unique_ptr<ur_event_handle_t_> EventPtr{nullptr };
282292
283- try {
284- EventPtr =
285- std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeWithNative (
286- hContext, reinterpret_cast <CUevent>(hNativeEvent)));
287- } catch (const std::bad_alloc &) {
288- return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
289- } catch (...) {
290- return UR_RESULT_ERROR_UNKNOWN;
291- }
292-
293- *phEvent = EventPtr.release ();
293+ *phEvent = ur_event_handle_t_::makeWithNative (
294+ hContext, reinterpret_cast <CUevent>(hNativeEvent));
294295
295296 return UR_RESULT_SUCCESS;
296297}
0 commit comments