From 51900aeff9f475b8fbde4b9b5f1f44921705b10e Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Mon, 27 Nov 2023 16:11:47 +0000 Subject: [PATCH 1/2] Clarify spec for QUEUE_INFO_SIZE and change testing for it accordingly. Also correctly report lack of queue on device support in cuda and hip adapters. --- include/ur_api.h | 9 ++- scripts/core/queue.yml | 8 ++- source/adapters/cuda/device.cpp | 5 +- source/adapters/hip/device.cpp | 5 +- source/adapters/opencl/common.cpp | 2 + source/loader/ur_libapi.cpp | 2 +- source/ur_api.cpp | 2 +- .../conformance/queue/queue_adapter_hip.match | 1 - .../queue/queue_adapter_opencl.match | 2 - test/conformance/queue/urQueueGetInfo.cpp | 55 ++++++++++++++++++- 10 files changed, 72 insertions(+), 19 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index 9d88eecbc6..a5a716b05f 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -5250,7 +5250,9 @@ typedef enum ur_queue_info_t { ///< The reference count returned should be considered immediately stale. ///< It is unsuitable for general use in applications. This feature is ///< provided for identifying memory leaks. - UR_QUEUE_INFO_SIZE = 5, ///< [uint32_t] The size of the queue + UR_QUEUE_INFO_SIZE = 5, ///< [uint32_t] The size of the queue on the device. Only a valid query + ///< if the queue was created with the `ON_DEVICE` queue flag, otherwise + ///< `::urQueueGetInfo` will return `::UR_RESULT_ERROR_INVALID_QUEUE`. UR_QUEUE_INFO_EMPTY = 6, ///< [::ur_bool_t] return true if the queue was empty at the time of the ///< query /// @cond @@ -5265,7 +5267,8 @@ typedef uint32_t ur_queue_flags_t; typedef enum ur_queue_flag_t { UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE = UR_BIT(0), ///< Enable/disable out of order execution UR_QUEUE_FLAG_PROFILING_ENABLE = UR_BIT(1), ///< Enable/disable profiling - UR_QUEUE_FLAG_ON_DEVICE = UR_BIT(2), ///< Is a device queue + UR_QUEUE_FLAG_ON_DEVICE = UR_BIT(2), ///< Is a device queue. If this is enabled `OUT_OF_ORDER_EXEC_MODE_ENABLE` + ///< must also be enabled. UR_QUEUE_FLAG_ON_DEVICE_DEFAULT = UR_BIT(3), ///< Is the default queue for a device UR_QUEUE_FLAG_DISCARD_EVENTS = UR_BIT(4), ///< Events will be discarded UR_QUEUE_FLAG_PRIORITY_LOW = UR_BIT(5), ///< Low priority queue @@ -5310,7 +5313,7 @@ typedef enum ur_queue_flag_t { /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `propSize != 0 && pPropValue == NULL` /// + `pPropValue == NULL && pPropSizeRet == NULL` -/// - ::UR_RESULT_ERROR_INVALID_QUEUE +/// - ::UR_RESULT_ERROR_INVALID_QUEUE - "If `hQueue` isn't a valid queue handle or if `propName` isn't supported by `hQueue`." /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES UR_APIEXPORT ur_result_t UR_APICALL diff --git a/scripts/core/queue.yml b/scripts/core/queue.yml index 816da179ba..27e8077ba2 100644 --- a/scripts/core/queue.yml +++ b/scripts/core/queue.yml @@ -32,7 +32,10 @@ etors: The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks. - name: SIZE - desc: "[uint32_t] The size of the queue" + desc: | + [uint32_t] The size of the queue on the device. Only a valid query + if the queue was created with the `ON_DEVICE` queue flag, otherwise + `$xQueueGetInfo` will return `$X_RESULT_ERROR_INVALID_QUEUE`. - name: EMPTY desc: "[$x_bool_t] return true if the queue was empty at the time of the query" --- #-------------------------------------------------------------------------- @@ -49,7 +52,7 @@ etors: desc: "Enable/disable profiling" - name: ON_DEVICE value: "$X_BIT(2)" - desc: "Is a device queue" + desc: "Is a device queue. If this is enabled `OUT_OF_ORDER_EXEC_MODE_ENABLE` must also be enabled." - name: ON_DEVICE_DEFAULT value: "$X_BIT(3)" desc: "Is the default queue for a device" @@ -108,6 +111,7 @@ returns: - "`propSize != 0 && pPropValue == NULL`" - "`pPropValue == NULL && pPropSizeRet == NULL`" - $X_RESULT_ERROR_INVALID_QUEUE + - "If `hQueue` isn't a valid queue handle or if `propName` isn't supported by `hQueue`." - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY - $X_RESULT_ERROR_OUT_OF_RESOURCES --- #-------------------------------------------------------------------------- diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index e6389c5ee2..87c934d246 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -569,10 +569,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, ur_queue_flag_t(UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE | UR_QUEUE_FLAG_PROFILING_ENABLE)); case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES: { - // The mandated minimum capability: - ur_queue_flags_t Capability = UR_QUEUE_FLAG_PROFILING_ENABLE | - UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE; - return ReturnValue(Capability); + return ReturnValue(0); } case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES: { // The mandated minimum capability: diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 9c12cd28bf..bfbbc5e4c9 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -465,10 +465,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, return ReturnValue(Capability); } case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES: { - // The mandated minimum capability: - ur_queue_flags_t Capability = UR_QUEUE_FLAG_PROFILING_ENABLE | - UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE; - return ReturnValue(Capability); + return ReturnValue(0); } case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES: case UR_DEVICE_INFO_QUEUE_PROPERTIES: { diff --git a/source/adapters/opencl/common.cpp b/source/adapters/opencl/common.cpp index 750616235d..d557d3a202 100644 --- a/source/adapters/opencl/common.cpp +++ b/source/adapters/opencl/common.cpp @@ -87,6 +87,8 @@ ur_result_t mapCLErrorToUR(cl_int Result) { return UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE; case CL_INVALID_KERNEL_ARGS: return UR_RESULT_ERROR_INVALID_KERNEL_ARGS; + case CL_INVALID_COMMAND_QUEUE: + return UR_RESULT_ERROR_INVALID_QUEUE; default: return UR_RESULT_ERROR_UNKNOWN; } diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 35e5d68e36..3c22ddd0cc 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -4120,7 +4120,7 @@ ur_result_t UR_APICALL urKernelCreateWithNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `propSize != 0 && pPropValue == NULL` /// + `pPropValue == NULL && pPropSizeRet == NULL` -/// - ::UR_RESULT_ERROR_INVALID_QUEUE +/// - ::UR_RESULT_ERROR_INVALID_QUEUE - "If `hQueue` isn't a valid queue handle or if `propName` isn't supported by `hQueue`." /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES ur_result_t UR_APICALL urQueueGetInfo( diff --git a/source/ur_api.cpp b/source/ur_api.cpp index bf90700e7d..01eed1dc0e 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -3496,7 +3496,7 @@ ur_result_t UR_APICALL urKernelCreateWithNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER /// + `propSize != 0 && pPropValue == NULL` /// + `pPropValue == NULL && pPropSizeRet == NULL` -/// - ::UR_RESULT_ERROR_INVALID_QUEUE +/// - ::UR_RESULT_ERROR_INVALID_QUEUE - "If `hQueue` isn't a valid queue handle or if `propName` isn't supported by `hQueue`." /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES ur_result_t UR_APICALL urQueueGetInfo( diff --git a/test/conformance/queue/queue_adapter_hip.match b/test/conformance/queue/queue_adapter_hip.match index d39b30aa73..bb4055ab17 100644 --- a/test/conformance/queue/queue_adapter_hip.match +++ b/test/conformance/queue/queue_adapter_hip.match @@ -1,2 +1 @@ urQueueGetInfoTestWithInfoParam.Success/AMD_HIP_BACKEND___{{.*}}___UR_QUEUE_INFO_DEVICE_DEFAULT -urQueueGetInfoTestWithInfoParam.Success/AMD_HIP_BACKEND___{{.*}}___UR_QUEUE_INFO_SIZE diff --git a/test/conformance/queue/queue_adapter_opencl.match b/test/conformance/queue/queue_adapter_opencl.match index a374e0b4b1..e69de29bb2 100644 --- a/test/conformance/queue/queue_adapter_opencl.match +++ b/test/conformance/queue/queue_adapter_opencl.match @@ -1,2 +0,0 @@ -urQueueGetInfoTestWithInfoParam.Success/Intel_R__OpenCL___{{.*}}___UR_QUEUE_INFO_DEVICE_DEFAULT -urQueueGetInfoTestWithInfoParam.Success/Intel_R__OpenCL___{{.*}}___UR_QUEUE_INFO_SIZE diff --git a/test/conformance/queue/urQueueGetInfo.cpp b/test/conformance/queue/urQueueGetInfo.cpp index 9704c72f64..686bf45656 100644 --- a/test/conformance/queue/urQueueGetInfo.cpp +++ b/test/conformance/queue/urQueueGetInfo.cpp @@ -23,7 +23,7 @@ UUR_TEST_SUITE_P(urQueueGetInfoTestWithInfoParam, UR_QUEUE_INFO_DEVICE_DEFAULT, UR_QUEUE_INFO_FLAGS, UR_QUEUE_INFO_REFERENCE_COUNT, - UR_QUEUE_INFO_SIZE, UR_QUEUE_INFO_EMPTY), + UR_QUEUE_INFO_EMPTY), uur::deviceTestWithParamPrinter); TEST_P(urQueueGetInfoTestWithInfoParam, Success) { @@ -70,6 +70,59 @@ TEST_P(urQueueGetInfoTestWithInfoParam, Success) { } } +struct urQueueGetInfoDeviceQueueTestWithInfoParam + : public uur::urContextTestWithParam { + void SetUp() { + urContextTestWithParam::SetUp(); + ur_queue_flags_t deviceQueueCapabilities; + ASSERT_SUCCESS( + urDeviceGetInfo(device, UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES, + sizeof(deviceQueueCapabilities), + &deviceQueueCapabilities, nullptr)); + if (!deviceQueueCapabilities) { + GTEST_SKIP() << "Queue on device is not supported."; + } + ASSERT_SUCCESS( + urQueueCreate(context, device, &queueProperties, &queue)); + } + + void TearDown() { + if (queue) { + ASSERT_SUCCESS(urQueueRelease(queue)); + } + urContextTestWithParam::TearDown(); + } + + ur_queue_handle_t queue = nullptr; + ur_queue_properties_t queueProperties = { + UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr, + UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE}; +}; + +UUR_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam, + ::testing::Values(UR_QUEUE_INFO_CONTEXT, UR_QUEUE_INFO_DEVICE, + UR_QUEUE_INFO_DEVICE_DEFAULT, + UR_QUEUE_INFO_FLAGS, + UR_QUEUE_INFO_REFERENCE_COUNT, + UR_QUEUE_INFO_SIZE, UR_QUEUE_INFO_EMPTY), + uur::deviceTestWithParamPrinter); + +TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Success) { + ur_queue_info_t info_type = getParam(); + size_t size = 0; + ASSERT_SUCCESS(urQueueGetInfo(queue, info_type, 0, nullptr, &size)); + ASSERT_NE(size, 0); + + if (const auto expected_size = queue_info_size_map.find(info_type); + expected_size != queue_info_size_map.end()) { + ASSERT_EQ(expected_size->second, size); + } + + std::vector data(size); + ASSERT_SUCCESS( + urQueueGetInfo(queue, info_type, size, data.data(), nullptr)); +} + using urQueueGetInfoTest = uur::urQueueTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest); From 41763be14086cb43eb25179af5eff40599b3f87b Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Wed, 8 May 2024 16:15:47 +0100 Subject: [PATCH 2/2] Only test DEVICE_DEFAULT query when queue is device default. Some supported CL drivers return an error rather than NULL if you try this query on a queue that wasn't created with the ON_DEVICE and DEVICE_DEFAULT flags. This isn't correct according to the CL spec but limiting our testing to the supported case is still preferable to adding an exception to the match files. --- .../conformance/queue/queue_adapter_hip.match | 1 - .../queue/queue_adapter_native_cpu.match | 9 +++++-- test/conformance/queue/urQueueGetInfo.cpp | 27 +++++++++++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/test/conformance/queue/queue_adapter_hip.match b/test/conformance/queue/queue_adapter_hip.match index bb4055ab17..e69de29bb2 100644 --- a/test/conformance/queue/queue_adapter_hip.match +++ b/test/conformance/queue/queue_adapter_hip.match @@ -1 +0,0 @@ -urQueueGetInfoTestWithInfoParam.Success/AMD_HIP_BACKEND___{{.*}}___UR_QUEUE_INFO_DEVICE_DEFAULT diff --git a/test/conformance/queue/queue_adapter_native_cpu.match b/test/conformance/queue/queue_adapter_native_cpu.match index a4c2c502a4..90bc25b23b 100644 --- a/test/conformance/queue/queue_adapter_native_cpu.match +++ b/test/conformance/queue/queue_adapter_native_cpu.match @@ -26,11 +26,16 @@ urQueueFinishTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urQueueFlushTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_CONTEXT urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_DEVICE -urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_DEVICE_DEFAULT urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_FLAGS urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_REFERENCE_COUNT -urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_SIZE urQueueGetInfoTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_EMPTY +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_CONTEXT +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_DEVICE +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_DEVICE_DEFAULT +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_FLAGS +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_REFERENCE_COUNT +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_SIZE +urQueueGetInfoDeviceQueueTestWithInfoParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_QUEUE_INFO_EMPTY urQueueGetInfoTest.InvalidSizeSmall/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urQueueRetainTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urQueueReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU_ diff --git a/test/conformance/queue/urQueueGetInfo.cpp b/test/conformance/queue/urQueueGetInfo.cpp index 686bf45656..9ffb97e1ff 100644 --- a/test/conformance/queue/urQueueGetInfo.cpp +++ b/test/conformance/queue/urQueueGetInfo.cpp @@ -20,7 +20,6 @@ using urQueueGetInfoTestWithInfoParam = UUR_TEST_SUITE_P(urQueueGetInfoTestWithInfoParam, ::testing::Values(UR_QUEUE_INFO_CONTEXT, UR_QUEUE_INFO_DEVICE, - UR_QUEUE_INFO_DEVICE_DEFAULT, UR_QUEUE_INFO_FLAGS, UR_QUEUE_INFO_REFERENCE_COUNT, UR_QUEUE_INFO_EMPTY), @@ -96,7 +95,8 @@ struct urQueueGetInfoDeviceQueueTestWithInfoParam ur_queue_handle_t queue = nullptr; ur_queue_properties_t queueProperties = { UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr, - UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE}; + UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_ON_DEVICE_DEFAULT | + UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE}; }; UUR_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam, @@ -110,17 +110,22 @@ UUR_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam, TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Success) { ur_queue_info_t info_type = getParam(); size_t size = 0; - ASSERT_SUCCESS(urQueueGetInfo(queue, info_type, 0, nullptr, &size)); - ASSERT_NE(size, 0); + auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size); - if (const auto expected_size = queue_info_size_map.find(info_type); - expected_size != queue_info_size_map.end()) { - ASSERT_EQ(expected_size->second, size); - } + if (result == UR_RESULT_SUCCESS) { + ASSERT_NE(size, 0); + + if (const auto expected_size = queue_info_size_map.find(info_type); + expected_size != queue_info_size_map.end()) { + ASSERT_EQ(expected_size->second, size); + } - std::vector data(size); - ASSERT_SUCCESS( - urQueueGetInfo(queue, info_type, size, data.data(), nullptr)); + std::vector data(size); + ASSERT_SUCCESS( + urQueueGetInfo(queue, info_type, size, data.data(), nullptr)); + } else { + ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION); + } } using urQueueGetInfoTest = uur::urQueueTest;