From 4e7f99f926fcf0271faa2a32e09c2740de6f2a4b Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Fri, 19 Jan 2024 19:17:25 +0000 Subject: [PATCH 1/4] [CTS] Add test for blocking property for buffer reads --- .../enqueue/urEnqueueMemBufferRead.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/conformance/enqueue/urEnqueueMemBufferRead.cpp b/test/conformance/enqueue/urEnqueueMemBufferRead.cpp index 6410d6feed..2693205793 100644 --- a/test/conformance/enqueue/urEnqueueMemBufferRead.cpp +++ b/test/conformance/enqueue/urEnqueueMemBufferRead.cpp @@ -65,6 +65,63 @@ TEST_P(urEnqueueMemBufferReadTest, InvalidSize) { nullptr)); } +TEST_P(urEnqueueMemBufferReadTest, Blocking) { + constexpr const size_t memSize = 10u; + constexpr const size_t bytes = memSize * sizeof(int); + const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int output[memSize] = {}; + + ur_mem_handle_t memObj; + ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, bytes, + nullptr, &memObj)); + + ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, memObj, true, 0, bytes, data, + 0, nullptr, nullptr)); + + ASSERT_SUCCESS(urEnqueueMemBufferRead(queue, memObj, true, 0, bytes, output, + 0, nullptr, nullptr)); + + bool isSame = + std::equal(std::begin(output), std::end(output), std::begin(data)); + EXPECT_TRUE(isSame); + if (!isSame) { + std::for_each(std::begin(output), std::end(output), + [](int &elem) { std::cout << elem << ","; }); + std::cout << std::endl; + } +} + +TEST_P(urEnqueueMemBufferReadTest, NonBlocking) { + constexpr const size_t memSize = 10u; + constexpr const size_t bytes = memSize * sizeof(int); + const int data[memSize] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int output[memSize] = {}; + + ur_mem_handle_t memObj; + ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, bytes, + nullptr, &memObj)); + + ur_event_handle_t cpIn, cpOut; + ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, memObj, false, 0, bytes, data, + 0, nullptr, &cpIn)); + ASSERT_NE(cpIn, nullptr); + + ASSERT_SUCCESS(urEnqueueMemBufferRead(queue, memObj, false, 0, bytes, + output, 0, nullptr, &cpOut)); + ASSERT_NE(cpOut, nullptr); + + ASSERT_SUCCESS(urEventWait(1, &cpOut)); + + bool isSame = + std::equal(std::begin(output), std::end(output), std::begin(data)); + EXPECT_TRUE(isSame); + if (!isSame) { + std::for_each(std::begin(output), std::end(output), + [](int &elem) { std::cout << elem << ","; }); + std::cout << std::endl; + } +} + using urEnqueueMemBufferReadMultiDeviceTest = uur::urMultiDeviceMemBufferQueueTest; From 4db517d9c68947751bb38b75ab869a620b4a90cf Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Fri, 19 Jan 2024 19:17:51 +0000 Subject: [PATCH 2/4] [CTS] Run buffer creation tests for all flags --- .../memory/memory_adapter_level_zero.match | 2 +- test/conformance/memory/urMemBufferCreate.cpp | 48 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/test/conformance/memory/memory_adapter_level_zero.match b/test/conformance/memory/memory_adapter_level_zero.match index ff51b24b4b..e51b8ea018 100644 --- a/test/conformance/memory/memory_adapter_level_zero.match +++ b/test/conformance/memory/memory_adapter_level_zero.match @@ -1,4 +1,4 @@ -urMemBufferCreateTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidBufferSize/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ diff --git a/test/conformance/memory/urMemBufferCreate.cpp b/test/conformance/memory/urMemBufferCreate.cpp index 995601b985..f25c5236c1 100644 --- a/test/conformance/memory/urMemBufferCreate.cpp +++ b/test/conformance/memory/urMemBufferCreate.cpp @@ -4,24 +4,35 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include -using urMemBufferCreateTest = uur::urContextTest; -UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateTest); +using urMemBufferCreateTestWithFlagsParam = + uur::urContextTestWithParam; -TEST_P(urMemBufferCreateTest, Success) { +using urMemBufferCreateWithFlagsTest = urMemBufferCreateTestWithFlagsParam; +UUR_TEST_SUITE_P(urMemBufferCreateWithFlagsTest, + ::testing::Values(UR_MEM_FLAG_READ_WRITE, + UR_MEM_FLAG_WRITE_ONLY, + UR_MEM_FLAG_READ_ONLY, + UR_MEM_FLAG_ALLOC_HOST_POINTER), + uur::deviceTestWithParamPrinter); + +TEST_P(urMemBufferCreateWithFlagsTest, Success) { ur_mem_handle_t buffer = nullptr; - ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, 4096, - nullptr, &buffer)); + ASSERT_SUCCESS( + urMemBufferCreate(context, getParam(), 4096, nullptr, &buffer)); ASSERT_NE(nullptr, buffer); ASSERT_SUCCESS(urMemRelease(buffer)); } -TEST_P(urMemBufferCreateTest, InvalidNullHandleContext) { +TEST_P(urMemBufferCreateWithFlagsTest, InvalidNullHandleContext) { ur_mem_handle_t buffer = nullptr; - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urMemBufferCreate(nullptr, UR_MEM_FLAG_READ_WRITE, 4096, - nullptr, &buffer)); + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urMemBufferCreate(nullptr, getParam(), 4096, nullptr, &buffer)); } +using urMemBufferCreateTest = uur::urContextTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateTest); + TEST_P(urMemBufferCreateTest, InvalidEnumerationFlags) { ur_mem_handle_t buffer = nullptr; ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION, @@ -29,9 +40,6 @@ TEST_P(urMemBufferCreateTest, InvalidEnumerationFlags) { nullptr, &buffer)); } -using urMemBufferCreateTestWithFlagsParam = - uur::urContextTestWithParam; - using urMemBufferCreateWithHostPtrFlagsTest = urMemBufferCreateTestWithFlagsParam; UUR_TEST_SUITE_P(urMemBufferCreateWithHostPtrFlagsTest, @@ -46,15 +54,15 @@ TEST_P(urMemBufferCreateWithHostPtrFlagsTest, InvalidHostPtr) { urMemBufferCreate(context, getParam(), 4096, nullptr, &buffer)); } -TEST_P(urMemBufferCreateTest, InvalidNullPointerBuffer) { - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER, - urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, 4096, - nullptr, nullptr)); +TEST_P(urMemBufferCreateWithFlagsTest, InvalidNullPointerBuffer) { + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_POINTER, + urMemBufferCreate(context, getParam(), 4096, nullptr, nullptr)); } -TEST_P(urMemBufferCreateTest, InvalidBufferSizeZero) { +TEST_P(urMemBufferCreateWithFlagsTest, InvalidBufferSizeZero) { ur_mem_handle_t buffer = nullptr; - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_BUFFER_SIZE, - urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, 0, - nullptr, &buffer)); + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_BUFFER_SIZE, + urMemBufferCreate(context, getParam(), 0, nullptr, &buffer)); } From c7bf3d6f422da6462ab9fa8e82c2d53bd1d1e3ed Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Mon, 22 Jan 2024 18:03:20 +0000 Subject: [PATCH 3/4] [CTS] Add mapping tests for host alloc --- .../enqueue/urEnqueueMemBufferMap.cpp | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/conformance/enqueue/urEnqueueMemBufferMap.cpp b/test/conformance/enqueue/urEnqueueMemBufferMap.cpp index fc44360c22..431189464a 100644 --- a/test/conformance/enqueue/urEnqueueMemBufferMap.cpp +++ b/test/conformance/enqueue/urEnqueueMemBufferMap.cpp @@ -99,6 +99,57 @@ TEST_P(urEnqueueMemBufferMapTest, SuccessPartialMap) { } } +TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedRead) { + const size_t memSize = sizeof(int); + const int value = 20; + + ur_mem_handle_t memObj; + ASSERT_SUCCESS(urMemBufferCreate( + context, UR_MEM_FLAG_READ_WRITE | UR_MEM_FLAG_ALLOC_HOST_POINTER, + memSize, nullptr, &memObj)); + + ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, memObj, true, 0, sizeof(int), + &value, 0, nullptr, nullptr)); + + int *host_ptr = nullptr; + ASSERT_SUCCESS(urEnqueueMemBufferMap(queue, memObj, true, UR_MAP_FLAG_READ, + 0, sizeof(int), 0, nullptr, nullptr, + (void **)&host_ptr)); + + ASSERT_EQ(*host_ptr, value); + ASSERT_SUCCESS( + urEnqueueMemUnmap(queue, memObj, host_ptr, 0, nullptr, nullptr)); + + ASSERT_SUCCESS(urMemRelease(memObj)); +} + +TEST_P(urEnqueueMemBufferMapTest, SuccesPinnedWrite) { + const size_t memSize = sizeof(int); + const int value = 30; + + ur_mem_handle_t memObj; + ASSERT_SUCCESS(urMemBufferCreate( + context, UR_MEM_FLAG_READ_WRITE | UR_MEM_FLAG_ALLOC_HOST_POINTER, + memSize, nullptr, &memObj)); + + int *host_ptr = nullptr; + ASSERT_SUCCESS(urEnqueueMemBufferMap(queue, memObj, true, UR_MAP_FLAG_WRITE, + 0, sizeof(int), 0, nullptr, nullptr, + (void **)&host_ptr)); + + *host_ptr = value; + + ASSERT_SUCCESS( + urEnqueueMemUnmap(queue, memObj, host_ptr, 0, nullptr, nullptr)); + + int read_value = 0; + ASSERT_SUCCESS(urEnqueueMemBufferRead(queue, memObj, true, 0, sizeof(int), + &read_value, 0, nullptr, nullptr)); + + ASSERT_EQ(read_value, value); + ASSERT_SUCCESS(urMemRelease(memObj)); +} + TEST_P(urEnqueueMemBufferMapTest, SuccessMultiMaps) { const std::vector input(count, 0); ASSERT_SUCCESS(urEnqueueMemBufferWrite(queue, buffer, true, 0, size, From 6eb886ee0942c9b809da738c1077924be5eb709a Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Tue, 23 Jan 2024 18:03:36 +0000 Subject: [PATCH 4/4] [CTS] Match create buffer with flags tests individually Co-authored-by: Kenneth Benzie (Benie) --- test/conformance/memory/memory_adapter_level_zero.match | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/conformance/memory/memory_adapter_level_zero.match b/test/conformance/memory/memory_adapter_level_zero.match index e51b8ea018..9aebbe1c67 100644 --- a/test/conformance/memory/memory_adapter_level_zero.match +++ b/test/conformance/memory/memory_adapter_level_zero.match @@ -1,4 +1,7 @@ -urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_READ_WRITE +urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_WRITE_ONLY +urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_READ_ONLY +urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_ALLOC_HOST_POINTER urMemBufferPartitionTest.InvalidBufferSize/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_