From 213bce7356f0f1d68e864309af35df6bae6fd4f9 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 | 3 +++ include/ur_print.hpp | 16 ++++++++++++++++ scripts/core/device.yml | 2 ++ source/adapters/cuda/device.cpp | 4 +++- 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, 43 insertions(+), 8 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index 764391527f..79dd7d5503 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -2193,6 +2193,9 @@ typedef enum ur_device_info_t { /// [::ur_bool_t] support the ::urProgramSetSpecializationConstants entry /// point UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 121, + /// [::ur_bool_t] return true if the device has a native assert + /// implementation. + UR_DEVICE_INFO_USE_NATIVE_ASSERT = 122, /// [::ur_bool_t] Returns true if the device supports the use of /// command-buffers. UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000, diff --git a/include/ur_print.hpp b/include/ur_print.hpp index 5c5f573477..71728dbd19 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -2876,6 +2876,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) { case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS: os << "UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS"; 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; @@ -4533,6 +4536,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, 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 c1fb313fb3..686849c71b 100644 --- a/scripts/core/device.yml +++ b/scripts/core/device.yml @@ -447,6 +447,8 @@ etors: desc: "[uint32_t] the number of compute units for specific backend." - name: PROGRAM_SET_SPECIALIZATION_CONSTANTS desc: "[$x_bool_t] support the $xProgramSetSpecializationConstants entry point" + - 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 3e0ce05c27..2b14e0446e 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -617,7 +617,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 "; @@ -1114,6 +1113,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_LOW_POWER_EVENTS_EXP: return ReturnValue(false); + 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 a472648793..c7f792120d 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -557,12 +557,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; @@ -968,6 +963,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_LOW_POWER_EVENTS_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 e6a73a378e..0f076d34e8 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -1198,6 +1198,8 @@ ur_result_t urDeviceGetInfo( return ReturnValue(false); case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: return ReturnValue(false); + 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 6deca1ac37..bf2e035191 100644 --- a/source/adapters/native_cpu/device.cpp +++ b/source/adapters/native_cpu/device.cpp @@ -426,6 +426,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); case UR_DEVICE_INFO_LOW_POWER_EVENTS_EXP: return ReturnValue(false); diff --git a/source/adapters/opencl/device.cpp b/source/adapters/opencl/device.cpp index 1267b2e941..bad1e92818 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -1227,6 +1227,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, return ReturnValue(false); case UR_DEVICE_INFO_LOW_POWER_EVENTS_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 8c6ea452dc..6e4b11615d 100644 --- a/test/conformance/device/urDeviceGetInfo.cpp +++ b/test/conformance/device/urDeviceGetInfo.cpp @@ -129,7 +129,8 @@ static std::unordered_map device_info_size_map = { {UR_DEVICE_INFO_ESIMD_SUPPORT, sizeof(ur_bool_t)}, {UR_DEVICE_INFO_IP_VERSION, sizeof(uint32_t)}, {UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, sizeof(ur_bool_t)}, - {UR_DEVICE_INFO_NUM_COMPUTE_UNITS, sizeof(uint32_t)}}; + {UR_DEVICE_INFO_NUM_COMPUTE_UNITS, sizeof(uint32_t)}, + {UR_DEVICE_INFO_USE_NATIVE_ASSERT, sizeof(ur_bool_t)}}; using urDeviceGetInfoTest = uur::urDeviceTestWithParam; @@ -255,7 +256,8 @@ UUR_DEVICE_TEST_SUITE_WITH_PARAM( UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_HALF, // UR_DEVICE_INFO_PREFERRED_VECTOR_WIDTH_INT, // UR_DEVICE_INFO_NUM_COMPUTE_UNITS, // - UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS // + UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS, // + UR_DEVICE_INFO_USE_NATIVE_ASSERT // ), uur::deviceTestWithParamPrinter); diff --git a/tools/urinfo/urinfo.hpp b/tools/urinfo/urinfo.hpp index d01245138f..048a0f7b2a 100644 --- a/tools/urinfo/urinfo.hpp +++ b/tools/urinfo/urinfo.hpp @@ -332,6 +332,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice, printDeviceInfo( hDevice, UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS); 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;