Skip to content

Commit db8df7d

Browse files
Xewar313kbenzie
authored andcommitted
Add command buffer operations tests (#17159)
Adds some tests that check most basic command buffer functionalities
1 parent 4f14289 commit db8df7d

File tree

10 files changed

+722
-6
lines changed

10 files changed

+722
-6
lines changed

test/conformance/enqueue/urEnqueueMemBufferWriteRect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TEST_P(urEnqueueMemBufferWriteRectTestWithParam, Success) {
8787
UUR_KNOWN_FAILURE_ON(uur::HIP{});
8888
}
8989

90-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
90+
UUR_KNOWN_FAILURE_ON(uur::LevelZero{});
9191

9292
// Unpack the parameters.
9393
const auto host_size = getParam().src_size;

test/conformance/exp_command_buffer/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ add_conformance_test_with_kernels_environment(exp_command_buffer
1111
event_sync.cpp
1212
kernel_event_sync.cpp
1313
invalid.cpp
14+
copy.cpp
15+
read.cpp
16+
write.cpp
17+
rect_read.cpp
18+
rect_write.cpp
1419
update/buffer_fill_kernel_update.cpp
1520
update/invalid_update.cpp
1621
update/kernel_handle_update.cpp
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
struct testParametersMemcpy {
10+
size_t size;
11+
size_t offset_src;
12+
size_t offset_dst;
13+
size_t copy_size;
14+
};
15+
16+
struct urCommandBufferMemcpyCommandsTest
17+
: uur::command_buffer::urCommandBufferExpTestWithParam<
18+
testParametersMemcpy> {
19+
void SetUp() override {
20+
UUR_RETURN_ON_FATAL_FAILURE(
21+
uur::command_buffer::urCommandBufferExpTestWithParam<
22+
testParametersMemcpy>::SetUp());
23+
24+
size = std::get<1>(GetParam()).size;
25+
offset_src = std::get<1>(GetParam()).offset_src;
26+
offset_dst = std::get<1>(GetParam()).offset_dst;
27+
copy_size = std::get<1>(GetParam()).copy_size;
28+
assert(size <= offset_src + copy_size);
29+
assert(size <= offset_dst + copy_size);
30+
// Allocate USM pointers
31+
ASSERT_SUCCESS(
32+
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &device_ptr));
33+
ASSERT_NE(device_ptr, nullptr);
34+
35+
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
36+
nullptr, &buffer));
37+
38+
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
39+
nullptr, &buffer_base));
40+
41+
ASSERT_NE(buffer, nullptr);
42+
ASSERT_NE(buffer_base, nullptr);
43+
}
44+
45+
void TearDown() override {
46+
if (device_ptr) {
47+
EXPECT_SUCCESS(urUSMFree(context, device_ptr));
48+
}
49+
50+
if (buffer) {
51+
EXPECT_SUCCESS(urMemRelease(buffer));
52+
}
53+
54+
if (buffer_base) {
55+
EXPECT_SUCCESS(urMemRelease(buffer_base));
56+
}
57+
58+
UUR_RETURN_ON_FATAL_FAILURE(
59+
uur::command_buffer::urCommandBufferExpTestWithParam<
60+
testParametersMemcpy>::TearDown());
61+
}
62+
63+
void verifyData(const std::vector<uint8_t> &output,
64+
const std::vector<uint8_t> &input) {
65+
for (size_t i = 0; i < copy_size; ++i) {
66+
ASSERT_EQ(output[i + offset_dst], input[i + offset_src])
67+
<< "Result mismatch at index: " << i;
68+
}
69+
for (size_t i = 0; i < offset_dst; ++i) {
70+
ASSERT_EQ(output[i], BASE_VALUE) << "Result mismatch at index: " << i;
71+
}
72+
for (size_t i = offset_dst + copy_size; i < size; ++i) {
73+
ASSERT_EQ(output[i], BASE_VALUE) << "Result mismatch at index: " << i;
74+
}
75+
}
76+
const uint8_t BASE_VALUE = 1;
77+
size_t size, copy_size, offset_src, offset_dst;
78+
79+
ur_exp_command_buffer_sync_point_t sync_point, sync_point2;
80+
void *device_ptr = nullptr;
81+
ur_mem_handle_t buffer = nullptr;
82+
ur_mem_handle_t buffer_base = nullptr;
83+
};
84+
85+
static std::vector<testParametersMemcpy> test_cases{
86+
// copy whole buffer
87+
{1, 0, 0, 1},
88+
{256, 0, 0, 256},
89+
{1024, 0, 0, 1024},
90+
// copy part of buffer
91+
{256, 127, 127, 128},
92+
{1024, 256, 256, 256},
93+
// copy to different offset
94+
{256, 127, 196, 25},
95+
{1024, 756, 256, 256},
96+
97+
};
98+
99+
template <typename T>
100+
static std::string printMemcpyTestString(
101+
const testing::TestParamInfo<typename T::ParamType> &info) {
102+
const auto device_handle = std::get<0>(info.param).device;
103+
const auto platform_device_name =
104+
uur::GetPlatformAndDeviceName(device_handle);
105+
std::stringstream test_name;
106+
test_name << platform_device_name << "__size__"
107+
<< std::get<1>(info.param).size << "__offset_src__"
108+
<< std::get<1>(info.param).offset_src << "__offset_src__"
109+
<< std::get<1>(info.param).offset_dst << "__copy_size__"
110+
<< std::get<1>(info.param).copy_size;
111+
return test_name.str();
112+
}
113+
114+
UUR_DEVICE_TEST_SUITE_WITH_PARAM(
115+
urCommandBufferMemcpyCommandsTest, testing::ValuesIn(test_cases),
116+
printMemcpyTestString<urCommandBufferMemcpyCommandsTest>);
117+
118+
TEST_P(urCommandBufferMemcpyCommandsTest, Buffer) {
119+
std::vector<uint8_t> input(size);
120+
std::iota(input.begin(), input.end(), 1);
121+
122+
ASSERT_SUCCESS(urCommandBufferAppendMemBufferWriteExp(
123+
cmd_buf_handle, buffer_base, 0, size, input.data(), 0, nullptr, 0,
124+
nullptr, &sync_point, nullptr, nullptr));
125+
126+
ASSERT_SUCCESS(urCommandBufferAppendMemBufferCopyExp(
127+
cmd_buf_handle, buffer_base, buffer, offset_src, offset_dst, copy_size, 1,
128+
&sync_point, 0, nullptr, &sync_point2, nullptr, nullptr));
129+
std::vector<uint8_t> output(size, BASE_VALUE);
130+
ASSERT_SUCCESS(urCommandBufferAppendMemBufferReadExp(
131+
cmd_buf_handle, buffer, 0, size, output.data(), 1, &sync_point2, 0,
132+
nullptr, nullptr, nullptr, nullptr));
133+
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));
134+
135+
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
136+
output.data(), 0, nullptr, nullptr));
137+
138+
ASSERT_SUCCESS(
139+
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
140+
ASSERT_SUCCESS(urQueueFinish(queue));
141+
142+
verifyData(output, input);
143+
}
144+
145+
TEST_P(urCommandBufferMemcpyCommandsTest, USM) {
146+
std::vector<uint8_t> input(size);
147+
std::iota(input.begin(), input.end(), 1);
148+
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(
149+
cmd_buf_handle, ((uint8_t *)device_ptr) + offset_dst,
150+
input.data() + offset_src, copy_size, 0, nullptr, 0, nullptr, &sync_point,
151+
nullptr, nullptr));
152+
153+
std::vector<uint8_t> output(size, BASE_VALUE);
154+
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(
155+
cmd_buf_handle, output.data(), device_ptr, size, 1, &sync_point, 0,
156+
nullptr, nullptr, nullptr, nullptr));
157+
158+
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));
159+
160+
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, true, device_ptr, output.data(),
161+
size, 0, nullptr, nullptr));
162+
163+
ASSERT_SUCCESS(
164+
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
165+
ASSERT_SUCCESS(urQueueFinish(queue));
166+
167+
verifyData(output, input);
168+
}

