Skip to content

Commit 6ab07b9

Browse files
committed
add interop event tests with barriers
This tests a scenario where a native interop event is used as part of a barrier. Current implementation fails because it skips waiting on events if the queue is using driver in order lists.
1 parent 9ca3ec7 commit 6ab07b9

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

test/adapters/level_zero/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if(UR_BUILD_ADAPTER_L0)
1515
SOURCES
1616
urProgramLink.cpp
1717
urKernelCreateWithNativeHandle.cpp
18+
urEventCreateWithNativeHandle.cpp
1819
ENVIRONMENT
1920
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\""
2021
)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (C) 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 "ur_api.h"
7+
#include "uur/checks.h"
8+
#include "ze_api.h"
9+
#include <cstring>
10+
#include <thread>
11+
#include <uur/fixtures.h>
12+
13+
using namespace std::chrono_literals;
14+
using urLevelZeroEventNativeHandleTest = uur::urQueueTest;
15+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urLevelZeroEventNativeHandleTest);
16+
17+
#define TEST_MEMCPY_SIZE 4096
18+
19+
TEST_P(urLevelZeroEventNativeHandleTest, WaitForNative) {
20+
ze_event_pool_desc_t desc;
21+
desc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
22+
desc.pNext = nullptr;
23+
desc.count = 1;
24+
desc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
25+
26+
ur_native_handle_t nativeContext;
27+
ASSERT_SUCCESS(urContextGetNativeHandle(context, &nativeContext));
28+
29+
ur_native_handle_t nativeDevice;
30+
ASSERT_SUCCESS(urDeviceGetNativeHandle(device, &nativeDevice));
31+
32+
ze_event_pool_handle_t pool = nullptr;
33+
34+
ASSERT_EQ(zeEventPoolCreate((ze_context_handle_t)nativeContext, &desc, 1,
35+
(ze_device_handle_t *)&nativeDevice, &pool),
36+
ZE_RESULT_SUCCESS);
37+
38+
ze_event_desc_t eventDesc;
39+
eventDesc.pNext = nullptr;
40+
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
41+
eventDesc.index = 0;
42+
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
43+
eventDesc.wait = 0;
44+
45+
ze_event_handle_t zeEvent;
46+
ASSERT_EQ(zeEventCreate(pool, &eventDesc, &zeEvent), ZE_RESULT_SUCCESS);
47+
48+
ur_event_native_properties_t pprops;
49+
pprops.isNativeHandleOwned = false;
50+
pprops.pNext = nullptr;
51+
pprops.stype = UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES;
52+
53+
ur_event_handle_t urEvent;
54+
ASSERT_SUCCESS(urEventCreateWithNativeHandle((ur_native_handle_t)zeEvent,
55+
context, &pprops, &urEvent));
56+
57+
int *src = (int *)malloc(TEST_MEMCPY_SIZE);
58+
memset(src, 0xc, TEST_MEMCPY_SIZE);
59+
60+
int *dst = (int *)malloc(TEST_MEMCPY_SIZE);
61+
memset(dst, 0, TEST_MEMCPY_SIZE);
62+
63+
int *dst2 = (int *)malloc(TEST_MEMCPY_SIZE);
64+
memset(dst, 0, TEST_MEMCPY_SIZE);
65+
66+
ur_event_handle_t memcpyEvent2;
67+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, false, dst2, src, TEST_MEMCPY_SIZE,
68+
0, nullptr, &memcpyEvent2));
69+
70+
ur_event_handle_t memcpyEvent3;
71+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, false, dst2, src, TEST_MEMCPY_SIZE,
72+
0, nullptr, &memcpyEvent3));
73+
74+
// just to make wait lists contain more than 1 event
75+
ur_event_handle_t events[] = {memcpyEvent2, urEvent, memcpyEvent3};
76+
77+
ur_event_handle_t waitEvent;
78+
ASSERT_SUCCESS(
79+
urEnqueueEventsWaitWithBarrier(queue, 3, events, &waitEvent));
80+
81+
ur_event_handle_t memcpyEvent;
82+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, false, dst, src, TEST_MEMCPY_SIZE,
83+
1, &waitEvent, &memcpyEvent));
84+
85+
// urQueueFinish would hang, so we flush and then wait
86+
// some time to make sure the gpu had plenty of time
87+
// to do the memcpy.
88+
urQueueFlush(queue);
89+
std::this_thread::sleep_for(500ms);
90+
91+
ASSERT_NE(memcmp(src, dst, TEST_MEMCPY_SIZE), 0);
92+
93+
zeEventHostSignal(zeEvent);
94+
95+
urQueueFinish(queue);
96+
97+
ASSERT_EQ(memcmp(src, dst, 4096), 0);
98+
99+
free(src);
100+
free(dst);
101+
free(dst2);
102+
urEventRelease(urEvent);
103+
urEventRelease(waitEvent);
104+
urEventRelease(memcpyEvent);
105+
urEventRelease(memcpyEvent2);
106+
urEventRelease(memcpyEvent3);
107+
zeEventDestroy(zeEvent);
108+
zeEventPoolDestroy(pool);
109+
}

0 commit comments

Comments
 (0)