Skip to content

Commit a898ec9

Browse files
authored
Merge pull request #768 from aarongreig/aaron/testUSMPools
Add parameterization to USM alloc tests for testing pools.
2 parents 5f37401 + 3985551 commit a898ec9

File tree

8 files changed

+173
-53
lines changed

8 files changed

+173
-53
lines changed

test/conformance/testing/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
add_ur_library(ur_testing STATIC
7-
source/utils.cpp)
7+
source/utils.cpp
8+
source/fixtures.cpp)
89
target_include_directories(ur_testing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
9-
target_link_libraries(ur_testing PRIVATE gtest_main unified-runtime::headers)
10+
target_link_libraries(ur_testing PRIVATE
11+
gtest_main
12+
${PROJECT_NAME}::common
13+
${PROJECT_NAME}::headers)
1014
add_library(${PROJECT_NAME}::testing ALIAS ur_testing)

test/conformance/testing/include/uur/fixtures.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ struct urUSMPoolTest : urContextTest {
634634
void SetUp() override {
635635
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());
636636
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr,
637-
UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK};
637+
0};
638638
ASSERT_SUCCESS(urUSMPoolCreate(this->context, &pool_desc, &pool));
639639
}
640640

@@ -645,15 +645,14 @@ struct urUSMPoolTest : urContextTest {
645645
UUR_RETURN_ON_FATAL_FAILURE(urContextTest::TearDown());
646646
}
647647

648-
ur_usm_pool_handle_t pool;
648+
ur_usm_pool_handle_t pool = nullptr;
649649
};
650650

651651
template <class T> struct urUSMPoolTestWithParam : urContextTestWithParam<T> {
652652
void SetUp() override {
653653
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
654654
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr,
655-
UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK};
656-
ur_usm_pool_handle_t pool = nullptr;
655+
0};
657656
ASSERT_SUCCESS(urUSMPoolCreate(this->context, &pool_desc, &pool));
658657
}
659658

@@ -664,7 +663,7 @@ template <class T> struct urUSMPoolTestWithParam : urContextTestWithParam<T> {
664663
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::TearDown());
665664
}
666665

667-
ur_usm_pool_handle_t pool;
666+
ur_usm_pool_handle_t pool = nullptr;
668667
};
669668

670669
struct urVirtualMemGranularityTest : urContextTest {
@@ -841,8 +840,12 @@ struct urUSMDeviceAllocTestWithParam : urQueueTestWithParam<T> {
841840
if (!device_usm) {
842841
GTEST_SKIP() << "Device USM in not supported";
843842
}
843+
if (use_pool) {
844+
ur_usm_pool_desc_t pool_desc = {};
845+
ASSERT_SUCCESS(urUSMPoolCreate(this->context, &pool_desc, &pool));
846+
}
844847
ASSERT_SUCCESS(urUSMDeviceAlloc(this->context, this->device, nullptr,
845-
nullptr, allocation_size, &ptr));
848+
pool, allocation_size, &ptr));
846849
ur_event_handle_t event = nullptr;
847850

848851
uint8_t fillPattern = 0;
@@ -857,11 +860,17 @@ struct urUSMDeviceAllocTestWithParam : urQueueTestWithParam<T> {
857860

858861
void TearDown() override {
859862
ASSERT_SUCCESS(urUSMFree(this->context, ptr));
863+
if (pool) {
864+
ASSERT_TRUE(use_pool);
865+
ASSERT_SUCCESS(urUSMPoolRelease(pool));
866+
}
860867
uur::urQueueTestWithParam<T>::TearDown();
861868
}
862869

863870
size_t allocation_size = sizeof(int);
864871
void *ptr = nullptr;
872+
bool use_pool = false;
873+
ur_usm_pool_handle_t pool = nullptr;
865874
};
866875

867876
/// @brief
@@ -879,6 +888,22 @@ std::string deviceTestWithParamPrinter(
879888
return uur::GetPlatformAndDeviceName(device) + "__" + ss.str();
880889
}
881890

