From 3dc67ed7e1d41f02b50e2cd95140d422ee0c526d Mon Sep 17 00:00:00 2001 From: Callum Fare Date: Thu, 29 Jun 2023 11:36:05 +0100 Subject: [PATCH] [UR][CTS] Add urEnqueueMemImageRead/Write tests --- .../enqueue/urEnqueueMemImageRead.cpp | 122 ++++++++++++++++++ .../enqueue/urEnqueueMemImageWrite.cpp | 119 +++++++++++++++++ .../testing/include/uur/fixtures.h | 75 +++++++++++ 3 files changed, 316 insertions(+) diff --git a/test/conformance/enqueue/urEnqueueMemImageRead.cpp b/test/conformance/enqueue/urEnqueueMemImageRead.cpp index 281aa8badb..d40625c3e1 100644 --- a/test/conformance/enqueue/urEnqueueMemImageRead.cpp +++ b/test/conformance/enqueue/urEnqueueMemImageRead.cpp @@ -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 + +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 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 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 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 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 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 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 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 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 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 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 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 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 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)); +} diff --git a/test/conformance/enqueue/urEnqueueMemImageWrite.cpp b/test/conformance/enqueue/urEnqueueMemImageWrite.cpp index 281aa8badb..7f7968bdff 100644 --- a/test/conformance/enqueue/urEnqueueMemImageWrite.cpp +++ b/test/conformance/enqueue/urEnqueueMemImageWrite.cpp @@ -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 + +using urEnqueueMemImageWriteTest = uur::urMemImageQueueTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemImageWriteTest); + +TEST_P(urEnqueueMemImageWriteTest, Success1D) { + std::vector 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 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 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 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 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 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 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 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 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 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 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 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 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)); +} diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index 0f279f2e74..09116c9a75 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -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());