From 2cbe1e92c58f12722a9337222387feb45aee8951 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Thu, 12 Oct 2023 13:12:25 +0200 Subject: [PATCH 1/3] UTs commandCopyImageToBuffer, commandCopyImage, commandCopyBufferToImage --- tests/test_openclhpp.cpp | 124 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index 7748e664..27e74dcd 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -408,6 +408,9 @@ void setUp(void) cl::pfn_clRetainCommandBufferKHR = ::clRetainCommandBufferKHR; cl::pfn_clReleaseCommandBufferKHR = ::clReleaseCommandBufferKHR; cl::pfn_clGetCommandBufferInfoKHR = ::clGetCommandBufferInfoKHR; + cl::pfn_clCommandCopyImageToBufferKHR = ::clCommandCopyImageToBufferKHR; + cl::pfn_clCommandCopyImageKHR = ::clCommandCopyImageKHR; + cl::pfn_clCommandCopyBufferToImageKHR = ::clCommandCopyBufferToImageKHR; #endif #if defined(cl_khr_semaphore) cl::pfn_clCreateSemaphoreWithPropertiesKHR = ::clCreateSemaphoreWithPropertiesKHR; @@ -485,6 +488,9 @@ void tearDown(void) cl::pfn_clRetainCommandBufferKHR = nullptr; cl::pfn_clReleaseCommandBufferKHR = nullptr; cl::pfn_clGetCommandBufferInfoKHR = nullptr; + cl::pfn_clCommandCopyImageToBufferKHR = nullptr; + cl::pfn_clCommandCopyImageKHR = nullptr; + cl::pfn_clCommandCopyBufferToImageKHR = nullptr; #endif #if defined(cl_khr_semaphore) cl::pfn_clCreateSemaphoreWithPropertiesKHR = nullptr; @@ -3604,6 +3610,124 @@ void testCommandBufferInfoKHRCommandQueues(void) TEST_ASSERT_EQUAL_PTR(make_command_queue(2), command_queues[2]()); #endif } + +static cl_int clcommandCopyImageToBufferKHR_testcommandCopyImageToBuffer(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, cl_mem src_image, +cl_mem dst_buffer, const size_t* src_origin, const size_t* region, size_t dst_offset, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_image, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_buffer, bufferPool[0]()); + TEST_ASSERT_EQUAL(src_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(dst_offset, 0); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); + TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + return 0; +} + +void testCommandCopyImageToBuffer(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl::size_type dst_offset = 0; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {sync_point}; + cl::MutableCommandKhr* mutable_handle = nullptr; + const cl::CommandQueue* command_queue = nullptr; + + clCommandCopyImageToBufferKHR_StubWithCallback(clcommandCopyImageToBufferKHR_testcommandCopyImageToBuffer); + ret = commandBufferKhrPool[0].commandCopyImageToBuffer(image2DPool[0], bufferPool[0], origin, region, dst_offset, &sync_points_vec, + &sync_point, mutable_handle, command_queue); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); +#endif +} + +static cl_int clCommandCopyImageKHR_testcommandCopyImage(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, cl_mem src_image, cl_mem dst_image, +const size_t* src_origin, const size_t* dst_origin, const size_t* region, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_image, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_image, image2DPool[1]()); + TEST_ASSERT_EQUAL(src_origin[0], 16); + TEST_ASSERT_EQUAL(dst_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); + TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + return 0; +} + +void testCommandCopyImage(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array dst_origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {sync_point}; + cl::MutableCommandKhr* mutable_handle = nullptr; + const cl::CommandQueue* command_queue = nullptr; + + clCommandCopyImageKHR_StubWithCallback(clCommandCopyImageKHR_testcommandCopyImage); + ret = commandBufferKhrPool[0].commandCopyImage(image2DPool[0], image2DPool[1], origin, dst_origin, region, &sync_points_vec, + &sync_point, mutable_handle, command_queue); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); +#endif +} + +static cl_int clCommandCopyBufferToImageKHR_testcommandCopyBufferToImage(cl_command_buffer_khr command_buffer, cl_command_queue command_queue, +cl_mem src_buffer, cl_mem dst_image, size_t src_offset, const size_t* dst_origin, const size_t* region, cl_uint num_sync_points_in_wait_list, +const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl_mutable_command_khr* mutable_handle, int num_calls) +{ + (void)num_calls; + TEST_ASSERT_EQUAL(command_buffer, commandBufferKhrPool[0]()); + TEST_ASSERT_EQUAL_PTR(command_queue,nullptr); + TEST_ASSERT_EQUAL(src_buffer, image2DPool[0]()); + TEST_ASSERT_EQUAL(dst_image, bufferPool[0]()); + TEST_ASSERT_EQUAL(dst_origin[0], 16); + TEST_ASSERT_EQUAL(region[0], 512); + TEST_ASSERT_EQUAL(src_offset, 0); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); + TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + return 0; +} + +void testCommandCopyBufferToImage(void) +{ +#if defined(cl_khr_command_buffer) + cl_int ret = CL_INVALID_CONTEXT; + + const std::array origin = {16, 32, 0}; + const std::array region = {512, 512, 0}; + cl::size_type src_offset = 0; + cl_sync_point_khr sync_point = 0; + const cl::vector sync_points_vec = {sync_point}; + cl::MutableCommandKhr* mutable_handle = nullptr; + const cl::CommandQueue* command_queue = nullptr; + + clCommandCopyBufferToImageKHR_StubWithCallback(clCommandCopyBufferToImageKHR_testcommandCopyBufferToImage); + ret = commandBufferKhrPool[0].commandCopyBufferToImage(bufferPool[0], image2DPool[0], src_offset, origin, region, &sync_points_vec, + &sync_point, mutable_handle, command_queue); + TEST_ASSERT_EQUAL(ret, CL_SUCCESS); +#endif +} + // Tests for Device::GetInfo static cl_int clGetInfo_testDeviceGetInfoCLDeviceVendorId( cl_device_id device, cl_device_info param_name, size_t param_value_size, From 2db024ebeb1bf5b44ab79ff91b6476eac14ca0cb Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Tue, 17 Oct 2023 12:18:03 +0200 Subject: [PATCH 2/3] Added checking for sync_point, other corrections --- tests/test_openclhpp.cpp | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index 27e74dcd..2bdb285c 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -3623,10 +3623,15 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL(src_origin[0], 16); TEST_ASSERT_EQUAL(region[0], 512); TEST_ASSERT_EQUAL(dst_offset, 0); - TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); - TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + *sync_point = 5; + return 0; } @@ -3639,14 +3644,13 @@ void testCommandCopyImageToBuffer(void) const std::array region = {512, 512, 0}; cl::size_type dst_offset = 0; cl_sync_point_khr sync_point = 0; - const cl::vector sync_points_vec = {sync_point}; - cl::MutableCommandKhr* mutable_handle = nullptr; - const cl::CommandQueue* command_queue = nullptr; + const cl::vector sync_points_vec = {1, 2, 3}; clCommandCopyImageToBufferKHR_StubWithCallback(clcommandCopyImageToBufferKHR_testcommandCopyImageToBuffer); ret = commandBufferKhrPool[0].commandCopyImageToBuffer(image2DPool[0], bufferPool[0], origin, region, dst_offset, &sync_points_vec, - &sync_point, mutable_handle, command_queue); + &sync_point, nullptr, nullptr); TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); #endif } @@ -3662,10 +3666,15 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL(src_origin[0], 16); TEST_ASSERT_EQUAL(dst_origin[0], 16); TEST_ASSERT_EQUAL(region[0], 512); - TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); - TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + *sync_point = 5; + return 0; } @@ -3678,14 +3687,13 @@ void testCommandCopyImage(void) const std::array dst_origin = {16, 32, 0}; const std::array region = {512, 512, 0}; cl_sync_point_khr sync_point = 0; - const cl::vector sync_points_vec = {sync_point}; - cl::MutableCommandKhr* mutable_handle = nullptr; - const cl::CommandQueue* command_queue = nullptr; + const cl::vector sync_points_vec = {1, 2, 3}; clCommandCopyImageKHR_StubWithCallback(clCommandCopyImageKHR_testcommandCopyImage); ret = commandBufferKhrPool[0].commandCopyImage(image2DPool[0], image2DPool[1], origin, dst_origin, region, &sync_points_vec, - &sync_point, mutable_handle, command_queue); + &sync_point, nullptr, nullptr); TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); #endif } @@ -3701,10 +3709,15 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL(dst_origin[0], 16); TEST_ASSERT_EQUAL(region[0], 512); TEST_ASSERT_EQUAL(src_offset, 0); - TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 1); - TEST_ASSERT_EQUAL(*sync_point_wait_list, 0); + TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); + TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); + TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); + TEST_ASSERT_EQUAL(sync_point_wait_list[2], 3); TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); + TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); + *sync_point = 5; + return 0; } @@ -3717,14 +3730,13 @@ void testCommandCopyBufferToImage(void) const std::array region = {512, 512, 0}; cl::size_type src_offset = 0; cl_sync_point_khr sync_point = 0; - const cl::vector sync_points_vec = {sync_point}; - cl::MutableCommandKhr* mutable_handle = nullptr; - const cl::CommandQueue* command_queue = nullptr; + const cl::vector sync_points_vec = {1, 2, 3}; clCommandCopyBufferToImageKHR_StubWithCallback(clCommandCopyBufferToImageKHR_testcommandCopyBufferToImage); ret = commandBufferKhrPool[0].commandCopyBufferToImage(bufferPool[0], image2DPool[0], src_offset, origin, region, &sync_points_vec, - &sync_point, mutable_handle, command_queue); + &sync_point, nullptr, nullptr); TEST_ASSERT_EQUAL(ret, CL_SUCCESS); + TEST_ASSERT_EQUAL(5, sync_point); #endif } From bd4215c9b0ed526e5ae3c8430546d6a37be33c58 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Mon, 20 Nov 2023 08:01:11 +0100 Subject: [PATCH 3/3] Added corrections --- tests/test_openclhpp.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index e0288cd6..b86f799d 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -3626,7 +3626,7 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL(dst_buffer, bufferPool[0]()); TEST_ASSERT_EQUAL(src_origin[0], 16); TEST_ASSERT_EQUAL(region[0], 512); - TEST_ASSERT_EQUAL(dst_offset, 0); + TEST_ASSERT_EQUAL(dst_offset, 10); TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); @@ -3634,9 +3634,12 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); - *sync_point = 5; + if (sync_point != nullptr) + { + *sync_point = 5; + } - return 0; + return CL_SUCCESS; } void testCommandCopyImageToBuffer(void) @@ -3646,7 +3649,7 @@ void testCommandCopyImageToBuffer(void) const std::array origin = {16, 32, 0}; const std::array region = {512, 512, 0}; - cl::size_type dst_offset = 0; + cl::size_type dst_offset = 10; cl_sync_point_khr sync_point = 0; const cl::vector sync_points_vec = {1, 2, 3}; @@ -3677,9 +3680,12 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); - *sync_point = 5; + if (sync_point != nullptr) + { + *sync_point = 5; + } - return 0; + return CL_SUCCESS; } void testCommandCopyImage(void) @@ -3712,7 +3718,7 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL(dst_image, bufferPool[0]()); TEST_ASSERT_EQUAL(dst_origin[0], 16); TEST_ASSERT_EQUAL(region[0], 512); - TEST_ASSERT_EQUAL(src_offset, 0); + TEST_ASSERT_EQUAL(src_offset, 10); TEST_ASSERT_EQUAL(num_sync_points_in_wait_list, 3); TEST_ASSERT_EQUAL(sync_point_wait_list[0], 1); TEST_ASSERT_EQUAL(sync_point_wait_list[1], 2); @@ -3720,9 +3726,12 @@ const cl_sync_point_khr* sync_point_wait_list, cl_sync_point_khr* sync_point, cl TEST_ASSERT_EQUAL_PTR(mutable_handle, nullptr); TEST_ASSERT_NOT_EQUAL(sync_point, nullptr); - *sync_point = 5; + if (sync_point != nullptr) + { + *sync_point = 5; + } - return 0; + return CL_SUCCESS; } void testCommandCopyBufferToImage(void) @@ -3732,7 +3741,7 @@ void testCommandCopyBufferToImage(void) const std::array origin = {16, 32, 0}; const std::array region = {512, 512, 0}; - cl::size_type src_offset = 0; + cl::size_type src_offset = 10; cl_sync_point_khr sync_point = 0; const cl::vector sync_points_vec = {1, 2, 3};