forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurPlatformCreateWithNativeHandle.cpp
70 lines (59 loc) · 2.95 KB
/
urPlatformCreateWithNativeHandle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2022-2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>
struct urPlatformCreateWithNativeHandleTest : uur::urPlatformTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(uur::urPlatformTest::SetUp());
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_ADAPTER,
sizeof(ur_adapter_handle_t), &adapter,
nullptr));
}
ur_adapter_handle_t adapter = nullptr;
};
UUR_INSTANTIATE_PLATFORM_TEST_SUITE(urPlatformCreateWithNativeHandleTest);
TEST_P(urPlatformCreateWithNativeHandleTest, Success) {
ur_native_handle_t native_handle = 0;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformGetNativeHandle(platform, &native_handle));
// We cannot assume anything about a native_handle, not even if it's
// `nullptr` since this could be a valid representation within a backend.
// We can however convert the native_handle back into a unified-runtime
// handle and perform some query on it to verify that it works.
ur_platform_handle_t plat = nullptr;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformCreateWithNativeHandle(native_handle, adapter, nullptr, &plat));
ASSERT_NE(plat, nullptr);
std::string input_platform_name = uur::GetPlatformName(platform);
std::string created_platform_name = uur::GetPlatformName(plat);
ASSERT_EQ(input_platform_name, created_platform_name);
}
TEST_P(urPlatformCreateWithNativeHandleTest,
SuccessWithExplicitUnOwnedNativeHandle) {
ur_native_handle_t native_handle = 0;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformGetNativeHandle(platform, &native_handle));
// We cannot assume anything about a native_handle, not even if it's
// `nullptr` since this could be a valid representation within a backend.
// We can however convert the native_handle back into a unified-runtime
// handle and perform some query on it to verify that it works.
ur_platform_native_properties_t props = {
nullptr, UR_STRUCTURE_TYPE_PLATFORM_NATIVE_PROPERTIES, false};
ur_platform_handle_t plat = nullptr;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformCreateWithNativeHandle(native_handle, adapter, &props, &plat));
ASSERT_NE(plat, nullptr);
std::string input_platform_name = uur::GetPlatformName(platform);
std::string created_platform_name = uur::GetPlatformName(plat);
ASSERT_EQ(input_platform_name, created_platform_name);
}
TEST_P(urPlatformCreateWithNativeHandleTest, InvalidNullPointerPlatform) {
ur_native_handle_t native_handle = 0;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urPlatformGetNativeHandle(platform, &native_handle));
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urPlatformCreateWithNativeHandle(native_handle, adapter,
nullptr, nullptr));
}