|
| 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