Skip to content

[SYCL] [UR] Add command buffer operations tests #17159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_P(urEnqueueMemBufferWriteRectTestWithParam, Success) {
UUR_KNOWN_FAILURE_ON(uur::HIP{});
}

UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{});
UUR_KNOWN_FAILURE_ON(uur::LevelZero{});

// Unpack the parameters.
const auto host_size = getParam().src_size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ add_conformance_test_with_kernels_environment(exp_command_buffer
event_sync.cpp
kernel_event_sync.cpp
invalid.cpp
copy.cpp
read.cpp
write.cpp
rect_read.cpp
rect_write.cpp
update/buffer_fill_kernel_update.cpp
update/invalid_update.cpp
update/kernel_handle_update.cpp
Expand Down
168 changes: 168 additions & 0 deletions unified-runtime/test/conformance/exp_command_buffer/copy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// Copyright (C) 2025 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"

struct testParametersMemcpy {
size_t size;
size_t offset_src;
size_t offset_dst;
size_t copy_size;
};

struct urCommandBufferMemcpyCommandsTest
: uur::command_buffer::urCommandBufferExpTestWithParam<
testParametersMemcpy> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::command_buffer::urCommandBufferExpTestWithParam<
testParametersMemcpy>::SetUp());

size = std::get<1>(GetParam()).size;
offset_src = std::get<1>(GetParam()).offset_src;
offset_dst = std::get<1>(GetParam()).offset_dst;
copy_size = std::get<1>(GetParam()).copy_size;
assert(size <= offset_src + copy_size);
assert(size <= offset_dst + copy_size);
// Allocate USM pointers
ASSERT_SUCCESS(
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &device_ptr));
ASSERT_NE(device_ptr, nullptr);

ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
nullptr, &buffer));

ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
nullptr, &buffer_base));

ASSERT_NE(buffer, nullptr);
ASSERT_NE(buffer_base, nullptr);
}

void TearDown() override {
if (device_ptr) {
EXPECT_SUCCESS(urUSMFree(context, device_ptr));
}

if (buffer) {
EXPECT_SUCCESS(urMemRelease(buffer));
}

if (buffer_base) {
EXPECT_SUCCESS(urMemRelease(buffer_base));
}

UUR_RETURN_ON_FATAL_FAILURE(
uur::command_buffer::urCommandBufferExpTestWithParam<
testParametersMemcpy>::TearDown());
}

void verifyData(const std::vector<uint8_t> &output,
const std::vector<uint8_t> &input) {
for (size_t i = 0; i < copy_size; ++i) {
ASSERT_EQ(output[i + offset_dst], input[i + offset_src])
<< "Result mismatch at index: " << i;
}
for (size_t i = 0; i < offset_dst; ++i) {
ASSERT_EQ(output[i], BASE_VALUE) << "Result mismatch at index: " << i;
}
for (size_t i = offset_dst + copy_size; i < size; ++i) {
ASSERT_EQ(output[i], BASE_VALUE) << "Result mismatch at index: " << i;
}
}
const uint8_t BASE_VALUE = 1;
size_t size, copy_size, offset_src, offset_dst;

ur_exp_command_buffer_sync_point_t sync_point, sync_point2;
void *device_ptr = nullptr;
ur_mem_handle_t buffer = nullptr;
ur_mem_handle_t buffer_base = nullptr;
};

static std::vector<testParametersMemcpy> test_cases{
// copy whole buffer
{1, 0, 0, 1},
{256, 0, 0, 256},
{1024, 0, 0, 1024},
// copy part of buffer
{256, 127, 127, 128},
{1024, 256, 256, 256},
// copy to different offset
{256, 127, 196, 25},
{1024, 756, 256, 256},

};

template <typename T>
static std::string printMemcpyTestString(
const testing::TestParamInfo<typename T::ParamType> &info) {
const auto device_handle = std::get<0>(info.param).device;
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
std::stringstream test_name;
test_name << platform_device_name << "__size__"
<< std::get<1>(info.param).size << "__offset_src__"
<< std::get<1>(info.param).offset_src << "__offset_src__"
<< std::get<1>(info.param).offset_dst << "__copy_size__"
<< std::get<1>(info.param).copy_size;
return test_name.str();
}

UUR_DEVICE_TEST_SUITE_WITH_PARAM(
urCommandBufferMemcpyCommandsTest, testing::ValuesIn(test_cases),
printMemcpyTestString<urCommandBufferMemcpyCommandsTest>);

TEST_P(urCommandBufferMemcpyCommandsTest, Buffer) {
std::vector<uint8_t> input(size);
std::iota(input.begin(), input.end(), 1);

ASSERT_SUCCESS(urCommandBufferAppendMemBufferWriteExp(
cmd_buf_handle, buffer_base, 0, size, input.data(), 0, nullptr, 0,
nullptr, &sync_point, nullptr, nullptr));

ASSERT_SUCCESS(urCommandBufferAppendMemBufferCopyExp(
cmd_buf_handle, buffer_base, buffer, offset_src, offset_dst, copy_size, 1,
&sync_point, 0, nullptr, &sync_point2, nullptr, nullptr));
std::vector<uint8_t> output(size, BASE_VALUE);
ASSERT_SUCCESS(urCommandBufferAppendMemBufferReadExp(
cmd_buf_handle, buffer, 0, size, output.data(), 1, &sync_point2, 0,
nullptr, nullptr, nullptr, nullptr));
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));

ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
output.data(), 0, nullptr, nullptr));

ASSERT_SUCCESS(
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
ASSERT_SUCCESS(urQueueFinish(queue));

verifyData(output, input);
}

