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