891+
// Helper struct to allow bool param tests with meaningful names.
892+
struct BoolTestParam {
893+
std::string name;
894+
bool value;
895+
896+
// For use with testing::ValuesIn to generate the param values.
897+
static std::vector<BoolTestParam> makeBoolParam(std::string name) {
898+
return std::vector<BoolTestParam>({{name, true}, {name, false}});
899+
}
900+
};
901+
902+
template <>
903+
std::string deviceTestWithParamPrinter<BoolTestParam>(
904+
const ::testing::TestParamInfo<
905+
std::tuple<ur_device_handle_t, BoolTestParam>> &info);
906+
882907
struct urProgramTest : urQueueTest {
883908
void SetUp() override {
884909
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp());
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2023 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+
#include "uur/fixtures.h"
7+
8+
namespace uur {
9+
template <>
10+
std::string deviceTestWithParamPrinter<BoolTestParam>(
11+
const ::testing::TestParamInfo<
12+
std::tuple<ur_device_handle_t, BoolTestParam>> &info) {
13+
auto device = std::get<0>(info.param);
14+
auto param = std::get<1>(info.param);
15+
16+
std::stringstream ss;
17+
ss << param.name << (param.value ? "Enabled" : "Disabled");
18+
return uur::GetPlatformAndDeviceName(device) + "__" + ss.str();
19+
}
20+
} // namespace uur

test/conformance/usm/urUSMDeviceAlloc.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,43 @@
55

66
#include <uur/fixtures.h>
77

8-
struct urUSMDeviceAllocTest : uur::urQueueTest {
8+
struct urUSMDeviceAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
99
void SetUp() override {
10-
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTest::SetUp());
10+
UUR_RETURN_ON_FATAL_FAILURE(
11+
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
1112
ur_device_usm_access_capability_flags_t deviceUSMSupport = 0;
1213
ASSERT_SUCCESS(
1314
uur::GetDeviceUSMDeviceSupport(device, deviceUSMSupport));
1415
if (!deviceUSMSupport) {
1516
GTEST_SKIP() << "Device USM is not supported.";
1617
}
18+
19+
if (getParam().value) {
20+
ur_usm_pool_desc_t pool_desc = {};
21+
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
22+
}
23+
}
24+
25+
void TearDown() override {
26+
if (pool) {
27+
ASSERT_SUCCESS(urUSMPoolRelease(pool));
28+
}
29+
UUR_RETURN_ON_FATAL_FAILURE(
30+
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
1731
}
32+
33+
ur_usm_pool_handle_t pool = nullptr;
1834
};
19-
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMDeviceAllocTest);
35+
36+
UUR_TEST_SUITE_P(
37+
urUSMDeviceAllocTest,
38+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
39+
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
2040

2141
TEST_P(urUSMDeviceAllocTest, Success) {
2242
void *ptr = nullptr;
2343
size_t allocation_size = sizeof(int);
24-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
44+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, pool,
2545
allocation_size, &ptr));
2646
ASSERT_NE(ptr, nullptr);
2747

@@ -47,7 +67,7 @@ TEST_P(urUSMDeviceAllocTest, SuccessWithDescriptors) {
4767
/* alignment */ 0};
4868
void *ptr = nullptr;
4969
size_t allocation_size = sizeof(int);
50-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, nullptr,
70+
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, &usm_desc, pool,
5171
allocation_size, &ptr));
5272

5373
ur_event_handle_t event = nullptr;
@@ -64,27 +84,27 @@ TEST_P(urUSMDeviceAllocTest, InvalidNullHandleContext) {
6484
void *ptr = nullptr;
6585
ASSERT_EQ_RESULT(
6686
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
67-
urUSMDeviceAlloc(nullptr, device, nullptr, nullptr, sizeof(int), &ptr));
87+
urUSMDeviceAlloc(nullptr, device, nullptr, pool, sizeof(int), &ptr));
6888
}
6989

7090
TEST_P(urUSMDeviceAllocTest, InvalidNullHandleDevice) {
7191
void *ptr = nullptr;
72-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
73-
urUSMDeviceAlloc(context, nullptr, nullptr, nullptr,
74-
sizeof(int), &ptr));
92+
ASSERT_EQ_RESULT(
93+
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
94+
urUSMDeviceAlloc(context, nullptr, nullptr, pool, sizeof(int), &ptr));
7595
}
7696