test/conformance/exp_command_buffer/fill.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct urCommandBufferFillCommandsTest
5353
testParametersFill>::TearDown());
5454
}
5555

56-
void verifyData(std::vector<uint8_t> &output, size_t verify_size) {
56+
void verifyData(const std::vector<uint8_t> &output,
57+
const size_t verify_size) {
5758
size_t pattern_index = 0;
5859
for (size_t i = 0; i < verify_size; ++i) {
5960
ASSERT_EQ(output[i], pattern[pattern_index])

test/conformance/exp_command_buffer/fixtures.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static void checkCommandBufferUpdateSupport(
4545

4646
struct urCommandBufferExpTest : uur::urContextTest {
4747
void SetUp() override {
48-
4948
UUR_RETURN_ON_FATAL_FAILURE(uur::urContextTest::SetUp());
5049

5150
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
@@ -71,7 +70,6 @@ struct urCommandBufferExpTest : uur::urContextTest {
7170
template <class T>
7271
struct urCommandBufferExpTestWithParam : urQueueTestWithParam<T> {
7372
void SetUp() override {
74-
7573
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTestWithParam<T>::SetUp());
7674

7775
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(this->device));
@@ -95,7 +93,6 @@ struct urCommandBufferExpTestWithParam : urQueueTestWithParam<T> {
9593

9694
struct urCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
9795
void SetUp() override {
98-
9996
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());
10097

10198
UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
@@ -156,7 +153,6 @@ struct urUpdatableCommandBufferExpTest : uur::urQueueTest {
156153
struct urUpdatableCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
157154
void SetUp() override {
158155
UUR_KNOWN_FAILURE_ON(uur::LevelZeroV2{});
159-
160156
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());
161157

162158
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "fixtures.h"
8+
9+
struct testParametersRead {
10+
size_t size;
11+
size_t offset;
12+
size_t read_size;
13+
};
14+
15+
struct urCommandBufferReadCommandsTest
16+
: uur::command_buffer::urCommandBufferExpTestWithParam<testParametersRead> {
17+
void SetUp() override {
18+
UUR_RETURN_ON_FATAL_FAILURE(
19+
uur::command_buffer::urCommandBufferExpTestWithParam<
20+
testParametersRead>::SetUp());
21+
22+
size = std::get<1>(GetParam()).size;
23+
offset = std::get<1>(GetParam()).offset;
24+
read_size = std::get<1>(GetParam()).read_size;
25+
assert(size <= offset + read_size);
26+
// Allocate USM pointers
27+
ASSERT_SUCCESS(
28+
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &device_ptr));
29+
ASSERT_NE(device_ptr, nullptr);
30+
31+
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
32+
nullptr, &buffer));
33+
34+
ASSERT_NE(buffer, nullptr);
35+
}
36+
37+
void TearDown() override {
38+
if (device_ptr) {
39+
EXPECT_SUCCESS(urUSMFree(context, device_ptr));
40+
}
41+
42+
if (buffer) {
43+
EXPECT_SUCCESS(urMemRelease(buffer));
44+
}
45+
46+
UUR_RETURN_ON_FATAL_FAILURE(
47+
uur::command_buffer::urCommandBufferExpTestWithParam<
48+
testParametersRead>::TearDown());
49+
}
50+
51+
void verifyData(const std::vector<uint8_t> &output,
52+
const std::vector<uint8_t> &input) {
53+
for (size_t i = 0; i < read_size; ++i) {
54+
ASSERT_EQ(output[i], input[i + offset])
55+
<< "Result mismatch at index: " << i;
56+
}
57+
}
58+
59+
size_t size, read_size, offset;
60+
61+
void *device_ptr = nullptr;
62+
ur_mem_handle_t buffer = nullptr;
63+
};
64+
65+
static std::vector<testParametersRead> test_cases{
66+
// read whole buffer
67+
{1, 0, 1},
68+
{256, 0, 256},
69+
{1024, 0, 1024},
70+
// read part of buffer
71+
{256, 127, 128},
72+
{1024, 256, 256},
73+
};
74+
75+
template <typename T>
76+
static std::string
77+
printReadTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
78+
const auto device_handle = std::get<0>(info.param).device;
79+
const auto platform_device_name =
80+
uur::GetPlatformAndDeviceName(device_handle);
81+
std::stringstream test_name;
82+
test_name << platform_device_name << "__size__"
83+
<< std::get<1>(info.param).size << "__offset__"
84+
<< std::get<1>(info.param).offset << "__read_size__"
85+
<< std::get<1>(info.param).read_size;
86+
return test_name.str();
87+
}
88+
89+
UUR_DEVICE_TEST_SUITE_WITH_PARAM(
90+
urCommandBufferReadCommandsTest, testing::ValuesIn(test_cases),
91+
printReadTestString<urCommandBufferReadCommandsTest>);
92+
93+
TEST_P(urCommandBufferReadCommandsTest, Buffer) {
94+
std::vector<uint8_t> input(size);
95+
std::iota(input.begin(), input.end(), 1);
96+
97+
std::vector<uint8_t> output(size, 1);
98+
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
99+
input.data(), 0, nullptr, nullptr));
100+
101+
ASSERT_SUCCESS(urCommandBufferAppendMemBufferReadExp(
102+
cmd_buf_handle, buffer, offset, read_size, output.data(), 0, nullptr, 0,
103+
nullptr, nullptr, nullptr, nullptr));
104+
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));
105+
106+
ASSERT_SUCCESS(
107+
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
108+
ASSERT_SUCCESS(urQueueFinish(queue));
109+
110+
verifyData(output, input);
111+
}

0 commit comments

Comments
 (0)