Skip to content

Commit b38264f

Browse files
committed
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
1 parent 73e54a0 commit b38264f

File tree

10 files changed

+51
-8
lines changed

10 files changed

+51
-8
lines changed

include/ur_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,8 @@ typedef enum ur_device_info_t {
16391639
UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT = 118, ///< [::ur_bool_t] return true if the device supports the
16401640
///< `EnqueueDeviceGlobalVariableWrite` and
16411641
///< `EnqueueDeviceGlobalVariableRead` entry points.
1642+
UR_DEVICE_INFO_USE_NATIVE_ASSERT = 119, ///< [::ur_bool_t] return true if the device has a native assert
1643+
///< implementation.
16421644
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000, ///< [::ur_bool_t] Returns true if the device supports the use of
16431645
///< command-buffers.
16441646
UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP = 0x1001, ///< [::ur_device_command_buffer_update_capability_flags_t] Command-buffer

include/ur_print.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
25502550
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
25512551
os << "UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT";
25522552
break;
2553+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
2554+
os << "UR_DEVICE_INFO_USE_NATIVE_ASSERT";
2555+
break;
25532556
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
25542557
os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP";
25552558
break;
@@ -4052,6 +4055,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
40524055

40534056
os << ")";
40544057
} break;
4058+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT: {
4059+
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
4060+
if (sizeof(ur_bool_t) > size) {
4061+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_bool_t) << ")";
4062+
return UR_RESULT_ERROR_INVALID_SIZE;
4063+
}
4064+
os << (const void *)(tptr) << " (";
4065+
4066+
os << *tptr;
4067+
4068+
os << ")";
4069+
} break;
40554070
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
40564071
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
40574072
if (sizeof(ur_bool_t) > size) {

scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ etors:
441441
desc: "[$x_device_handle_t] The composite device containing this component device."
442442
- name: GLOBAL_VARIABLE_SUPPORT
443443
desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` entry points."
444+
- name: USE_NATIVE_ASSERT
445+
desc: "[$x_bool_t] return true if the device has a native assert implementation."
444446
--- #--------------------------------------------------------------------------
445447
type: function
446448
desc: "Retrieves various information about device"

source/adapters/cuda/device.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
616616
case UR_DEVICE_INFO_EXTENSIONS: {
617617

618618
std::string SupportedExtensions = "cl_khr_fp64 cl_khr_subgroups ";
619-
SupportedExtensions += "cl_intel_devicelib_assert ";
620619
// Return supported for the UR command-buffer experimental feature
621620
SupportedExtensions += "ur_exp_command_buffer ";
622621
SupportedExtensions += "ur_exp_usm_p2p ";
@@ -1105,6 +1104,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11051104
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR) >= 9;
11061105
return ReturnValue(static_cast<bool>(Value));
11071106
}
1107+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
1108+
// CUDA doesn't actually support asserts natively so this results in
1109+
// asserts being a NOP. We report support to avoid fallback assert
1110+
// implementations which may be incompatible.
1111+
// See https://github.com/intel/llvm/pull/4604 for discussion of the
1112+
// original iteration of this workaround.
1113+
return ReturnValue(true);
11081114

11091115
default:
11101116
break;

source/adapters/hip/device.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
543543
return ReturnValue("");
544544
}
545545
case UR_DEVICE_INFO_EXTENSIONS: {
546-
// TODO: Remove comment when HIP support native asserts.
547-
// DEVICELIB_ASSERT extension is set so fallback assert
548-
// postprocessing is NOP. HIP 4.3 docs indicate support for
549-
// native asserts are in progress
550546
std::string SupportedExtensions = "";
551-
SupportedExtensions += "cl_intel_devicelib_assert ";
552547
SupportedExtensions += "ur_exp_usm_p2p ";
553548

554549
int RuntimeVersion = 0;
@@ -933,6 +928,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
933928
}
934929
case UR_DEVICE_INFO_COMMAND_BUFFER_EVENT_SUPPORT_EXP:
935930
return ReturnValue(false);
931+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
932+
// TODO: Remove comment when HIP support native asserts.
933+
// HIP doesn't actually support native asserts yet, we report support to
934+
// avoid incompatible fallback assert implementations. HIP 4.3 docs
935+
// indicate support for native asserts are in progress
936+
// See https://github.com/intel/llvm/pull/4604 for discussion of the
937+
// original iteration of this workaround.
938+
return ReturnValue(true);
936939
default:
937940
break;
938941
}

source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,8 @@ ur_result_t urDeviceGetInfo(
11551155
return ReturnValue(false);
11561156
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
11571157
return ReturnValue(true);
1158+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
1159+
return ReturnValue(false);
11581160
default:
11591161
logger::error("Unsupported ParamName in urGetDeviceInfo");
11601162
logger::error("ParamNameParamName={}(0x{})", ParamName,

source/adapters/native_cpu/device.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
414414
case UR_DEVICE_INFO_ENQUEUE_NATIVE_COMMAND_SUPPORT_EXP:
415415
return ReturnValue(false);
416416

417+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
418+
return ReturnValue(false);
419+
417420
default:
418421
DIE_NO_IMPLEMENTATION;
419422
}

source/adapters/opencl/device.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10941094
}
10951095
case UR_DEVICE_INFO_COMMAND_BUFFER_EVENT_SUPPORT_EXP:
10961096
return ReturnValue(false);
1097+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT: {
1098+
bool Supported = false;
1099+
UR_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
1100+
cl_adapter::cast<cl_device_id>(hDevice), {"cl_intel_devicelib_assert"},
1101+
Supported));
1102+
return ReturnValue(Supported);
1103+
}
10971104
default: {
10981105
return UR_RESULT_ERROR_INVALID_ENUMERATION;
10991106
}

test/conformance/device/urDeviceGetInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static std::unordered_map<ur_device_info_t, size_t> device_info_size_map = {
115115
{UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, sizeof(uint32_t)},
116116
{UR_DEVICE_INFO_COMPONENT_DEVICES, sizeof(uint32_t)},
117117
{UR_DEVICE_INFO_COMPOSITE_DEVICE, sizeof(ur_device_handle_t)},
118-
};
118+
{UR_DEVICE_INFO_USE_NATIVE_ASSERT, sizeof(ur_bool_t)}};
119119

120120
struct urDeviceGetInfoTest : uur::urAllDevicesTest,
121121
::testing::WithParamInterface<ur_device_info_t> {
@@ -236,7 +236,8 @@ INSTANTIATE_TEST_SUITE_P(
236236
UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED, //
237237
UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP, //
238238
UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT, //
239-
UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS //
239+
UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS, //
240+
UR_DEVICE_INFO_USE_NATIVE_ASSERT //
240241
),
241242
[](const ::testing::TestParamInfo<ur_device_info_t> &info) {
242243
std::stringstream ss;

tools/urinfo/urinfo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
331331
std::cout << prefix;
332332
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT);
333333
std::cout << prefix;
334+
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_USE_NATIVE_ASSERT);
335+
std::cout << prefix;
334336
printDeviceInfo<ur_bool_t>(hDevice,
335337
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP);
336338
std::cout << prefix;

0 commit comments

Comments
 (0)