TEST_P(urCommandBufferMemcpyCommandsTest, USM) {
std::vector<uint8_t> input(size);
std::iota(input.begin(), input.end(), 1);
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(
cmd_buf_handle, ((uint8_t *)device_ptr) + offset_dst,
input.data() + offset_src, copy_size, 0, nullptr, 0, nullptr, &sync_point,
nullptr, nullptr));

std::vector<uint8_t> output(size, BASE_VALUE);
ASSERT_SUCCESS(urCommandBufferAppendUSMMemcpyExp(
cmd_buf_handle, output.data(), device_ptr, size, 1, &sync_point, 0,
nullptr, nullptr, nullptr, nullptr));

ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));

ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, true, device_ptr, output.data(),
size, 0, nullptr, nullptr));

ASSERT_SUCCESS(
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
ASSERT_SUCCESS(urQueueFinish(queue));

verifyData(output, input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ struct urCommandBufferFillCommandsTest
testParametersFill>::TearDown());
}

void verifyData(std::vector<uint8_t> &output, size_t verify_size) {
void verifyData(const std::vector<uint8_t> &output,
const size_t verify_size) {
size_t pattern_index = 0;
for (size_t i = 0; i < verify_size; ++i) {
ASSERT_EQ(output[i], pattern[pattern_index])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static void checkCommandBufferUpdateSupport(

struct urCommandBufferExpTest : uur::urContextTest {
void SetUp() override {

UUR_RETURN_ON_FATAL_FAILURE(uur::urContextTest::SetUp());

UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
Expand All @@ -71,7 +70,6 @@ struct urCommandBufferExpTest : uur::urContextTest {
template <class T>
struct urCommandBufferExpTestWithParam : urQueueTestWithParam<T> {
void SetUp() override {

UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTestWithParam<T>::SetUp());

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

struct urCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
void SetUp() override {

UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());

UUR_RETURN_ON_FATAL_FAILURE(checkCommandBufferSupport(device));
Expand Down Expand Up @@ -156,7 +153,6 @@ struct urUpdatableCommandBufferExpTest : uur::urQueueTest {
struct urUpdatableCommandBufferExpExecutionTest : uur::urKernelExecutionTest {
void SetUp() override {
UUR_KNOWN_FAILURE_ON(uur::LevelZeroV2{});

UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());

ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
Expand Down
111 changes: 111 additions & 0 deletions unified-runtime/test/conformance/exp_command_buffer/read.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (C) 2025 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See LICENSE.TXT
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"

struct testParametersRead {
size_t size;
size_t offset;
size_t read_size;
};

struct urCommandBufferReadCommandsTest
: uur::command_buffer::urCommandBufferExpTestWithParam<testParametersRead> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(
uur::command_buffer::urCommandBufferExpTestWithParam<
testParametersRead>::SetUp());

size = std::get<1>(GetParam()).size;
offset = std::get<1>(GetParam()).offset;
read_size = std::get<1>(GetParam()).read_size;
assert(size <= offset + read_size);
// Allocate USM pointers
ASSERT_SUCCESS(
urUSMDeviceAlloc(context, device, nullptr, nullptr, size, &device_ptr));
ASSERT_NE(device_ptr, nullptr);

ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, size,
nullptr, &buffer));

ASSERT_NE(buffer, nullptr);
}

void TearDown() override {
if (device_ptr) {
EXPECT_SUCCESS(urUSMFree(context, device_ptr));
}

if (buffer) {
EXPECT_SUCCESS(urMemRelease(buffer));
}

UUR_RETURN_ON_FATAL_FAILURE(
uur::command_buffer::urCommandBufferExpTestWithParam<
testParametersRead>::TearDown());
}

void verifyData(const std::vector<uint8_t> &output,
const std::vector<uint8_t> &input) {
for (size_t i = 0; i < read_size; ++i) {
ASSERT_EQ(output[i], input[i + offset])
<< "Result mismatch at index: " << i;
}
}

size_t size, read_size, offset;

void *device_ptr = nullptr;
ur_mem_handle_t buffer = nullptr;
};

static std::vector<testParametersRead> test_cases{
// read whole buffer
{1, 0, 1},
{256, 0, 256},
{1024, 0, 1024},
// read part of buffer
{256, 127, 128},
{1024, 256, 256},
};

template <typename T>
static std::string
printReadTestString(const testing::TestParamInfo<typename T::ParamType> &info) {
const auto device_handle = std::get<0>(info.param).device;
const auto platform_device_name =
uur::GetPlatformAndDeviceName(device_handle);
std::stringstream test_name;
test_name << platform_device_name << "__size__"
<< std::get<1>(info.param).size << "__offset__"
<< std::get<1>(info.param).offset << "__read_size__"
<< std::get<1>(info.param).read_size;
return test_name.str();
}

UUR_DEVICE_TEST_SUITE_WITH_PARAM(
urCommandBufferReadCommandsTest, testing::ValuesIn(test_cases),
printReadTestString<urCommandBufferReadCommandsTest>);

TEST_P(urCommandBufferReadCommandsTest, Buffer) {
std::vector<uint8_t> input(size);
std::iota(input.begin(), input.end(), 1);

std::vector<uint8_t> output(size, 1);
ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size,
input.data(), 0, nullptr, nullptr));

ASSERT_SUCCESS(urCommandBufferAppendMemBufferReadExp(
cmd_buf_handle, buffer, offset, read_size, output.data(), 0, nullptr, 0,
nullptr, nullptr, nullptr, nullptr));
ASSERT_SUCCESS(urCommandBufferFinalizeExp(cmd_buf_handle));

ASSERT_SUCCESS(
urEnqueueCommandBufferExp(queue, cmd_buf_handle, 0, nullptr, nullptr));
ASSERT_SUCCESS(urQueueFinish(queue));

verifyData(output, input);
}
Loading