Skip to content

Commit

Permalink
[UR][CTS] Add urEnqueueMemImageRead/Write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
callumfare committed Jun 29, 2023
1 parent 26099b3 commit 0b86fff
Show file tree
Hide file tree
Showing 3 changed files with 353 additions and 0 deletions.
142 changes: 142 additions & 0 deletions test/conformance/enqueue/urEnqueueMemImageRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,145 @@
// 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 <uur/fixtures.h>

using urEnqueueMemImageReadTest = uur::urMemImageQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemImageReadTest);

// Note that for each test, we multiply the size in pixels by 4 to account for
// each channel in the RGBA image

TEST_P(urEnqueueMemImageReadTest, Success1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, Success2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageRead(queue, image2D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, Success3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageRead(queue, image3D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidNullHandleQueue) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemImageRead(nullptr, image1D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidNullHandleImage) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemImageRead(queue, nullptr, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidNullPointerDst) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, nullptr, 0, nullptr, nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidNullPtrEventWaitList) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};

ASSERT_EQ_RESULT(urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, output.data(), 1, nullptr,
nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);

ur_event_handle_t validEvent;
ASSERT_SUCCESS(urEnqueueEventsWait(queue, 0, nullptr, &validEvent));

ASSERT_EQ_RESULT(urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, output.data(), 0, &validEvent,
nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}

TEST_P(urEnqueueMemImageReadTest, InvalidOrigin1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{1, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidOrigin2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height, 1};
ur_rect_offset_t origin{0, 1, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image2D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidOrigin3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth};
ur_rect_offset_t origin{0, 0, 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image3D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidRegion1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width + 1, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image1D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidRegion2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height + 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image2D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageReadTest, InvalidRegion3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth + 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image3D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}
140 changes: 140 additions & 0 deletions test/conformance/enqueue/urEnqueueMemImageWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,143 @@
// 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 <uur/fixtures.h>

using urEnqueueMemImageWriteTest = uur::urMemImageQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemImageWriteTest);

TEST_P(urEnqueueMemImageWriteTest, Success1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageWrite(queue, image1D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, Success2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageWrite(queue, image2D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, Success3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_SUCCESS(urEnqueueMemImageWrite(queue, image3D, true, origin, region,
0, 0, output.data(), 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidNullHandleQueue) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemImageWrite(nullptr, image1D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidNullHandleImage) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueMemImageWrite(queue, nullptr, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidNullPointerSrc) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urEnqueueMemImageWrite(queue, image1D, true, origin,
region, 0, 0, nullptr, 0, nullptr,
nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidNullPtrEventWaitList) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{0, 0, 0};

ASSERT_EQ_RESULT(urEnqueueMemImageWrite(queue, image1D, true, origin,
region, 0, 0, output.data(), 1,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);

ur_event_handle_t validEvent;
ASSERT_SUCCESS(urEnqueueEventsWait(queue, 0, nullptr, &validEvent));

ASSERT_EQ_RESULT(urEnqueueMemImageWrite(queue, image1D, true, origin,
region, 0, 0, output.data(), 0,
&validEvent, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}

TEST_P(urEnqueueMemImageWriteTest, InvalidOrigin1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width, 1, 1};
ur_rect_offset_t origin{1, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image1D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidOrigin2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height, 1};
ur_rect_offset_t origin{0, 1, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image2D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidOrigin3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth};
ur_rect_offset_t origin{0, 0, 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image3D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidRegion1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t region{width + 1, 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image1D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidRegion2D) {
std::vector<uint32_t> output(width * height * 4, 42);
ur_rect_region_t region{width, height + 1, 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image2D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}

TEST_P(urEnqueueMemImageWriteTest, InvalidRegion3D) {
std::vector<uint32_t> output(width * height * depth * 4, 42);
ur_rect_region_t region{width, height, depth + 1};
ur_rect_offset_t origin{0, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image3D, true, origin,
region, 0, 0, output.data(), 0,
nullptr, nullptr));
}
71 changes: 71 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,77 @@ struct urMemBufferQueueTest : urQueueTest {
ur_mem_handle_t buffer = nullptr;
};

struct urMemImageQueueTest : urQueueTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::SetUp());
ASSERT_SUCCESS(urMemImageCreate(this->context, UR_MEM_FLAG_READ_WRITE,
&format, &desc1D, nullptr, &image1D));

ASSERT_SUCCESS(urMemImageCreate(this->context, UR_MEM_FLAG_READ_WRITE,
&format, &desc2D, nullptr, &image2D));

ASSERT_SUCCESS(urMemImageCreate(this->context, UR_MEM_FLAG_READ_WRITE,
&format, &desc3D, nullptr, &image3D));
}

void TearDown() override {
if (image1D) {
EXPECT_SUCCESS(urMemRelease(image1D));
}
if (image2D) {
EXPECT_SUCCESS(urMemRelease(image2D));
}
if (image3D) {
EXPECT_SUCCESS(urMemRelease(image3D));
}
UUR_RETURN_ON_FATAL_FAILURE(urQueueTest::TearDown());
}

const size_t width = 1024;
const size_t height = 8;
const size_t depth = 2;
ur_mem_handle_t image1D = nullptr;
ur_mem_handle_t image2D = nullptr;
ur_mem_handle_t image3D = nullptr;
ur_image_format_t format = {UR_IMAGE_CHANNEL_ORDER_RGBA,
UR_IMAGE_CHANNEL_TYPE_FLOAT};
ur_image_desc_t desc1D = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype
nullptr, // pNext
UR_MEM_TYPE_IMAGE1D, // mem object type
width, // image width
1, // image height
1, // image depth
1, // array size
0, // row pitch
0, // slice pitch
0, // mip levels
0}; // num samples

ur_image_desc_t desc2D = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype
nullptr, // pNext
UR_MEM_TYPE_IMAGE2D, // mem object type
width, // image width
height, // image height
1, // image depth
1, // array size
0, // row pitch
0, // slice pitch
0, // mip levels
0}; // num samples

ur_image_desc_t desc3D = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype
nullptr, // pNext
UR_MEM_TYPE_IMAGE3D, // mem object type
width, // image width
height, // image height
depth, // image depth
1, // array size
0, // row pitch
0, // slice pitch
0, // mip levels
0}; // num samples
};

struct urUSMDeviceAllocTest : urQueueTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTest::SetUp());
Expand Down

0 comments on commit 0b86fff

Please sign in to comment.