diff --git a/test/conformance/enqueue/urEnqueueMemImageRead.cpp b/test/conformance/enqueue/urEnqueueMemImageRead.cpp index 281aa8badb..1c50a3fc57 100644 --- a/test/conformance/enqueue/urEnqueueMemImageRead.cpp +++ b/test/conformance/enqueue/urEnqueueMemImageRead.cpp @@ -2,3 +2,142 @@ // 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); + +TEST_P(urEnqueueMemImageReadTest, Success1D) { + std::vector 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 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 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 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 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 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 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 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 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 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 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 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 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)); +} diff --git a/test/conformance/enqueue/urEnqueueMemImageWrite.cpp b/test/conformance/enqueue/urEnqueueMemImageWrite.cpp index 281aa8badb..2ab0f8bd46 100644 --- a/test/conformance/enqueue/urEnqueueMemImageWrite.cpp +++ b/test/conformance/enqueue/urEnqueueMemImageWrite.cpp @@ -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 + +using urEnqueueMemImageWriteTest = uur::urMemImageQueueTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueMemImageWriteTest); + +TEST_P(urEnqueueMemImageWriteTest, Success1D) { + std::vector 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 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 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 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 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 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 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 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 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 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 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 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 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)); +} diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index 0f279f2e74..9f66b4618e 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -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_IMAGE2D, // 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());