Skip to content

Commit

Permalink
Add device info query to report support for native asserts.
Browse files Browse the repository at this point in the history
This allows cuda and hip to stop reporting the relevant opencl extension
string, see issue #1374
  • Loading branch information
aarongreig committed Nov 1, 2024
1 parent fa8cc8e commit df32785
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
2 changes: 2 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion source/adapters/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand Down Expand Up @@ -1105,6 +1104,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<bool>(Value));
}
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
return ReturnValue(true);

default:
break;
Expand Down
7 changes: 2 additions & 5 deletions source/adapters/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -933,6 +928,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;
}
Expand Down
2 changes: 2 additions & 0 deletions source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions source/adapters/native_cpu/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions source/adapters/opencl/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cl_device_id>(hDevice), {"cl_intel_devicelib_assert"},
Supported));
return ReturnValue(Supported);
}
default: {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
Expand Down
5 changes: 3 additions & 2 deletions test/conformance/device/urDeviceGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static std::unordered_map<ur_device_info_t, size_t> 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<ur_device_info_t> {
Expand Down Expand Up @@ -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<ur_device_info_t> &info) {
std::stringstream ss;
Expand Down
2 changes: 2 additions & 0 deletions tools/urinfo/urinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ inline void printDeviceInfos(ur_device_handle_t hDevice,
std::cout << prefix;
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT);
std::cout << prefix;
printDeviceInfo<ur_bool_t>(hDevice, UR_DEVICE_INFO_USE_NATIVE_ASSERT);
std::cout << prefix;
printDeviceInfo<ur_bool_t>(hDevice,
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP);
std::cout << prefix;
Expand Down

0 comments on commit df32785

Please sign in to comment.