33// See LICENSE.TXT
44// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
6+ #include " helpers.h"
67#include < uur/fixtures.h>
78
8- struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
9+ struct urUSMSharedAllocTest
10+ : uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
911 void SetUp () override {
1012 UUR_RETURN_ON_FATAL_FAILURE (
11- uur::urQueueTestWithParam<uur::BoolTestParam >::SetUp ());
13+ uur::urQueueTestWithParam<uur::USMDeviceAllocParams >::SetUp ());
1214 ur_device_usm_access_capability_flags_t shared_usm_cross = 0 ;
1315 ur_device_usm_access_capability_flags_t shared_usm_single = 0 ;
1416
@@ -21,7 +23,7 @@ struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
2123 GTEST_SKIP () << " Shared USM is not supported by the device." ;
2224 }
2325
24- if (getParam (). value ) {
26+ if (usePool ) {
2527 ur_usm_pool_desc_t pool_desc = {};
2628 ASSERT_SUCCESS (urUSMPoolCreate (context, &pool_desc, &pool));
2729 }
@@ -32,22 +34,29 @@ struct urUSMSharedAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
3234 ASSERT_SUCCESS (urUSMPoolRelease (pool));
3335 }
3436 UUR_RETURN_ON_FATAL_FAILURE (
35- uur::urQueueTestWithParam<uur::BoolTestParam >::TearDown ());
37+ uur::urQueueTestWithParam<uur::USMDeviceAllocParams >::TearDown ());
3638 }
3739
3840 ur_usm_pool_handle_t pool = nullptr ;
41+ bool usePool = std::get<0 >(getParam()).value;
3942};
4043
44+ // The 0 value parameters are not relevant for urUSMSharedAllocTest tests, they
45+ // are used below in urUSMSharedAllocAlignmentTest for allocation size and
46+ // alignment values
4147UUR_TEST_SUITE_P (
4248 urUSMSharedAllocTest,
43- testing::ValuesIn (uur::BoolTestParam::makeBoolParam(" UsePool" )),
44- uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
49+ testing::Combine (
50+ testing::ValuesIn (uur::BoolTestParam::makeBoolParam(" UsePool" )),
51+ testing::Values(0 ), testing::Values(0 )),
52+ uur::printUSMAllocTestString<urUSMSharedAllocTest>);
4553
4654TEST_P (urUSMSharedAllocTest, Success) {
4755 void *ptr = nullptr ;
4856 size_t allocation_size = sizeof (int );
4957 ASSERT_SUCCESS (urUSMSharedAlloc (context, device, nullptr , pool,
5058 allocation_size, &ptr));
59+ ASSERT_NE (ptr, nullptr );
5160
5261 ur_event_handle_t event = nullptr ;
5362 uint8_t pattern = 0 ;
@@ -60,7 +69,6 @@ TEST_P(urUSMSharedAllocTest, Success) {
6069}
6170
6271TEST_P (urUSMSharedAllocTest, SuccessWithDescriptors) {
63-
6472 ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
6573 nullptr ,
6674 /* device flags */ 0 };
@@ -76,6 +84,7 @@ TEST_P(urUSMSharedAllocTest, SuccessWithDescriptors) {
7684 size_t allocation_size = sizeof (int );
7785 ASSERT_SUCCESS (urUSMSharedAlloc (context, device, &usm_desc, pool,
7886 allocation_size, &ptr));
87+ ASSERT_NE (ptr, nullptr );
7988
8089 ur_event_handle_t event = nullptr ;
8190 uint8_t pattern = 0 ;
@@ -97,6 +106,7 @@ TEST_P(urUSMSharedAllocTest, SuccessWithMultipleAdvices) {
97106 size_t allocation_size = sizeof (int );
98107 ASSERT_SUCCESS (urUSMSharedAlloc (context, device, &usm_desc, pool,
99108 allocation_size, &ptr));
109+ ASSERT_NE (ptr, nullptr );
100110
101111 ur_event_handle_t event = nullptr ;
102112 uint8_t pattern = 0 ;
@@ -144,3 +154,43 @@ TEST_P(urUSMSharedAllocTest, InvalidValueAlignPowerOfTwo) {
144154 UR_RESULT_ERROR_INVALID_VALUE,
145155 urUSMSharedAlloc (context, device, &desc, pool, sizeof (int ), &ptr));
146156}
157+
158+ using urUSMSharedAllocAlignmentTest = urUSMSharedAllocTest;
159+
160+ UUR_TEST_SUITE_P (
161+ urUSMSharedAllocAlignmentTest,
162+ testing::Combine (
163+ testing::ValuesIn (uur::BoolTestParam::makeBoolParam(" UsePool" )),
164+ testing::Values(4 , 8 , 16 , 32 , 64 ), testing::Values(8 , 512 , 2048 )),
165+ uur::printUSMAllocTestString<urUSMSharedAllocAlignmentTest>);
166+
167+ TEST_P (urUSMSharedAllocAlignmentTest, SuccessAlignedAllocations) {
168+ uint32_t alignment = std::get<1 >(getParam ());
169+ size_t allocation_size = std::get<2 >(getParam ());
170+
171+ ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
172+ nullptr ,
173+ /* device flags */ 0 };
174+
175+ ur_usm_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC,
176+ &usm_device_desc,
177+ /* host flags */ 0 };
178+
179+ ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_host_desc,
180+ /* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
181+ alignment};
182+
183+ void *ptr = nullptr ;
184+ ASSERT_SUCCESS (urUSMSharedAlloc (context, device, &usm_desc, pool,
185+ allocation_size, &ptr));
186+ ASSERT_NE (ptr, nullptr );
187+
188+ ur_event_handle_t event = nullptr ;
189+ uint8_t pattern = 0 ;
190+ ASSERT_SUCCESS (urEnqueueUSMFill (queue, ptr, sizeof (pattern), &pattern,
191+ allocation_size, 0 , nullptr , &event));
192+ ASSERT_SUCCESS (urEventWait (1 , &event));
193+
194+ ASSERT_SUCCESS (urUSMFree (context, ptr));
195+ EXPECT_SUCCESS (urEventRelease (event));
196+ }
0 commit comments