Skip to content

Commit e79993d

Browse files
authored
Merge pull request #1233 from callumfare/callum/cts_usm_pt1
[CTS] Add more USM testing
2 parents 858225a + 76d68f1 commit e79993d

File tree

9 files changed

+261
-23
lines changed

9 files changed

+261
-23
lines changed

test/conformance/device_code/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp)
9393
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/image_copy.cpp)
9494
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/mean.cpp)
9595
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/spec_constant.cpp)
96+
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/usm_ll.cpp)
9697

9798
set(KERNEL_HEADER ${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/kernel_entry_points.h)
9899
add_custom_command(OUTPUT ${KERNEL_HEADER}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 <sycl/sycl.hpp>
7+
8+
using namespace sycl;
9+
10+
int numNodes = 4;
11+
12+
struct Node {
13+
Node() : pNext(nullptr), Num(0xDEADBEEF) {}
14+
15+
Node *pNext;
16+
uint32_t Num;
17+
};
18+
19+
int main() {
20+
queue q;
21+
auto dev = q.get_device();
22+
auto ctxt = q.get_context();
23+
24+
if (!dev.get_info<info::device::usm_shared_allocations>()) {
25+
return 0;
26+
}
27+
28+
Node *s_head =
29+
(Node *)aligned_alloc_shared(alignof(Node), sizeof(Node), dev, ctxt);
30+
if (s_head == nullptr) {
31+
return -1;
32+
}
33+
Node *s_cur = s_head;
34+
35+
for (int i = 0; i < numNodes; i++) {
36+
s_cur->Num = i * 2;
37+
38+
if (i != (numNodes - 1)) {
39+
s_cur->pNext = (Node *)aligned_alloc_shared(
40+
alignof(Node), sizeof(Node), dev, ctxt);
41+
} else {
42+
s_cur->pNext = nullptr;
43+
}
44+
45+
s_cur = s_cur->pNext;
46+
}
47+
48+
auto e1 = q.submit([=](handler &cgh) {
49+
cgh.single_task<class linkedlist>([=]() {
50+
Node *pHead = s_head;
51+
while (pHead) {
52+
pHead->Num = pHead->Num * 2 + 1;
53+
pHead = pHead->pNext;
54+
}
55+
});
56+
});
57+
58+
e1.wait();
59+
60+
s_cur = s_head;
61+
for (int i = 0; i < numNodes; i++) {
62+
Node *old = s_cur;
63+
s_cur = s_cur->pNext;
64+
free(old, ctxt);
65+
}
66+
67+
return 0;
68+
}

test/conformance/enqueue/enqueue_adapter_opencl.match

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
{{OPT}}urEnqueueUSMMemcpy2DNegativeTest.InvalidSize/Intel_R__OpenCL___{{.*}}
3434
{{OPT}}urEnqueueUSMMemcpy2DNegativeTest.InvalidEventWaitList/Intel_R__OpenCL___{{.*}}
3535
{{OPT}}urEnqueueUSMPrefetchTest.InvalidSizeTooLarge/Intel_R__OpenCL___{{.*}}
36+
{{OPT}}urEnqueueKernelLaunchUSMLinkedList.Success/Intel_R__OpenCL___{{.*}}_UsePoolEnabled

test/conformance/enqueue/helpers.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,33 @@ struct TestParameters2D {
6666
size_t height;
6767
};
6868

69+
inline std::string USMKindToString(USMKind kind) {
70+
switch (kind) {
71+
case USMKind::Device:
72+
return "Device";
73+
case USMKind::Host:
74+
return "Host";
75+
case USMKind::Shared:
76+
default:
77+
return "Shared";
78+
}
79+
}
80+
6981
template <typename T>
7082
inline std::string
7183
print2DTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
7284
const auto device_handle = std::get<0>(info.param);
7385
const auto platform_device_name =
7486
uur::GetPlatformAndDeviceName(device_handle);
7587
std::stringstream test_name;
88+
auto src_kind = std::get<1>(std::get<1>(info.param));
89+
auto dst_kind = std::get<2>(std::get<1>(info.param));
7690
test_name << platform_device_name << "__pitch__"
77-
<< std::get<1>(info.param).pitch << "__width__"
78-
<< std::get<1>(info.param).width << "__height__"
79-
<< std::get<1>(info.param).height;
91+
<< std::get<0>(std::get<1>(info.param)).pitch << "__width__"
92+
<< std::get<0>(std::get<1>(info.param)).width << "__height__"
93+
<< std::get<0>(std::get<1>(info.param)).height << "__src__"
94+
<< USMKindToString(src_kind) << "__dst__"
95+
<< USMKindToString(dst_kind);
8096
return test_name.str();
8197
}
8298

test/conformance/enqueue/urEnqueueKernelLaunch.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,102 @@ TEST_P(urEnqueueKernelLaunchMultiDeviceTest, KernelLaunchReadDifferentQueues) {
263263
ASSERT_EQ(val, output) << "Result on queue " << i << " did not match!";
264264
}
265265
}
266+
267+
struct urEnqueueKernelLaunchUSMLinkedList
268+
: uur::urKernelTestWithParam<uur::BoolTestParam> {
269+
struct Node {
270+
Node() : next(nullptr), num(0xDEADBEEF) {}
271+
272+
Node *next;
273+
uint32_t num;
274+
};
275+
276+
void SetUp() override {
277+
program_name = "usm_ll";
278+
UUR_RETURN_ON_FATAL_FAILURE(
279+
uur::urKernelTestWithParam<uur::BoolTestParam>::SetUp());
280+
281+
use_pool = getParam().value;
282+
ASSERT_SUCCESS(urQueueCreate(context, device, 0, &queue));
283+
ur_usm_pool_desc_t pool_desc{UR_STRUCTURE_TYPE_USM_POOL_DESC, nullptr,
284+
0};
285+
if (use_pool) {
286+
ASSERT_SUCCESS(urUSMPoolCreate(this->context, &pool_desc, &pool));
287+
}
288+
}
289+
290+
void TearDown() override {
291+
auto *list_cur = list_head;
292+
while (list_cur) {
293+
auto *list_next = list_cur->next;
294+
ASSERT_SUCCESS(urUSMFree(context, list_cur));
295+
list_cur = list_next;
296+
}
297+
298+
if (queue) {
299+
ASSERT_SUCCESS(urQueueRelease(queue));
300+
}
301+
302+
if (pool) {
303+
ASSERT_SUCCESS(urUSMPoolRelease(pool));
304+
}
305+
306+
UUR_RETURN_ON_FATAL_FAILURE(
307+
uur::urKernelTestWithParam<uur::BoolTestParam>::TearDown());
308+
}
309+
310+
size_t global_size = 1;
311+
size_t global_offset = 0;
312+
Node *list_head = nullptr;
313+
const int num_nodes = 4;
314+
bool use_pool = false;
315+
ur_usm_pool_handle_t pool = nullptr;
316+
ur_queue_handle_t queue;
317+
};
318+
319+
UUR_TEST_SUITE_P(
320+
urEnqueueKernelLaunchUSMLinkedList,
321+
testing::ValuesIn(uur::BoolTestParam::makeBoolParam("UsePool")),
322+
uur::deviceTestWithParamPrinter<uur::BoolTestParam>);
323+
324+
TEST_P(urEnqueueKernelLaunchUSMLinkedList, Success) {
325+
ur_device_usm_access_capability_flags_t shared_usm_flags = 0;
326+
ASSERT_SUCCESS(
327+
uur::GetDeviceUSMSingleSharedSupport(device, shared_usm_flags));
328+
if (!(shared_usm_flags & UR_DEVICE_USM_ACCESS_CAPABILITY_FLAG_ACCESS)) {
329+
GTEST_SKIP() << "Shared USM is not supported.";
330+
}
331+
332+
// Build linked list with USM allocations
333+
ASSERT_SUCCESS(urUSMSharedAlloc(context, device, nullptr, pool,
334+
sizeof(Node),
335+
reinterpret_cast<void **>(&list_head)));
336+
ASSERT_NE(list_head, nullptr);
337+
Node *list_cur = list_head;
338+
for (int i = 0; i < num_nodes; i++) {
339+
list_cur->num = i * 2;
340+
if (i < num_nodes - 1) {
341+
ASSERT_SUCCESS(
342+
urUSMSharedAlloc(context, device, nullptr, pool, sizeof(Node),
343+
reinterpret_cast<void **>(&list_cur->next)));
344+
ASSERT_NE(list_cur->next, nullptr);
345+
} else {
346+
list_cur->next = nullptr;
347+
}
348+
list_cur = list_cur->next;
349+
}
350+
351+
// Run kernel which will iterate the list and modify the values
352+
ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, &list_head));
353+
ASSERT_SUCCESS(urEnqueueKernelLaunch(queue, kernel, 1, &global_offset,
354+
&global_size, nullptr, 0, nullptr,
355+
nullptr));
356+
ASSERT_SUCCESS(urQueueFinish(queue));
357+
358+
// Verify values
359+
list_cur = list_head;
360+
for (int i = 0; i < num_nodes; i++) {
361+
ASSERT_EQ(list_cur->num, i * 4 + 1);
362+
list_cur = list_cur->next;
363+
}
364+
}

