Skip to content

Commit e525bc5

Browse files
Georgi Mirazchiyskiomarahmed1111
authored andcommitted
[HIP] Return error on silently failing urEventGetInfo queries for interop created events
1 parent d671824 commit e525bc5

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

source/adapters/hip/event.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
178178

179179
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
180180
switch (propName) {
181-
case UR_EVENT_INFO_COMMAND_QUEUE:
181+
case UR_EVENT_INFO_COMMAND_QUEUE: {
182+
// If the runtime owns the native handle, we have reference to the queue.
183+
// Otherwise, the event handle comes from an interop API with no RT refs.
184+
if (!hEvent->backendHasOwnership()) {
185+
setErrorMessage("Command queue info cannot be queried for the event. The "
186+
"event object was created from a native event and has no "
187+
"valid reference to a command queue.",
188+
UR_RESULT_ERROR_INVALID_VALUE);
189+
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
190+
}
191+
assert(hEvent->getQueue());
182192
return ReturnValue(hEvent->getQueue());
193+
}
183194
case UR_EVENT_INFO_COMMAND_TYPE:
184195
return ReturnValue(hEvent->getCommandType());
185196
case UR_EVENT_INFO_REFERENCE_COUNT:

test/adapters/hip/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_adapter_test(hip
1111
urDeviceGetNativeHandle.cpp
1212
urEventGetNativeHandle.cpp
1313
test_context.cpp
14+
test_event.cpp
1415
ENVIRONMENT
1516
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_hip>\""
1617
)

test/adapters/hip/test_event.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (C) 2022-2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include "event.hpp"
7+
#include "fixtures.h"
8+
#include "uur/raii.h"
9+
10+
#include <hip/hip_runtime.h>
11+
#include <tuple>
12+
13+
struct RAIIHipEvent {
14+
hipEvent_t handle = nullptr;
15+
16+
~RAIIHipEvent() {
17+
if (handle) {
18+
std::ignore = hipEventDestroy(handle);
19+
}
20+
}
21+
22+
hipEvent_t *ptr() { return &handle; }
23+
hipEvent_t get() { return handle; }
24+
};
25+
26+
using urHipEventTest = uur::urContextTest;
27+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urHipEventTest);
28+
29+
// Testing the urEventGetInfo behaviour for natively constructed (HIP) events.
30+
// Backend interop APIs can lead to creating event objects that are not fully
31+
// initialized. In the Cuda adapter, an event can have nullptr command queue
32+
// because the interop API does not associate a UR-owned queue with the event.
33+
TEST_P(urHipEventTest, GetQueueFromEventCreatedWithNativeHandle) {
34+
RAIIHipEvent hip_event;
35+
ASSERT_SUCCESS_HIP(
36+
hipEventCreateWithFlags(hip_event.ptr(), hipEventDefault));
37+
38+
auto native_event = reinterpret_cast<ur_native_handle_t>(hip_event.get());
39+
uur::raii::Event event{nullptr};
40+
ASSERT_SUCCESS(urEventCreateWithNativeHandle(native_event, context, nullptr,
41+
event.ptr()));
42+
EXPECT_NE(event, nullptr);
43+
44+
size_t ret_size{};
45+
ur_queue_handle_t q{};
46+
ASSERT_EQ_RESULT(urEventGetInfo(event, UR_EVENT_INFO_COMMAND_QUEUE,
47+
sizeof(ur_queue_handle_t), &q, &ret_size),
48+
UR_RESULT_ERROR_ADAPTER_SPECIFIC);
49+
}

0 commit comments

Comments
 (0)