7797
TEST_P(urUSMDeviceAllocTest, InvalidNullPtrResult) {
78-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
79-
urUSMDeviceAlloc(context, device, nullptr, nullptr,
80-
sizeof(int), nullptr));
98+
ASSERT_EQ_RESULT(
99+
UR_RESULT_ERROR_INVALID_NULL_POINTER,
100+
urUSMDeviceAlloc(context, device, nullptr, pool, sizeof(int), nullptr));
81101
}
82102

83103
TEST_P(urUSMDeviceAllocTest, InvalidUSMSize) {
84104
void *ptr = nullptr;
85105
ASSERT_EQ_RESULT(
86106
UR_RESULT_ERROR_INVALID_USM_SIZE,
87-
urUSMDeviceAlloc(context, device, nullptr, nullptr, -1, &ptr));
107+
urUSMDeviceAlloc(context, device, nullptr, pool, -1, &ptr));
88108
}
89109

90110
TEST_P(urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
@@ -94,5 +114,5 @@ TEST_P(urUSMDeviceAllocTest, InvalidValueAlignPowerOfTwo) {
94114
desc.align = 5;
95115
ASSERT_EQ_RESULT(
96116
UR_RESULT_ERROR_INVALID_VALUE,
97-
urUSMDeviceAlloc(context, device, &desc, nullptr, sizeof(int), &ptr));
117+
urUSMDeviceAlloc(context, device, &desc, pool, sizeof(int), &ptr));
98118
}

test/conformance/usm/urUSMGetMemAllocInfo.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
#include <map>
77
#include <uur/fixtures.h>
88

9-
using urUSMAllocInfoTest =
10-
uur::urUSMDeviceAllocTestWithParam<ur_usm_alloc_info_t>;
9+
struct urUSMAllocInfoTest
10+
: uur::urUSMDeviceAllocTestWithParam<ur_usm_alloc_info_t> {
11+
void SetUp() override {
12+
use_pool = getParam() == UR_USM_ALLOC_INFO_POOL;
13+
UUR_RETURN_ON_FATAL_FAILURE(
14+
uur::urUSMDeviceAllocTestWithParam<ur_usm_alloc_info_t>::SetUp());
15+
}
16+
};
1117

