Skip to content

Commit

Permalink
Merge pull request #659 from callumfare/callum/cts-enqueue-image-read…
Browse files Browse the repository at this point in the history
…write

[UR][CTS] Add urEnqueueMemImageRead/Write tests
  • Loading branch information
callumfare authored Jun 29, 2023
2 parents 3f89f04 + f5a7881 commit 7e5059c
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 0 deletions.
122 changes: 122 additions & 0 deletions test/conformance/enqueue/urEnqueueMemImageRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,125 @@
// 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);
ASSERT_SUCCESS(urEnqueueMemImageRead(queue, image1D, true, origin, region1D,
0, 0, output.data(), 0, nullptr,
nullptr));
}

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

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

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

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

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

TEST_P(urEnqueueMemImageReadTest, InvalidNullPtrEventWaitList) {
std::vector<uint32_t> output(width * 4, 42);
ASSERT_EQ_RESULT(urEnqueueMemImageRead(queue, image1D, true, origin,
region1D, 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,
region1D, 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_offset_t bad_origin{1, 0, 0};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image1D, true, bad_origin,
region1D, 0, 0, output.data(), 0,
nullptr, nullptr));
}

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

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

TEST_P(urEnqueueMemImageReadTest, InvalidRegion1D) {
std::vector<uint32_t> output(width * 4, 42);
ur_rect_region_t bad_region{width + 1, 1, 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image1D, true, origin,
bad_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 bad_region{width, height + 1, 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image2D, true, origin,
bad_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 bad_region{width, height, depth + 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageRead(queue, image3D, true, origin,
bad_region, 0, 0, output.data(), 0,
nullptr, nullptr));
}
119 changes: 119 additions & 0 deletions test/conformance/enqueue/urEnqueueMemImageWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,122 @@
// 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> input(width * 4, 42);
ASSERT_SUCCESS(urEnqueueMemImageWrite(queue, image1D, true, origin,
region1D, 0, 0, input.data(), 0,
nullptr, nullptr));
}

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

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

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

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

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

TEST_P(urEnqueueMemImageWriteTest, InvalidNullPtrEventWaitList) {
std::vector<uint32_t> input(width * 4, 42);
ASSERT_EQ_RESULT(urEnqueueMemImageWrite(queue, image1D, true, origin,
region1D, 0, 0, input.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,
region1D, 0, 0, input.data(), 0,
&validEvent, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
}

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

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

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

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

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

TEST_P(urEnqueueMemImageWriteTest, InvalidRegion3D) {
std::vector<uint32_t> input(width * height * depth * 4, 42);
ur_rect_region_t bad_region{width, height, depth + 1};
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urEnqueueMemImageWrite(queue, image3D, true, origin,
bad_region, 0, 0, input.data(), 0,
nullptr, nullptr));
}
75 changes: 75 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,81 @@ 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_rect_region_t region1D{width, 1, 1};
ur_rect_region_t region2D{width, height, 1};
ur_rect_region_t region3D{width, height, depth};
ur_rect_offset_t origin{0, 0, 0};
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 7e5059c

Please sign in to comment.