Skip to content

Commit 0c11a74

Browse files
authored
Merge pull request #2642 from martygrant/martin/usm-cts-spec-gap
Improvements to align CTS and Spec for USM
2 parents 9d6542b + ee8efc4 commit 0c11a74

File tree

5 files changed

+244
-196
lines changed

5 files changed

+244
-196
lines changed

test/conformance/usm/helpers.h

+63-14
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,82 @@
1111

1212
namespace uur {
1313

14-
using USMDeviceAllocParams = std::tuple<uur::BoolTestParam, uint32_t, size_t>;
14+
using USMAllocTestParams =
15+
std::tuple<uur::BoolTestParam, uint32_t, size_t, ur_usm_advice_flags_t>;
16+
17+
struct urUSMAllocTest : uur::urQueueTestWithParam<uur::USMAllocTestParams> {
18+
void SetUp() override {
19+
UUR_RETURN_ON_FATAL_FAILURE(
20+
uur::urQueueTestWithParam<uur::USMAllocTestParams>::SetUp());
21+
if (usePool) {
22+
ur_bool_t poolSupport = false;
23+
ASSERT_SUCCESS(uur::GetDeviceUSMPoolSupport(device, poolSupport));
24+
if (!poolSupport) {
25+
GTEST_SKIP() << "USM pools are not supported.";
26+
}
27+
ur_usm_pool_desc_t pool_desc = {};
28+
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
29+
}
30+
}
31+
32+
void TearDown() override {
33+
if (pool) {
34+
ASSERT_SUCCESS(urUSMPoolRelease(pool));
35+
}
36+
UUR_RETURN_ON_FATAL_FAILURE(
37+
uur::urQueueTestWithParam<uur::USMAllocTestParams>::TearDown());
38+
}
39+
40+
ur_usm_pool_handle_t pool = nullptr;
41+
const bool usePool = std::get<0>(getParam()).value;
42+
ur_device_usm_access_capability_flags_t USMSupport = 0;
43+
const uint32_t alignment = std::get<1>(getParam());
44+
size_t allocation_size = std::get<2>(getParam());
45+
const ur_usm_advice_flags_t advice_flags = std::get<3>(getParam());
46+
void *ptr = nullptr;
47+
};
1548

1649
template <typename T>
1750
inline std::string printUSMAllocTestString(
1851
const testing::TestParamInfo<typename T::ParamType> &info) {
19-
// ParamType will be std::tuple<ur_device_handle_t, USMDeviceAllocParams>
52+
// ParamType will be std::tuple<ur_device_handle_t, USMAllocTestParams>
2053
const auto device_handle = std::get<0>(info.param).device;
2154
const auto platform_device_name =
2255
uur::GetPlatformAndDeviceName(device_handle);
23-
const auto &usmDeviceAllocParams = std::get<1>(info.param);
24-
const auto &BoolParam = std::get<0>(usmDeviceAllocParams);
56+
const auto &USMAllocTestParams = std::get<1>(info.param);
57+
const auto &BoolParam = std::get<0>(USMAllocTestParams);
2558

2659
std::stringstream ss;
27-
ss << BoolParam.name << (BoolParam.value ? "Enabled" : "Disabled");
28-
29-
const auto alignment = std::get<1>(usmDeviceAllocParams);
30-
const auto size = std::get<2>(usmDeviceAllocParams);
31-
if (alignment && size > 0) {
32-
ss << "_";
33-
ss << std::get<1>(usmDeviceAllocParams);
34-
ss << "_";
35-
ss << std::get<2>(usmDeviceAllocParams);
36-
}
60+
ss << BoolParam.name << (BoolParam.value ? "Enabled" : "Disabled"); // UsePool
61+
ss << "_";
62+
ss << std::get<1>(USMAllocTestParams); // alignment
63+
ss << "_";
64+
ss << std::get<2>(USMAllocTestParams); // size
65+
ss << "_";
66+
ss << std::get<3>(USMAllocTestParams); // ur_usm_advice_flags_t
3767

3868
return platform_device_name + "__" + ss.str();
3969
}
4070

71+
static std::vector<ur_usm_advice_flags_t> usm_alloc_test_parameters{
72+
UR_USM_ADVICE_FLAG_DEFAULT,
73+
UR_USM_ADVICE_FLAG_SET_READ_MOSTLY,
74+
UR_USM_ADVICE_FLAG_CLEAR_READ_MOSTLY,
75+
UR_USM_ADVICE_FLAG_SET_PREFERRED_LOCATION,
76+
UR_USM_ADVICE_FLAG_CLEAR_PREFERRED_LOCATION,
77+
UR_USM_ADVICE_FLAG_SET_NON_ATOMIC_MOSTLY,
78+
UR_USM_ADVICE_FLAG_CLEAR_NON_ATOMIC_MOSTLY,
79+
UR_USM_ADVICE_FLAG_BIAS_CACHED,
80+
UR_USM_ADVICE_FLAG_BIAS_UNCACHED,
81+
UR_USM_ADVICE_FLAG_SET_ACCESSED_BY_DEVICE,
82+
UR_USM_ADVICE_FLAG_CLEAR_ACCESSED_BY_DEVICE,
83+
UR_USM_ADVICE_FLAG_SET_ACCESSED_BY_HOST,
84+
UR_USM_ADVICE_FLAG_CLEAR_ACCESSED_BY_HOST,
85+
UR_USM_ADVICE_FLAG_SET_PREFERRED_LOCATION_HOST,
86+
UR_USM_ADVICE_FLAG_CLEAR_PREFERRED_LOCATION_HOST,
87+
UR_USM_ADVICE_FLAG_SET_NON_COHERENT_MEMORY,
88+
UR_USM_ADVICE_FLAG_CLEAR_NON_COHERENT_MEMORY};
89+
4190
} // namespace uur
4291

4392
#endif // UUR_ENQUEUE_RECT_HELPERS_H_INCLUDED

test/conformance/usm/urUSMDeviceAlloc.cpp

+47-56
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,18 @@
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

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

7552
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};
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

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

10782
TEST_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+
139134
using urUSMDeviceAllocAlignmentTest = urUSMDeviceAllocTest;
140135

141136
UUR_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

148144
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};
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

Comments
 (0)