Skip to content

Commit 52a7fc6

Browse files
author
Hugh Delaney
committed
Add ScopedStream testing for UR CUDA adapter
1 parent d574d16 commit 52a7fc6

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/adapters/cuda/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ add_adapter_test(cuda
1313
urDeviceCreateWithNativeHandle.cpp
1414
urEventGetNativeHandle.cpp
1515
urEventCreateWithNativeHandle.cpp
16+
urQueueGetNativeHandle.cpp
1617
kernel_tests.cpp
1718
memory_tests.cpp
19+
#FIXME: make this cleaner
20+
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/queue.cpp
21+
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/common.cpp
1822
ENVIRONMENT
1923
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_cuda>\""
2024
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 "fixtures.h"
7+
#include "queue.hpp"
8+
9+
using urCudaQueueGetNativeHandleTest = uur::urQueueTest;
10+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaQueueGetNativeHandleTest);
11+
12+
TEST_P(urCudaQueueGetNativeHandleTest, Success) {
13+
CUstream Stream;
14+
ASSERT_SUCCESS(
15+
urQueueGetNativeHandle(queue, nullptr, (ur_native_handle_t *)&Stream));
16+
ASSERT_SUCCESS_CUDA(cuStreamSynchronize(Stream));
17+
}
18+
19+
TEST_P(urCudaQueueGetNativeHandleTest, OutOfOrder) {
20+
CUstream Stream;
21+
ur_queue_properties_t props = {
22+
/*.stype =*/UR_STRUCTURE_TYPE_QUEUE_PROPERTIES,
23+
/*.pNext =*/nullptr,
24+
/*.flags =*/UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE,
25+
};
26+
ASSERT_SUCCESS(urQueueCreate(context, device, &props, &queue));
27+
ASSERT_SUCCESS(
28+
urQueueGetNativeHandle(queue, nullptr, (ur_native_handle_t *)&Stream));
29+
ASSERT_SUCCESS_CUDA(cuStreamSynchronize(Stream));
30+
}
31+
32+
TEST_P(urCudaQueueGetNativeHandleTest, ScopedStream) {
33+
CUstream Stream1, Stream2;
34+
ur_queue_properties_t props = {
35+
/*.stype =*/UR_STRUCTURE_TYPE_QUEUE_PROPERTIES,
36+
/*.pNext =*/nullptr,
37+
/*.flags =*/UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE,
38+
};
39+
ur_queue_handle_t OutOfOrderQueue;
40+
ASSERT_SUCCESS(urQueueCreate(context, device, &props, &OutOfOrderQueue));
41+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
42+
(ur_native_handle_t *)&Stream1));
43+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
44+
(ur_native_handle_t *)&Stream2));
45+
46+
// We might want to remove this assertion at some point. This is just
47+
// testing current implementated behaviour that getting the native OutOfOrderQueue
48+
// will call `getNextComputeStream`
49+
ASSERT_NE(Stream1, Stream2);
50+
51+
{
52+
ScopedStream ActiveStream(OutOfOrderQueue, 0, nullptr);
53+
54+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
55+
(ur_native_handle_t *)&Stream1));
56+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
57+
(ur_native_handle_t *)&Stream2));
58+
ASSERT_EQ(Stream1, Stream2);
59+
}
60+
61+
// Go back to returning new streams each time
62+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
63+
(ur_native_handle_t *)&Stream1));
64+
ASSERT_SUCCESS(urQueueGetNativeHandle(OutOfOrderQueue, nullptr,
65+
(ur_native_handle_t *)&Stream2));
66+
ASSERT_NE(Stream1, Stream2);
67+
}

0 commit comments

Comments
 (0)