Skip to content

Commit befdc7c

Browse files
authored
Merge pull request oneapi-src#1482 from oneapi-src/martin/alignedUSMAllocationsCTS
[CTS] Add new urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations test
2 parents 065bf2d + db31783 commit befdc7c

8 files changed

+383
-23
lines changed

test/conformance/enqueue/helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ print2DTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
7373
const auto platform_device_name =
7474
uur::GetPlatformAndDeviceName(device_handle);
7575
std::stringstream test_name;
76-
auto src_kind = std::get<1>(std::get<1>(info.param));
77-
auto dst_kind = std::get<2>(std::get<1>(info.param));
76+
const auto src_kind = std::get<1>(std::get<1>(info.param));
77+
const auto dst_kind = std::get<2>(std::get<1>(info.param));
7878
test_name << platform_device_name << "__pitch__"
7979
<< std::get<0>(std::get<1>(info.param)).pitch << "__width__"
8080
<< std::get<0>(std::get<1>(info.param)).width << "__height__"

test/conformance/usm/helpers.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 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+
#ifndef UUR_USM_HELPERS_H_INCLUDED
7+
#define UUR_USM_HELPERS_H_INCLUDED
8+
9+
#include <uur/fixtures.h>
10+
11+
namespace uur {
12+
13+
using USMDeviceAllocParams = std::tuple<uur::BoolTestParam, uint32_t, size_t>;
14+
15+
template <typename T>
16+
inline std::string printUSMAllocTestString(
17+
const testing::TestParamInfo<typename T::ParamType> &info) {
18+
// ParamType will be std::tuple<ur_device_handle_t, USMDeviceAllocParams>
19+
const auto device_handle = std::get<0>(info.param);
20+
const auto platform_device_name =
21+
uur::GetPlatformAndDeviceName(device_handle);
22+
const auto usmDeviceAllocParams = std::get<1>(info.param);
23+
const auto BoolParam = std::get<0>(usmDeviceAllocParams);
24+
25+
std::stringstream ss;
26+
ss << BoolParam.name << (BoolParam.value ? "Enabled" : "Disabled");
27+
28+
const auto alignment = std::get<1>(usmDeviceAllocParams);
29+
const auto size = std::get<2>(usmDeviceAllocParams);
30+
if (alignment && size > 0) {
31+
ss << "_";
32+
ss << std::get<1>(usmDeviceAllocParams);
33+
ss << "_";
34+
ss << std::get<2>(usmDeviceAllocParams);
35+
}
36+
37+
return platform_device_name + "__" + ss.str();
38+
}
39+
40+
} // namespace uur
41+
42+
#endif // UUR_ENQUEUE_RECT_HELPERS_H_INCLUDED

test/conformance/usm/urUSMDeviceAlloc.cpp

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5-
5+
#include "helpers.h"
66
#include <uur/fixtures.h>
77

8-
struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
8+
struct urUSMDeviceAllocTest
9+
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
910
void SetUp() override {
1011
UUR_RETURN_ON_FATAL_FAILURE(
11-
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
12+
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp());
1213
ur_device_usm_access_capability_flags_t deviceUSMSupport = 0;
1314
ASSERT_SUCCESS(
1415
uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport));
1516
if (!deviceUSMSupport) {
1617
GTEST_SKIP() << "Device USM is not supported.";
1718
}
1819

19-
if (getParam().value) {
20+
if (usePool) {
2021
ur_usm_pool_desc_t pool_desc = {};
2122
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
2223
}
@@ -27,16 +28,22 @@ struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
2728
ASSERT_SUCCESS(urUSMPoolRelease(pool));
2829
}
2930
UUR_RETURN_ON_FATAL_FAILURE(
30-
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
31+
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::TearDown());
3132
}
3233

3334
ur_usm_pool_handle_t pool = nullptr;
35+
bool usePool = std::get<0>(getParam()).value;
3436
};
3537

38+
// The 0 value parameters are not relevant for urUSMDeviceAllocTest tests, they
39+
// are used below in urUSMDeviceAllocAlignmentTest for allocation size and
40+
// alignment values
3641
UUR_TEST_SUITE_P(
3742
urUSMDeviceAllocTest,
38-
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
39-
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
43+
testing::Combine(
44+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
45+
testing::Values(0), testing::Values(0)),
46+
uur::printUSMAllocTestString<urUSMDeviceAllocTest>);
4047

4148
TEST_P(urUSMDeviceAllocTest, Success) {
4249
void *ptr = nullptr;
@@ -69,6 +76,7 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
6976
size_t allocation_size = sizeof(int);
7077
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
7178
allocation_size, &ptr));
79+
ASSERT_NE(ptr, nullptr);
7280

