Skip to content

Commit c07039e

Browse files
authored
[UR] Add device info query for native assert. (#15929)
1 parent f870412 commit c07039e

File tree

14 files changed

+118
-15
lines changed

14 files changed

+118
-15
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ device_impl::device_impl(ur_native_handle_t InteropDeviceHandle,
7373
}
7474
MPlatform = Platform;
7575

76-
MIsAssertFailSupported =
77-
has_extension(UR_DEVICE_INFO_EXTENSION_DEVICELIB_ASSERT);
76+
Adapter->call<UrApiKind::urDeviceGetInfo>(
77+
MDevice, UR_DEVICE_INFO_USE_NATIVE_ASSERT, sizeof(ur_bool_t),
78+
&MUseNativeAssert, nullptr);
7879
}
7980

8081
device_impl::~device_impl() {
@@ -478,7 +479,7 @@ bool device_impl::has(aspect Aspect) const {
478479
case aspect::ext_oneapi_srgb:
479480
return get_info<info::device::ext_oneapi_srgb>();
480481
case aspect::ext_oneapi_native_assert:
481-
return isAssertFailSupported();
482+
return useNativeAssert();
482483
case aspect::ext_oneapi_cuda_async_barrier: {
483484
int async_barrier_supported;
484485
bool call_successful =
@@ -796,9 +797,7 @@ bool device_impl::has(aspect Aspect) const {
796797
return false; // This device aspect has not been implemented yet.
797798
}
798799

799-
bool device_impl::isAssertFailSupported() const {
800-
return MIsAssertFailSupported;
801-
}
800+
bool device_impl::useNativeAssert() const { return MUseNativeAssert; }
802801

803802
std::string device_impl::getDeviceName() const {
804803
std::call_once(MDeviceNameFlag,

sycl/source/detail/device_impl.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ class device_impl {
209209
/// \return true if the SYCL device has the given feature.
210210
bool has(aspect Aspect) const;
211211

212-
bool isAssertFailSupported() const;
212+
/// Indicates the SYCL device prefers to use its native assert
213+
/// implementation.
214+
///
215+
/// If this is false we will use the fallback assert implementation,
216+
/// as detailed in doc/design/Assert.md
217+
bool useNativeAssert() const;
213218

214219
bool isRootDevice() const { return MRootDevice == nullptr; }
215220

@@ -302,7 +307,7 @@ class device_impl {
302307
ur_device_type_t MType;
303308
ur_device_handle_t MRootDevice = nullptr;
304309
PlatformImplPtr MPlatform;
305-
bool MIsAssertFailSupported = false;
310+
bool MUseNativeAssert = false;
306311
mutable std::string MDeviceName;
307312
mutable std::once_flag MDeviceNameFlag;
308313
mutable ext::oneapi::experimental::architecture MDeviceArch{};

sycl/unittests/assert/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_sycl_unittest(AssertTests OBJECT
22
assert.cpp
3+
support_native.cpp
34
)
45

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//==---------- support_native.cpp --- Check support is correctly reported --==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "ur_mock_helpers.hpp"
10+
11+
#include <sycl/sycl.hpp>
12+
13+
#include <helpers/UrMock.hpp>
14+
15+
#include <gtest/gtest.h>
16+
17+
template <bool Support>
18+
static ur_result_t redefinedDeviceGetInfoAfter(void *pParams) {
19+
auto &Params = *reinterpret_cast<ur_device_get_info_params_t *>(pParams);
20+
if (*Params.ppropName == UR_DEVICE_INFO_USE_NATIVE_ASSERT) {
21+
if (*Params.ppPropValue)
22+
*reinterpret_cast<ur_bool_t *>(*Params.ppPropValue) = Support;
23+
if (*Params.ppPropSizeRet)
24+
**Params.ppPropSizeRet = sizeof(ur_bool_t);
25+
}
26+
return UR_RESULT_SUCCESS;
27+
}
28+
29+
TEST(SupportNativeAssert, True) {
30+
mock::getCallbacks().set_after_callback("urDeviceGetInfo",
31+
&redefinedDeviceGetInfoAfter<true>);
32+
33+
sycl::unittest::UrMock<> Mock;
34+
sycl::platform Plt = sycl::platform();
35+
36+
const sycl::device Dev = Plt.get_devices()[0];
37+
38+
ASSERT_TRUE(Dev.has(sycl::aspect::ext_oneapi_native_assert));
39+
}
40+
41+
TEST(SupportNativeAssert, False) {
42+
mock::getCallbacks().set_after_callback("urDeviceGetInfo",
43+
&redefinedDeviceGetInfoAfter<false>);
44+
45+
sycl::unittest::UrMock<> Mock;
46+
sycl::platform Plt = sycl::platform();
47+
48+
const sycl::device Dev = Plt.get_devices()[0];
49+
50+
ASSERT_FALSE(Dev.has(sycl::aspect::ext_oneapi_native_assert));
51+
}

unified-runtime/include/ur_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,9 @@ typedef enum ur_device_info_t {
22222222
/// [::ur_bool_t] support the ::urProgramSetSpecializationConstants entry
22232223
/// point
22242224
UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS = 121,
2225+
/// [::ur_bool_t] return true if the device has a native assert
2226+
/// implementation.
2227+
UR_DEVICE_INFO_USE_NATIVE_ASSERT = 122,
22252228
/// [::ur_bool_t] Returns true if the device supports the use of
22262229
/// command-buffers.
22272230
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000,

unified-runtime/include/ur_print.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
29302930
case UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS:
29312931
os << "UR_DEVICE_INFO_PROGRAM_SET_SPECIALIZATION_CONSTANTS";
29322932
break;
2933+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
2934+
os << "UR_DEVICE_INFO_USE_NATIVE_ASSERT";
2935+
break;
29332936
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
29342937
os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP";
29352938
break;
@@ -4602,6 +4605,19 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr,
46024605

46034606
os << ")";
46044607
} break;
4608+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT: {
4609+
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
4610+
if (sizeof(ur_bool_t) > size) {
4611+
os << "invalid size (is: " << size
4612+
<< ", expected: >=" << sizeof(ur_bool_t) << ")";
4613+
return UR_RESULT_ERROR_INVALID_SIZE;
4614+
}
4615+
os << (const void *)(tptr) << " (";
4616+
4617+
os << *tptr;
4618+
4619+
os << ")";
4620+
} break;
46054621
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
46064622
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
46074623
if (sizeof(ur_bool_t) > size) {

unified-runtime/scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ etors:
447447
desc: "[uint32_t] the number of compute units for specific backend."
448448
- name: PROGRAM_SET_SPECIALIZATION_CONSTANTS
449449
desc: "[$x_bool_t] support the $xProgramSetSpecializationConstants entry point"
450+
- name: USE_NATIVE_ASSERT
451+
desc: "[$x_bool_t] return true if the device has a native assert implementation."
450452
--- #--------------------------------------------------------------------------
451453
type: function
452454
desc: "Retrieves various information about device"

unified-runtime/source/adapters/cuda/device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
615615
return ReturnValue("");
616616
}
617617
case UR_DEVICE_INFO_EXTENSIONS: {
618-
619618
std::string SupportedExtensions = "cl_khr_fp64 ";
620-
SupportedExtensions += "cl_intel_devicelib_assert ";
621619

622620
int Major = 0;
623621
int Minor = 0;
@@ -1113,6 +1111,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11131111
}
11141112
case UR_DEVICE_INFO_LOW_POWER_EVENTS_EXP:
11151113
return ReturnValue(false);
1114+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
1115+
return ReturnValue(true);
11161116
case UR_DEVICE_INFO_USM_P2P_SUPPORT_EXP:
11171117
return ReturnValue(true);
11181118
case UR_DEVICE_INFO_LAUNCH_PROPERTIES_SUPPORT_EXP:

unified-runtime/source/adapters/hip/device.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
546546
return ReturnValue("");
547547
}
548548
case UR_DEVICE_INFO_EXTENSIONS: {
549-
// TODO: Remove comment when HIP support native asserts.
550-
// DEVICELIB_ASSERT extension is set so fallback assert
551-
// postprocessing is NOP. HIP 4.3 docs indicate support for
552-
// native asserts are in progress
553549
std::string SupportedExtensions = "";
554-
SupportedExtensions += "cl_intel_devicelib_assert ";
555550

556551
hipDeviceProp_t Props;
557552
detail::ur::assertion(hipGetDeviceProperties(&Props, hDevice->get()) ==
@@ -1080,6 +1075,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10801075
case UR_DEVICE_INFO_LOW_POWER_EVENTS_EXP: {
10811076
return ReturnValue(false);
10821077
}
1078+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
1079+
return ReturnValue(true);
10831080
case UR_DEVICE_INFO_USM_P2P_SUPPORT_EXP:
10841081
return ReturnValue(true);
10851082
case UR_DEVICE_INFO_LAUNCH_PROPERTIES_SUPPORT_EXP:

unified-runtime/source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,8 @@ ur_result_t urDeviceGetInfo(
12031203
return ReturnValue(false);
12041204
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED:
12051205
return ReturnValue(false);
1206+
case UR_DEVICE_INFO_USE_NATIVE_ASSERT:
1207+
return ReturnValue(false);
12061208
case UR_DEVICE_INFO_USM_P2P_SUPPORT_EXP:
12071209
return ReturnValue(true);
12081210
case UR_DEVICE_INFO_LAUNCH_PROPERTIES_SUPPORT_EXP:

0 commit comments

Comments
 (0)