From d5f06df7b4e9afe605a419f80108817cdc02b766 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 | 8 +++++++- source/adapters/hip/device.cpp | 13 ++++++++----- source/adapters/level_zero/device.cpp | 2 ++ source/adapters/native_cpu/device.cpp | 3 +++ source/adapters/opencl/device.cpp | 7 +++++++ test/conformance/device/urDeviceGetInfo.cpp | 5 +++-- tools/urinfo/urinfo.hpp | 2 ++ 10 files changed, 51 insertions(+), 8 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index db1c47b2d5..ed55eb2289 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -1639,6 +1639,8 @@ typedef enum ur_device_info_t { UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT = 118, ///< [::ur_bool_t] return true if the device supports the ///< `EnqueueDeviceGlobalVariableWrite` and ///< `EnqueueDeviceGlobalVariableRead` entry points. + UR_DEVICE_INFO_USE_NATIVE_ASSERT = 119, ///< [::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 0439a12642..87d271e3f1 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -2550,6 +2550,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) { case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT: os << "UR_DEVICE_INFO_GLOBAL_VARIABLE_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; @@ -4052,6 +4055,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 6641d8bb2b..824ac640ac 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -441,6 +441,8 @@ etors: desc: "[$x_device_handle_t] The composite device containing this component device." - name: GLOBAL_VARIABLE_SUPPORT desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` 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 ea7c4da8ec..c6ecf36292 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 "; @@ -1105,6 +1104,13 @@ 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: + // CUDA doesn't actually support asserts natively so this results in + // asserts being a NOP. We report support to avoid fallback assert + // implementations which may be incompatible. + // See https://github.com/intel/llvm/pull/4604 for discussion of the + // original iteration of this workaround. + return ReturnValue(true); default: break; diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 5d6ca49e97..ac7d0ec3d3 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; @@ -933,6 +928,14 @@ 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: + // TODO: Remove comment when HIP supports native asserts. + // HIP doesn't actually support native asserts yet, we report support to + // avoid incompatible fallback assert implementations. HIP 4.3 docs + // indicate support for native asserts are in progress + // See https://github.com/intel/llvm/pull/4604 for discussion of the + // original iteration of this workaround. + return ReturnValue(true); default: break; } diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index 269575a927..bc209334bb 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -1149,6 +1149,8 @@ ur_result_t urDeviceGetInfo( return ReturnValue(false); case UR_DEVICE_INFO_GLOBAL_VARIABLE_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 2a829a82e1..e528cce4c7 100644 --- a/source/adapters/native_cpu/device.cpp +++ b/source/adapters/native_cpu/device.cpp @@ -414,6 +414,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_ENQUEUE_NATIVE_COMMAND_SUPPORT_EXP: 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 4c83e08fa0..f771dc1d2c 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -1114,6 +1114,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 14fedf728f..2f0693653f 100644 --- a/test/conformance/device/urDeviceGetInfo.cpp +++ b/test/conformance/device/urDeviceGetInfo.cpp @@ -115,7 +115,7 @@ 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_USE_NATIVE_ASSERT, sizeof(ur_bool_t)}}; struct urDeviceGetInfoTest : uur::urAllDevicesTest, ::testing::WithParamInterface { @@ -236,7 +236,8 @@ INSTANTIATE_TEST_SUITE_P( UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED, // UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, // UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, // - UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS // + UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS, // + 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 e4e0cdb696..9bc7fb768d 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -331,6 +331,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice, std::cout << prefix; printDeviceInfo(hDevice, UR_DEVICE_INFO_GLOBAL_VARIABLE_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;