From 6a711b3838997332011071c7240201888e23f79e Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Wed, 30 Oct 2024 16:51:21 +0000 Subject: [PATCH] Add device info query to report support for native asserts. This allows cuda and hip to stop reporting the relevant opencl extension string, see issue #1374 --- include/ur_api.h | 2 ++ include/ur_print.hpp | 15 +++++++++++++++ scripts/core/device.yml | 2 ++ source/adapters/cuda/device.cpp | 3 ++- source/adapters/hip/device.cpp | 7 ++----- source/adapters/level_zero/device.cpp | 2 ++ source/adapters/native_cpu/device.cpp | 2 ++ source/adapters/opencl/device.cpp | 7 +++++++ test/conformance/device/urDeviceGetInfo.cpp | 6 ++++-- tools/urinfo/urinfo.hpp | 2 ++ 10 files changed, 40 insertions(+), 8 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index 60d6fc2f70..03774a1d68 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -1642,6 +1642,8 @@ typedef enum ur_device_info_t { UR_DEVICE_INFO_USM_POOL_SUPPORT = 119, ///< [::ur_bool_t] return true if the device supports USM pooling. Pertains ///< to the `USMPool` entry points and usage of the `pool` parameter of the ///< USM alloc entry points. + UR_DEVICE_INFO_USE_NATIVE_ASSERT = 120, ///< [::ur_bool_t] return true if the device has a native assert + ///< implementation. UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000, ///< [::ur_bool_t] Returns true if the device supports the use of ///< command-buffers. UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP = 0x1001, ///< [::ur_device_command_buffer_update_capability_flags_t] Command-buffer diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 09431d4352..d52e8f8fb3 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -2553,6 +2553,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) { case UR_DEVICE_INFO_USM_POOL_SUPPORT: os << "UR_DEVICE_INFO_USM_POOL_SUPPORT"; break; + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: + os << "UR_DEVICE_INFO_USE_NATIVE_ASSERT"; + break; case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP"; break; @@ -4067,6 +4070,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info os << ")"; } break; + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: { + const ur_bool_t *tptr = (const ur_bool_t *)ptr; + if (sizeof(ur_bool_t) > size) { + os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_bool_t) << ")"; + return UR_RESULT_ERROR_INVALID_SIZE; + } + os << (const void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: { const ur_bool_t *tptr = (const ur_bool_t *)ptr; if (sizeof(ur_bool_t) > size) { diff --git a/scripts/core/device.yml b/scripts/core/device.yml index c430ff0b36..fe21c18e86 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -443,6 +443,8 @@ etors: desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` entry points." - name: USM_POOL_SUPPORT desc: "[$x_bool_t] return true if the device supports USM pooling. Pertains to the `USMPool` entry points and usage of the `pool` parameter of the USM alloc entry points." + - name: USE_NATIVE_ASSERT + desc: "[$x_bool_t] return true if the device has a native assert implementation." --- #-------------------------------------------------------------------------- type: function desc: "Retrieves various information about device" diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index be5867628d..2631f9d1fb 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -616,7 +616,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_EXTENSIONS: { std::string SupportedExtensions = "cl_khr_fp64 cl_khr_subgroups "; - SupportedExtensions += "cl_intel_devicelib_assert "; // Return supported for the UR command-buffer experimental feature SupportedExtensions += "ur_exp_command_buffer "; SupportedExtensions += "ur_exp_usm_p2p "; @@ -1107,6 +1106,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >= 9; return ReturnValue(static_cast(Value)); } + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: + return ReturnValue(true); default: break; diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index dbac5d37f1..8a9803e413 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -543,12 +543,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, return ReturnValue(""); } case UR_DEVICE_INFO_EXTENSIONS: { - // TODO: Remove comment when HIP support native asserts. - // DEVICELIB_ASSERT extension is set so fallback assert - // postprocessing is NOP. HIP 4.3 docs indicate support for - // native asserts are in progress std::string SupportedExtensions = ""; - SupportedExtensions += "cl_intel_devicelib_assert "; SupportedExtensions += "ur_exp_usm_p2p "; int RuntimeVersion = 0; @@ -935,6 +930,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_COMMAND_BUFFER_EVENT_SUPPORT_EXP: return ReturnValue(false); + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: + return ReturnValue(true); default: break; } diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index 94dad86070..a92b189d20 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -1151,6 +1151,8 @@ ur_result_t urDeviceGetInfo( return ReturnValue(true); case UR_DEVICE_INFO_USM_POOL_SUPPORT: return ReturnValue(true); + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: + return ReturnValue(false); default: logger::error("Unsupported ParamName in urGetDeviceInfo"); logger::error("ParamNameParamName={}(0x{})", ParamName, diff --git a/source/adapters/native_cpu/device.cpp b/source/adapters/native_cpu/device.cpp index d744d6290b..912c5da9b5 100644 --- a/source/adapters/native_cpu/device.cpp +++ b/source/adapters/native_cpu/device.cpp @@ -416,6 +416,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_USM_POOL_SUPPORT: return ReturnValue(false); + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: + return ReturnValue(false); default: DIE_NO_IMPLEMENTATION; diff --git a/source/adapters/opencl/device.cpp b/source/adapters/opencl/device.cpp index e17211826f..3cc42c097c 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -1119,6 +1119,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_COMMAND_BUFFER_EVENT_SUPPORT_EXP: return ReturnValue(false); + case UR_DEVICE_INFO_USE_NATIVE_ASSERT: { + bool Supported = false; + UR_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions( + cl_adapter::cast(hDevice), {"cl_intel_devicelib_assert"}, + Supported)); + return ReturnValue(Supported); + } default: { return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/test/conformance/device/urDeviceGetInfo.cpp b/test/conformance/device/urDeviceGetInfo.cpp index e41cff97ed..af8f5358b0 100644 --- a/test/conformance/device/urDeviceGetInfo.cpp +++ b/test/conformance/device/urDeviceGetInfo.cpp @@ -115,7 +115,8 @@ static std::unordered_map device_info_size_map = { {UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, sizeof(uint32_t)}, {UR_DEVICE_INFO_COMPONENT_DEVICES, sizeof(uint32_t)}, {UR_DEVICE_INFO_COMPOSITE_DEVICE, sizeof(ur_device_handle_t)}, - {UR_DEVICE_INFO_USM_POOL_SUPPORT, sizeof(ur_bool_t)}}; + {UR_DEVICE_INFO_USM_POOL_SUPPORT, sizeof(ur_bool_t)}, + {UR_DEVICE_INFO_USE_NATIVE_ASSERT, sizeof(ur_bool_t)}}; struct urDeviceGetInfoTest : uur::urAllDevicesTest, ::testing::WithParamInterface { @@ -237,7 +238,8 @@ INSTANTIATE_TEST_SUITE_P( UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, // UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, // UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS, // - UR_DEVICE_INFO_USM_POOL_SUPPORT // + UR_DEVICE_INFO_USM_POOL_SUPPORT, // + UR_DEVICE_INFO_USE_NATIVE_ASSERT // ), [](const ::testing::TestParamInfo &info) { std::stringstream ss; diff --git a/tools/urinfo/urinfo.hpp b/tools/urinfo/urinfo.hpp index d949b1f5df..0bc8828cd0 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -333,6 +333,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice, std::cout << prefix; printDeviceInfo(hDevice, UR_DEVICE_INFO_USM_POOL_SUPPORT); std::cout << prefix; + printDeviceInfo(hDevice, UR_DEVICE_INFO_USE_NATIVE_ASSERT); + std::cout << prefix; printDeviceInfo(hDevice, UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP); std::cout << prefix;