5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
#include " helpers.h"
7
7
#include " uur/utils.h"
8
+ #include < limits>
8
9
#include < uur/fixtures.h>
9
10
#include < uur/known_failure.h>
10
11
11
- struct urUSMDeviceAllocTest
12
- : uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
12
+ struct urUSMDeviceAllocTest : uur::urUSMAllocTest {
13
13
void SetUp () override {
14
- UUR_RETURN_ON_FATAL_FAILURE (
15
- uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp ());
16
- ur_device_usm_access_capability_flags_t deviceUSMSupport = 0 ;
17
- ASSERT_SUCCESS (uur::GetDeviceUSMDeviceSupport (device, deviceUSMSupport));
18
- if (!deviceUSMSupport) {
14
+ UUR_RETURN_ON_FATAL_FAILURE (uur::urUSMAllocTest::SetUp ());
15
+ ASSERT_SUCCESS (uur::GetDeviceUSMDeviceSupport (device, USMSupport));
16
+ if (!USMSupport) {
19
17
GTEST_SKIP () << " Device USM is not supported." ;
20
18
}
21
-
22
- if (usePool) {
23
- ur_bool_t poolSupport = false ;
24
- ASSERT_SUCCESS (uur::GetDeviceUSMPoolSupport (device, poolSupport));
25
- if (!poolSupport) {
26
- GTEST_SKIP () << " USM pools are not supported." ;
27
- }
28
- ur_usm_pool_desc_t pool_desc = {};
29
- ASSERT_SUCCESS (urUSMPoolCreate (context, &pool_desc, &pool));
30
- }
31
- }
32
-
33
- void TearDown () override {
34
- if (pool) {
35
- ASSERT_SUCCESS (urUSMPoolRelease (pool));
36
- }
37
- UUR_RETURN_ON_FATAL_FAILURE (
38
- uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::TearDown ());
39
19
}
40
-
41
- ur_usm_pool_handle_t pool = nullptr ;
42
- bool usePool = std::get<0 >(getParam()).value;
43
20
};
44
21
45
22
// The 0 value parameters are not relevant for urUSMDeviceAllocTest tests, they
@@ -49,14 +26,14 @@ UUR_DEVICE_TEST_SUITE_WITH_PARAM(
49
26
urUSMDeviceAllocTest,
50
27
testing::Combine (
51
28
testing::ValuesIn (uur::BoolTestParam::makeBoolParam(" UsePool" )),
52
- testing::Values(0 ), testing::Values(0 )),
29
+ testing::Values(0 ), testing::Values(0 ),
30
+ ::testing::ValuesIn(uur::usm_alloc_test_parameters)),
53
31
uur::printUSMAllocTestString<urUSMDeviceAllocTest>);
54
32
55
33
TEST_P (urUSMDeviceAllocTest, Success) {
56
34
UUR_KNOWN_FAILURE_ON (uur::NativeCPU{});
57
35
58
- void *ptr = nullptr ;
59
- size_t allocation_size = sizeof (int );
36
+ allocation_size = sizeof (int );
60
37
ASSERT_SUCCESS (
61
38
urUSMDeviceAlloc (context, device, nullptr , pool, allocation_size, &ptr));
62
39
ASSERT_NE (ptr, nullptr );
@@ -73,16 +50,15 @@ TEST_P(urUSMDeviceAllocTest, Success) {
73
50
}
74
51
75
52
TEST_P (urUSMDeviceAllocTest, SuccessWithDescriptors) {
53
+ const ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
54
+ nullptr ,
55
+ /* device flags */ 0 };
56
+
57
+ const ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
58
+ advice_flags, alignment};
76
59
77
- ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
78
- nullptr ,
79
- /* device flags */ 0 };
60
+ allocation_size = sizeof (int );
80
61
81
- ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
82
- /* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
83
- /* alignment */ 0 };
84
- void *ptr = nullptr ;
85
- size_t allocation_size = sizeof (int );
86
62
ASSERT_SUCCESS (urUSMDeviceAlloc (context, device, &usm_desc, pool,
87
63
allocation_size, &ptr));
88
64
ASSERT_NE (ptr, nullptr );
@@ -98,14 +74,12 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
98
74
}
99
75
100
76
TEST_P (urUSMDeviceAllocTest, InvalidNullHandleContext) {
101
- void *ptr = nullptr ;
102
77
ASSERT_EQ_RESULT (
103
78
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
104
79
urUSMDeviceAlloc (nullptr , device, nullptr , pool, sizeof (int ), &ptr));
105
80
}
106
81
107
82
TEST_P (urUSMDeviceAllocTest, InvalidNullHandleDevice) {
108
- void *ptr = nullptr ;
109
83
ASSERT_EQ_RESULT (
110
84
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
111
85
urUSMDeviceAlloc (context, nullptr , nullptr , pool, sizeof (int ), &ptr));
@@ -121,43 +95,60 @@ TEST_P(urUSMDeviceAllocTest, InvalidUSMSize) {
121
95
UUR_KNOWN_FAILURE_ON (uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
122
96
uur::NativeCPU{});
123
97
124
- void *ptr = nullptr ;
125
98
ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_USM_SIZE,
126
- urUSMDeviceAlloc (context, device, nullptr , pool, -1 , &ptr));
99
+ urUSMDeviceAlloc (context, device, nullptr , pool, 0 , &ptr));
100
+
101
+ // TODO: Producing error X from case "size is greater than
102
+ // UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE" is currently unreliable due to
103
+ // implementation issues for UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE
104
+ // https://github.com/oneapi-src/unified-runtime/issues/2665
127
105
}
128
106
129
- TEST_P (urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
130
- void *ptr = nullptr ;
107
+ TEST_P (urUSMDeviceAllocTest, InvalidValue) {
131
108
ur_usm_desc_t desc = {};
132
109
desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
133
110
desc.align = 5 ;
111
+ desc.pNext = nullptr ;
112
+ desc.hints = UR_USM_ADVICE_FLAG_DEFAULT;
113
+ ASSERT_EQ_RESULT (
114
+ UR_RESULT_ERROR_INVALID_VALUE,
115
+ urUSMDeviceAlloc (context, device, &desc, pool, sizeof (int ), &ptr));
116
+
117
+ desc.align = std::numeric_limits<uint32_t >::max ();
134
118
ASSERT_EQ_RESULT (
135
119
UR_RESULT_ERROR_INVALID_VALUE,
136
120
urUSMDeviceAlloc (context, device, &desc, pool, sizeof (int ), &ptr));
137
121
}
138
122
123
+ TEST_P (urUSMDeviceAllocTest, InvalidEnumeration) {
124
+ ur_usm_desc_t desc = {};
125
+ desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
126
+ desc.align = 5 ;
127
+ desc.pNext = nullptr ;
128
+ desc.hints = UR_USM_ADVICE_FLAG_FORCE_UINT32;
129
+ ASSERT_EQ_RESULT (
130
+ UR_RESULT_ERROR_INVALID_ENUMERATION,
131
+ urUSMDeviceAlloc (context, device, &desc, pool, sizeof (int ), &ptr));
132
+ }
133
+
139
134
using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;
140
135
141
136
UUR_DEVICE_TEST_SUITE_WITH_PARAM (
142
137
urUSMDeviceAllocAlignmentTest,
143
138
testing::Combine (
144
139
testing::ValuesIn (uur::BoolTestParam::makeBoolParam(" UsePool" )),
145
- testing::Values(4 , 8 , 16 , 32 , 64 ), testing::Values(8 , 512 , 2048 )),
140
+ testing::Values(4 , 8 , 16 , 32 , 64 ), testing::Values(8 , 512 , 2048 ),
141
+ testing::ValuesIn(uur::usm_alloc_test_parameters)),
146
142
uur::printUSMAllocTestString<urUSMDeviceAllocAlignmentTest>);
147
143
148
144
TEST_P (urUSMDeviceAllocAlignmentTest, SuccessAlignedAllocations) {
149
- uint32_t alignment = std::get<1 >(getParam ());
150
- size_t allocation_size = std::get<2 >(getParam ());
151
-
152
- ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
153
- nullptr ,
154
- /* device flags */ 0 };
145
+ const ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
146
+ nullptr ,
147
+ /* device flags */ 0 };
155
148
156
- ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
157
- /* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
158
- alignment};
149
+ const ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
150
+ advice_flags, alignment};
159
151
160
- void *ptr = nullptr ;
161
152
ASSERT_SUCCESS (urUSMDeviceAlloc (context, device, &usm_desc, pool,
162
153
allocation_size, &ptr));
163
154
ASSERT_NE (ptr, nullptr );
0 commit comments