1218
UUR_TEST_SUITE_P(urUSMAllocInfoTest,
1319
::testing::Values(UR_USM_ALLOC_INFO_TYPE,
@@ -71,7 +77,7 @@ TEST_P(urUSMGetMemAllocInfoTest, InvalidEnumeration) {
7177

7278
TEST_P(urUSMGetMemAllocInfoTest, InvalidValuePropSize) {
7379
ur_usm_type_t USMType;
74-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
80+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
7581
urUSMGetMemAllocInfo(context, ptr, UR_USM_ALLOC_INFO_TYPE,
7682
sizeof(ur_usm_type_t) - 1, &USMType,
7783
nullptr));

test/conformance/usm/urUSMHostAlloc.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,36 @@
66
#include <cstring>
77
#include <uur/fixtures.h>
88

9-
struct urUSMHostAllocTest : uur::urQueueTest {
9+
struct urUSMHostAllocTest : uur::urQueueTestWithParam<uur::BoolTestParam> {
1010
void SetUp() override {
11-
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTest::SetUp());
11+
UUR_RETURN_ON_FATAL_FAILURE(
12+
uur::urQueueTestWithParam<uur::BoolTestParam>::SetUp());
1213
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
1314
ASSERT_SUCCESS(uur::GetDeviceUSMHostSupport(device, hostUSMSupport));
1415
if (!hostUSMSupport) {
1516
GTEST_SKIP() << "Device USM is not supported.";
1617
}
18+
if (getParam().value) {
19+
ur_usm_pool_desc_t pool_desc = {};
20+
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
21+
}
22+
}
23+
24+
void TearDown() override {
25+
if (pool) {
26+
ASSERT_SUCCESS(urUSMPoolRelease(pool));
27+
}
28+
UUR_RETURN_ON_FATAL_FAILURE(
29+
uur::urQueueTestWithParam<uur::BoolTestParam>::TearDown());
1730
}
31+
32+
ur_usm_pool_handle_t pool = nullptr;
1833
};
19-
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMHostAllocTest);
34+
35+
UUR_TEST_SUITE_P(
36+
urUSMHostAllocTest,
37+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
38+
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
2039

2140
TEST_P(urUSMHostAllocTest, Success) {
2241
ur_device_usm_access_capability_flags_t hostUSMSupport = 0;
@@ -27,7 +46,7 @@ TEST_P(urUSMHostAllocTest, Success) {
2746

2847
size_t allocation_size = sizeof(int);
2948
int *ptr = nullptr;
30-
ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, nullptr, sizeof(int),
49+
ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, pool, sizeof(int),
3150
reinterpret_cast<void **>(&ptr)));
3251
ASSERT_NE(ptr, nullptr);
3352

@@ -68,7 +87,7 @@ TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {
6887
void *ptr = nullptr;
6988
size_t allocation_size = sizeof(int);
7089
ASSERT_SUCCESS(
71-
urUSMHostAlloc(context, &usm_desc, nullptr, allocation_size, &ptr));
90+
urUSMHostAlloc(context, &usm_desc, pool, allocation_size, &ptr));
7291

7392
ur_event_handle_t event = nullptr;
7493
uint8_t pattern = 0;
@@ -82,29 +101,27 @@ TEST_P(urUSMHostAllocTest, SuccessWithDescriptors) {
82101

83102
TEST_P(urUSMHostAllocTest, InvalidNullHandleContext) {
84103
void *ptr = nullptr;
85-
ASSERT_EQ_RESULT(
86-
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
87-
urUSMHostAlloc(nullptr, nullptr, nullptr, sizeof(int), &ptr));
104+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
105+
urUSMHostAlloc(nullptr, nullptr, pool, sizeof(int), &ptr));
88106
}
89107

90108
TEST_P(urUSMHostAllocTest, InvalidNullPtrMem) {
91109
ASSERT_EQ_RESULT(
92110
UR_RESULT_ERROR_INVALID_NULL_POINTER,
93-
urUSMHostAlloc(context, nullptr, nullptr, sizeof(int), nullptr));
111+
urUSMHostAlloc(context, nullptr, pool, sizeof(int), nullptr));
94112
}
95113

96114
TEST_P(urUSMHostAllocTest, InvalidUSMSize) {
97115
void *ptr = nullptr;
98116
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_USM_SIZE,
99-
urUSMHostAlloc(context, nullptr, nullptr, -1, &ptr));
117+
urUSMHostAlloc(context, nullptr, pool, -1, &ptr));
100118
}
101119

102120
TEST_P(urUSMHostAllocTest, InvalidValueAlignPowerOfTwo) {
103121
void *ptr = nullptr;
104122
ur_usm_desc_t desc = {};
105123
desc.stype = UR_STRUCTURE_TYPE_USM_DESC;
106124
desc.align = 5;
107-
ASSERT_EQ_RESULT(
108-
UR_RESULT_ERROR_INVALID_VALUE,
109-
urUSMHostAlloc(context, &desc, nullptr, sizeof(int), &ptr));
125+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
126+
urUSMHostAlloc(context, &desc, pool, sizeof(int), &ptr));
110127
}

test/conformance/usm/urUSMPoolCreate.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ using urUSMPoolCreateTest = uur::urContextTest;
99
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMPoolCreateTest);
1010

1111
TEST_P(urUSMPoolCreateTest, Success) {
12+
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr, 0};
13+
ur_usm_pool_handle_t pool = nullptr;
14+
ASSERT_SUCCESS(urUSMPoolCreate(context, &pool_desc, &pool));
15+
ASSERT_NE(pool, nullptr);
16+
EXPECT_SUCCESS(urUSMPoolRelease(pool));
17+
}
18+
19+
TEST_P(urUSMPoolCreateTest, SuccessWithFlag) {
1220
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr,
1321
UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK};
1422
ur_usm_pool_handle_t pool = nullptr;

0 commit comments

Comments
 (0)