55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66#include " helpers.h"
77#include " uur/utils.h"
8+ #include < limits>
89#include < uur/fixtures.h>
910#include < uur/known_failure.h>
1011
11- struct urUSMDeviceAllocTest
12- : uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
12+ struct urUSMDeviceAllocTest : uur::urUSMAllocTest {
1313 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) {
1917 GTEST_SKIP () << " Device USM is not supported." ;
2018 }
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 ());
3919 }
40-
41- ur_usm_pool_handle_t pool = nullptr ;
42- bool usePool = std::get<0 >(getParam()).value;
4320};
4421
4522// The 0 value parameters are not relevant for urUSMDeviceAllocTest tests, they
@@ -49,14 +26,14 @@ UUR_DEVICE_TEST_SUITE_WITH_PARAM(
4926 urUSMDeviceAllocTest,
5027 testing::Combine (
5128 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)),
5331 uur::printUSMAllocTestString<urUSMDeviceAllocTest>);
5432
5533TEST_P (urUSMDeviceAllocTest, Success) {
5634 UUR_KNOWN_FAILURE_ON (uur::NativeCPU{});
5735
58- void *ptr = nullptr ;
59- size_t allocation_size = sizeof (int );
36+ allocation_size = sizeof (int );
6037 ASSERT_SUCCESS (
6138 urUSMDeviceAlloc (context, device, nullptr , pool, allocation_size, &ptr));
6239 ASSERT_NE (ptr, nullptr );
@@ -73,16 +50,15 @@ TEST_P(urUSMDeviceAllocTest, Success) {
7350}
7451
7552TEST_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};
7659
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 );
8061
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 );
8662 ASSERT_SUCCESS (urUSMDeviceAlloc (context, device, &usm_desc, pool,
8763 allocation_size, &ptr));
8864 ASSERT_NE (ptr, nullptr );
@@ -98,14 +74,12 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
9874}
9975
10076TEST_P (urUSMDeviceAllocTest, InvalidNullHandleContext) {
101- void *ptr = nullptr ;
10277 ASSERT_EQ_RESULT (
10378 UR_RESULT_ERROR_INVALID_NULL_HANDLE,
10479 urUSMDeviceAlloc (nullptr , device, nullptr , pool, sizeof (int ), &ptr));
10580}
10681
10782TEST_P (urUSMDeviceAllocTest, InvalidNullHandleDevice) {
108- void *ptr = nullptr ;
10983 ASSERT_EQ_RESULT (
11084 UR_RESULT_ERROR_INVALID_NULL_HANDLE,
11185 urUSMDeviceAlloc (context, nullptr , nullptr , pool, sizeof (int ), &ptr));
@@ -121,43 +95,60 @@ TEST_P(urUSMDeviceAllocTest, InvalidUSMSize) {
12195 UUR_KNOWN_FAILURE_ON (uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
12296 uur::NativeCPU{});
12397
124- void *ptr = nullptr ;
12598 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
127105}
128106
129- TEST_P (urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
130- void *ptr = nullptr ;
107+ TEST_P (urUSMDeviceAllocTest, InvalidValue) {
131108 ur_usm_desc_t desc = {};
132109 desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
133110 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 ();
134118 ASSERT_EQ_RESULT (
135119 UR_RESULT_ERROR_INVALID_VALUE,
136120 urUSMDeviceAlloc (context, device, &desc, pool, sizeof (int ), &ptr));
137121}
138122
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+
139134using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;
140135
141136UUR_DEVICE_TEST_SUITE_WITH_PARAM (
142137 urUSMDeviceAllocAlignmentTest,
143138 testing::Combine (
144139 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)),
146142 uur::printUSMAllocTestString<urUSMDeviceAllocAlignmentTest>);
147143
148144TEST_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 };
155148
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};
159151
160- void *ptr = nullptr ;
161152 ASSERT_SUCCESS (urUSMDeviceAlloc (context, device, &usm_desc, pool,
162153 allocation_size, &ptr));
163154 ASSERT_NE (ptr, nullptr );
0 commit comments