Skip to content

Commit 6549b7b

Browse files
authored
[SYCL] Fix no exception thrown for info::device::preferred_interop_user_sync and info::device::profile when the backend is not OpenCL (#16171)
According to the SYCL 2020 specification, these two info descriptors are supposed to throw an exception when the backend is not OpenCL `info::device::preferred_interop_user_sync` `info::device::profile` https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_device_information_descriptors
1 parent bbcf65c commit 6549b7b

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

sycl/source/detail/device_info.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,32 @@ typename Param::return_type get_device_info(const DeviceImplPtr &Dev) {
14111411
return get_device_info_impl<typename Param::return_type, Param>::get(Dev);
14121412
}
14131413

1414+
template <>
1415+
inline typename info::device::preferred_interop_user_sync::return_type
1416+
get_device_info<info::device::preferred_interop_user_sync>(
1417+
const DeviceImplPtr &Dev) {
1418+
if (Dev->getBackend() != backend::opencl) {
1419+
throw sycl::exception(
1420+
errc::invalid,
1421+
"the info::device::preferred_interop_user_sync info descriptor can "
1422+
"only be queried with an OpenCL backend");
1423+
}
1424+
using Param = info::device::preferred_interop_user_sync;
1425+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1426+
}
1427+
1428+
template <>
1429+
inline typename info::device::profile::return_type
1430+
get_device_info<info::device::profile>(const DeviceImplPtr &Dev) {
1431+
if (Dev->getBackend() != backend::opencl) {
1432+
throw sycl::exception(errc::invalid,
1433+
"the info::device::profile info descriptor can "
1434+
"only be queried with an OpenCL backend");
1435+
}
1436+
using Param = info::device::profile;
1437+
return get_device_info_impl<Param::return_type, Param>::get(Dev);
1438+
}
1439+
14141440
template <>
14151441
inline ext::intel::info::device::device_id::return_type
14161442
get_device_info<ext::intel::info::device::device_id>(const DeviceImplPtr &Dev) {

sycl/test-e2e/Basic/info.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ int main() {
208208
std::string separator(std::string(80, '-') + "\n");
209209
std::cout << separator << "Device information\n" << separator;
210210
device dev(default_selector_v);
211+
backend backend{dev.get_backend()};
211212

212213
print_info<info::device::device_type, info::device_type>(dev, "Device type");
213214
print_info<info::device::vendor_id, std::uint32_t>(dev, "Vendor ID");
@@ -322,7 +323,14 @@ int main() {
322323
print_info<info::device::name, std::string>(dev, "Name");
323324
print_info<info::device::vendor, std::string>(dev, "Vendor");
324325
print_info<info::device::driver_version, std::string>(dev, "Driver version");
325-
print_info<info::device::profile, std::string>(dev, "Profile");
326+
try {
327+
print_info<info::device::profile, std::string>(dev, "Profile");
328+
assert(backend == sycl::backend::opencl &&
329+
"An exception is expected for non OpenCL backend");
330+
} catch (const sycl::exception &e) {
331+
assert(e.code() == sycl::errc::invalid &&
332+
backend != sycl::backend::opencl && "Unexpected exception");
333+
}
326334
print_info<info::device::version, std::string>(dev, "Version");
327335
print_info<info::device::backend_version, std::string>(dev,
328336
"Backend version");
@@ -332,11 +340,18 @@ int main() {
332340
"Extensions");
333341
print_info<info::device::printf_buffer_size, size_t>(dev,
334342
"Printf buffer size");
335-
print_info<info::device::preferred_interop_user_sync, bool>(
336-
dev, "Preferred interop user sync");
343+
try {
344+
print_info<info::device::preferred_interop_user_sync, bool>(
345+
dev, "Preferred interop user sync");
346+
assert(backend == sycl::backend::opencl &&
347+
"An exception is expected for non OpenCL backend");
348+
} catch (const sycl::exception &e) {
349+
assert(e.code() == sycl::errc::invalid &&
350+
backend != sycl::backend::opencl && "Unexpected exception");
351+
}
337352
try {
338353
print_info<info::device::parent_device, device>(dev, "Parent device");
339-
} catch (sycl::exception e) {
354+
} catch (const sycl::exception &e) {
340355
std::cout << "Expected exception has been caught: " << e.what()
341356
<< std::endl;
342357
}

0 commit comments

Comments
 (0)