test/conformance/enqueue/urEnqueueUSMMemcpy2D.cpp

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
#include "helpers.h"
77
#include <uur/fixtures.h>
88

9+
using TestParametersMemcpy2D =
10+
std::tuple<uur::TestParameters2D, uur::USMKind, uur::USMKind>;
11+
912
struct urEnqueueUSMMemcpy2DTestWithParam
10-
: uur::urQueueTestWithParam<uur::TestParameters2D> {
13+
: uur::urQueueTestWithParam<TestParametersMemcpy2D> {
1114
void SetUp() override {
1215
UUR_RETURN_ON_FATAL_FAILURE(
13-
uur::urQueueTestWithParam<uur::TestParameters2D>::SetUp());
16+
uur::urQueueTestWithParam<TestParametersMemcpy2D>::SetUp());
17+
18+
const auto [in2DParams, inSrcKind, inDstKind] = getParam();
19+
std::tie(pitch, width, height, src_kind, dst_kind) =
20+
std::make_tuple(in2DParams.pitch, in2DParams.width,
21+
in2DParams.height, inSrcKind, inDstKind);
22+
1423
ur_device_usm_access_capability_flags_t device_usm = 0;
1524
ASSERT_SUCCESS(uur::GetDeviceUSMDeviceSupport(device, device_usm));
16-
if (!device_usm) {
25+
if (!device_usm && (src_kind == uur::USMKind::Device ||
26+
dst_kind == uur::USMKind::Device)) {
1727
GTEST_SKIP() << "Device USM is not supported";
1828
}
1929

@@ -25,15 +35,13 @@ struct urEnqueueUSMMemcpy2DTestWithParam
2535
GTEST_SKIP() << "2D USM memcpy is not supported";
2636
}
2737

28-
const auto [inPitch, inWidth, inHeight] = getParam();
29-
std::tie(pitch, width, height) =
30-
std::make_tuple(inPitch, inWidth, inHeight);
31-
3238
const size_t num_elements = pitch * height;
33-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
34-
num_elements, &pSrc));
35-
ASSERT_SUCCESS(urUSMDeviceAlloc(context, device, nullptr, nullptr,
36-
num_elements, &pDst));
39+
ASSERT_SUCCESS(uur::MakeUSMAllocationByType(
40+
src_kind, context, device, nullptr, nullptr, num_elements, &pSrc));
41+
42+
ASSERT_SUCCESS(uur::MakeUSMAllocationByType(
43+
dst_kind, context, device, nullptr, nullptr, num_elements, &pDst));
44+
3745
ur_event_handle_t memset_event = nullptr;
3846