7381
ur_event_handle_t event = nullptr;
7482
uint8_t pattern = 0;
@@ -116,3 +124,39 @@ TEST_P(urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
116124
UR_RESULT_ERROR_INVALID_VALUE,
117125
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));
118126
}
127+
128+
using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;
129+
130+
UUR_TEST_SUITE_P(
131+
urUSMDeviceAllocAlignmentTest,
132+
testing::Combine(
133+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
134+
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048)),
135+
uur::printUSMAllocTestString<urUSMDeviceAllocAlignmentTest>);
136+
137+
TEST_P(urUSMDeviceAllocAlignmentTest, SuccessAlignedAllocations) {
138+
uint32_t alignment = std::get<1>(getParam());
139+
size_t allocation_size = std::get<2>(getParam());
140+
141+
ur_usm_device_desc_t usm_device_desc{UR_STRUCTURE_TYPE_USM_DEVICE_DESC,
142+
nullptr,
143+
/* device flags */ 0};
144+
145+
ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_device_desc,
146+
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
147+
alignment};
148+
149+
void *ptr = nullptr;
150+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
151+
allocation_size, &ptr));
152+
ASSERT_NE(ptr, nullptr);
153+
154+
ur_event_handle_t event = nullptr;
155+
uint8_t pattern = 0;
156+
ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern,
157+
allocation_size, 0, nullptr, &event));
158+
ASSERT_SUCCESS(urEventWait(1, &event));
159+
160+
ASSERT_SUCCESS(urUSMFree(context, ptr));
161+
EXPECT_SUCCESS(urEventRelease(event));
162+
}

test/conformance/usm/urUSMHostAlloc.cpp

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
#include "helpers.h"
67
#include <cstring>
78
#include <uur/fixtures.h>
89

9-
struct urUSMHostAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
10+
struct urUSMHostAllocTest
11+
: uur::urQueueTestWithParam<uur::USMDeviceAllocParams> {
1012
void SetUp() override {
1113
UUR_RETURN_ON_FATAL_FAILURE(
12-
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
14+
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::SetUp());
1315
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
1416
ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport));
1517
if (!hostUSMSupport) {
1618
GTEST_SKIP() << "Device USM is not supported.";
1719
}
18-
if (getParam().value) {
20+
21+
if (usePool) {
1922
ur_usm_pool_desc_t pool_desc = {};
2023
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
2124
}
@@ -26,16 +29,22 @@ struct urUSMHostAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
2629
ASSERT_SUCCESS(urUSMPoolRelease(pool));
2730
}
2831
UUR_RETURN_ON_FATAL_FAILURE(
29-
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
32+
uur::urQueueTestWithParam<uur::USMDeviceAllocParams>::TearDown());
3033
}
3134

3235
ur_usm_pool_handle_t pool = nullptr;
36+
bool usePool = std::get<0>(getParam()).value;
3337
};
3438

39+
// The 0 value parameters are not relevant for urUSMHostAllocTest tests, they
40+
// are used below in urUSMHostAllocAlignmentTest for allocation size and
41+
// alignment values
3542
UUR_TEST_SUITE_P(
3643
urUSMHostAllocTest,
37-
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
38-
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
44+
testing::Combine(
45+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
46+
testing::Values(0), testing::Values(0)),
47+
uur::printUSMAllocTestString<urUSMHostAllocTest>);
3948

4049
TEST_P(urUSMHostAllocTest, Success) {
4150
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
@@ -77,7 +86,6 @@ TEST_P(urUSMHostAllocTest, Success) {
7786
}
7887

7988
TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {
80-
8189
ur_usm_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC, nullptr,
8290
/* host flags */ 0};
8391

@@ -88,6 +96,7 @@ TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {
8896
size_t allocation_size = sizeof(int);
8997
ASSERT_SUCCESS(
9098
urUSMHostAlloc(context, &usm_desc, pool, allocation_size, &ptr));
99+
ASSERT_NE(ptr, nullptr);
91100

92101
ur_event_handle_t event = nullptr;
93102
uint8_t pattern = 0;
@@ -125,3 +134,38 @@ TEST_P(urUSMHostAllocTest, InvalidValueAlignPowerOfTwo) {
125134
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
126135
urUSMHostAlloc(context, &desc, pool, sizeof(int), &ptr));
127136
}
137+
138+
using urUSMHostAllocAlignmentTest = urUSMHostAllocTest;
139+
140+
UUR_TEST_SUITE_P(
141+
urUSMHostAllocAlignmentTest,
142+
testing::Combine(
143+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
144+
testing::Values(4, 8, 16, 32, 64), testing::Values(8, 512, 2048)),
145+
uur::printUSMAllocTestString<urUSMHostAllocAlignmentTest>);
146+
147+
TEST_P(urUSMHostAllocAlignmentTest, SuccessAlignedAllocations) {
148+
uint32_t alignment = std::get<1>(getParam());
149+
size_t allocation_size = std::get<2>(getParam());
150+
151+
ur_usm_host_desc_t usm_host_desc{UR_STRUCTURE_TYPE_USM_HOST_DESC, nullptr,
152+
/* host flags */ 0};
153+
154+
ur_usm_desc_t usm_desc{UR_STRUCTURE_TYPE_USM_DESC, &usm_host_desc,
155+
/* mem advice flags */ UR_USM_ADVICE_FLAG_DEFAULT,
156+
alignment};
157+
158+
void *ptr = nullptr;
159+
ASSERT_SUCCESS(
160+
urUSMHostAlloc(context, &usm_desc, pool, allocation_size, &ptr));
161+
ASSERT_NE(ptr, nullptr);
162+
163+
ur_event_handle_t event = nullptr;
164+
uint8_t pattern = 0;
165+
ASSERT_SUCCESS(urEnqueueUSMFill(queue, ptr, sizeof(pattern), &pattern,
166+
allocation_size, 0, nullptr, &event));
167+
ASSERT_SUCCESS(urEventWait(1, &event));
168+
169+
ASSERT_SUCCESS(urUSMFree(context, ptr));
170+
EXPECT_SUCCESS(urEventRelease(event));
171+
}

test/conformance/usm/urUSMSharedAlloc.cpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
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
4147
UUR_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

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

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

Comments
 (0)