3947
ASSERT_SUCCESS(urEnqueueUSMFill(queue, pSrc, sizeof(memset_value),
@@ -52,17 +60,22 @@ struct urEnqueueUSMMemcpy2DTestWithParam
5260
if (pDst) {
5361
ASSERT_SUCCESS(urUSMFree(context, pDst));
5462
}
55-
uur::urQueueTestWithParam<uur::TestParameters2D>::TearDown();
63+
uur::urQueueTestWithParam<TestParametersMemcpy2D>::TearDown();
5664
}
5765

5866
void verifyMemcpySucceeded() {
5967
std::vector<uint8_t> host_mem(pitch * height);
60-
ASSERT_SUCCESS(urEnqueueUSMMemcpy2D(queue, true, host_mem.data(), pitch,
61-
pDst, pitch, width, height, 0,
62-
nullptr, nullptr));
68+
const uint8_t *host_ptr = nullptr;
69+
if (dst_kind == uur::USMKind::Device) {
70+
ASSERT_SUCCESS(urEnqueueUSMMemcpy2D(queue, true, host_mem.data(),
71+
pitch, pDst, pitch, width,
72+
height, 0, nullptr, nullptr));
73+
host_ptr = host_mem.data();
74+
} else {
75+
host_ptr = static_cast<const uint8_t *>(pDst);
76+
}
6377
for (size_t w = 0; w < width; ++w) {
6478
for (size_t h = 0; h < height; ++h) {
65-
const auto *host_ptr = host_mem.data();
6679
const size_t index = (pitch * h) + w;
6780
ASSERT_TRUE(*(host_ptr + index) == memset_value);
6881
}
@@ -75,9 +88,11 @@ struct urEnqueueUSMMemcpy2DTestWithParam
7588
size_t pitch = 0;
7689
size_t width = 0;
7790
size_t height = 0;
91+
uur::USMKind src_kind;
92+
uur::USMKind dst_kind;
7893
};
7994

80-
static std::vector<uur::TestParameters2D> test_cases{
95+
static std::vector<uur::TestParameters2D> test_sizes{
8196
/* Everything set to 1 */
8297
{1, 1, 1},
8398
/* Height == 1 && Pitch > width */
@@ -92,7 +107,13 @@ static std::vector<uur::TestParameters2D> test_cases{
92107
{234, 233, 1}};
93108

94109
UUR_TEST_SUITE_P(urEnqueueUSMMemcpy2DTestWithParam,
95-
::testing::ValuesIn(test_cases),
110+
::testing::Combine(::testing::ValuesIn(test_sizes),
111+
::testing::Values(uur::USMKind::Device,
112+
uur::USMKind::Host,
113+
uur::USMKind::Shared),
114+
::testing::Values(uur::USMKind::Device,
115+
uur::USMKind::Host,
116+
uur::USMKind::Shared)),
96117
uur::print2DTestString<urEnqueueUSMMemcpy2DTestWithParam>);
97118

98119
TEST_P(urEnqueueUSMMemcpy2DTestWithParam, SuccessBlocking) {
@@ -119,7 +140,8 @@ TEST_P(urEnqueueUSMMemcpy2DTestWithParam, SuccessNonBlocking) {
119140

120141
using urEnqueueUSMMemcpy2DNegativeTest = urEnqueueUSMMemcpy2DTestWithParam;
121142
UUR_TEST_SUITE_P(urEnqueueUSMMemcpy2DNegativeTest,
122-
::testing::Values(uur::TestParameters2D{1, 1, 1}),
143+
::testing::Values(TestParametersMemcpy2D{
144+
{1, 1, 1}, uur::USMKind::Device, uur::USMKind::Device}),
123145
uur::print2DTestString<urEnqueueUSMMemcpy2DTestWithParam>);
124146

125147
TEST_P(urEnqueueUSMMemcpy2DNegativeTest, InvalidNullHandleQueue) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,8 @@ struct urProgramTest : urQueueTest {
10711071
template <class T> struct urProgramTestWithParam : urContextTestWithParam<T> {
10721072
void SetUp() override {
10731073
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
1074-
uur::KernelsEnvironment::instance->LoadSource("foo", 0, il_binary);
1074+
uur::KernelsEnvironment::instance->LoadSource(program_name, 0,
1075+
il_binary);
10751076
ASSERT_SUCCESS(uur::KernelsEnvironment::instance->CreateProgram(
10761077
this->platform, this->context, this->device, *il_binary, &program));
10771078
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,18 @@ ur_device_partition_property_t makePartitionEquallyDesc(uint32_t cu_per_device);
378378
ur_device_partition_property_t
379379
makePartitionByAffinityDomain(ur_device_affinity_domain_flags_t aff_domain);
380380

381+
enum class USMKind {
382+
Device,
383+
Host,
384+
Shared,
385+
};
386+
387+
ur_result_t MakeUSMAllocationByType(USMKind kind, ur_context_handle_t hContext,
388+
ur_device_handle_t hDevice,
389+
const ur_usm_desc_t *pUSMDesc,
390+
ur_usm_pool_handle_t hPool, size_t size,
391+
void **ppMem);
392+
381393
} // namespace uur
382394

383395
#endif // UR_CONFORMANCE_INCLUDE_UTILS_H_INCLUDED

test/conformance/testing/source/utils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,22 @@ makePartitionByAffinityDomain(ur_device_affinity_domain_flags_t aff_domain) {
658658
return desc;
659659
}
660660

661+
ur_result_t MakeUSMAllocationByType(USMKind kind, ur_context_handle_t hContext,
662+
ur_device_handle_t hDevice,
663+
const ur_usm_desc_t *pUSMDesc,
664+
ur_usm_pool_handle_t hPool, size_t size,
665+
void **ppMem) {
666+
switch (kind) {
667+
case USMKind::Device:
668+
return urUSMDeviceAlloc(hContext, hDevice, pUSMDesc, hPool, size,
669+
ppMem);
670+
case USMKind::Host:
671+
return urUSMHostAlloc(hContext, pUSMDesc, hPool, size, ppMem);
672+
default:
673+
case USMKind::Shared:
674+
return urUSMSharedAlloc(hContext, hDevice, pUSMDesc, hPool, size,
675+
ppMem);
676+
}
677+
}
678+
661679
} // namespace uur

0 commit comments

Comments
 (0)