Skip to content

Commit

Permalink
[SYCL] Fix no exception thrown for `info::device::preferred_interop_u…
Browse files Browse the repository at this point in the history
…ser_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
  • Loading branch information
DYNIO-INTEL authored Nov 27, 2024
1 parent bbcf65c commit 6549b7b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
26 changes: 26 additions & 0 deletions sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,32 @@ typename Param::return_type get_device_info(const DeviceImplPtr &Dev) {
return get_device_info_impl<typename Param::return_type, Param>::get(Dev);
}

template <>
inline typename info::device::preferred_interop_user_sync::return_type
get_device_info<info::device::preferred_interop_user_sync>(
const DeviceImplPtr &Dev) {
if (Dev->getBackend() != backend::opencl) {
throw sycl::exception(
errc::invalid,
"the info::device::preferred_interop_user_sync info descriptor can "
"only be queried with an OpenCL backend");
}
using Param = info::device::preferred_interop_user_sync;
return get_device_info_impl<Param::return_type, Param>::get(Dev);
}

template <>
inline typename info::device::profile::return_type
get_device_info<info::device::profile>(const DeviceImplPtr &Dev) {
if (Dev->getBackend() != backend::opencl) {
throw sycl::exception(errc::invalid,
"the info::device::profile info descriptor can "
"only be queried with an OpenCL backend");
}
using Param = info::device::profile;
return get_device_info_impl<Param::return_type, Param>::get(Dev);
}

template <>
inline ext::intel::info::device::device_id::return_type
get_device_info<ext::intel::info::device::device_id>(const DeviceImplPtr &Dev) {
Expand Down
23 changes: 19 additions & 4 deletions sycl/test-e2e/Basic/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ int main() {
std::string separator(std::string(80, '-') + "\n");
std::cout << separator << "Device information\n" << separator;
device dev(default_selector_v);
backend backend{dev.get_backend()};

print_info<info::device::device_type, info::device_type>(dev, "Device type");
print_info<info::device::vendor_id, std::uint32_t>(dev, "Vendor ID");
Expand Down Expand Up @@ -322,7 +323,14 @@ int main() {
print_info<info::device::name, std::string>(dev, "Name");
print_info<info::device::vendor, std::string>(dev, "Vendor");
print_info<info::device::driver_version, std::string>(dev, "Driver version");
print_info<info::device::profile, std::string>(dev, "Profile");
try {
print_info<info::device::profile, std::string>(dev, "Profile");
assert(backend == sycl::backend::opencl &&
"An exception is expected for non OpenCL backend");
} catch (const sycl::exception &e) {
assert(e.code() == sycl::errc::invalid &&
backend != sycl::backend::opencl && "Unexpected exception");
}
print_info<info::device::version, std::string>(dev, "Version");
print_info<info::device::backend_version, std::string>(dev,
"Backend version");
Expand All @@ -332,11 +340,18 @@ int main() {
"Extensions");
print_info<info::device::printf_buffer_size, size_t>(dev,
"Printf buffer size");
print_info<info::device::preferred_interop_user_sync, bool>(
dev, "Preferred interop user sync");
try {
print_info<info::device::preferred_interop_user_sync, bool>(
dev, "Preferred interop user sync");
assert(backend == sycl::backend::opencl &&
"An exception is expected for non OpenCL backend");
} catch (const sycl::exception &e) {
assert(e.code() == sycl::errc::invalid &&
backend != sycl::backend::opencl && "Unexpected exception");
}
try {
print_info<info::device::parent_device, device>(dev, "Parent device");
} catch (sycl::exception e) {
} catch (const sycl::exception &e) {
std::cout << "Expected exception has been caught: " << e.what()
<< std::endl;
}
Expand Down

0 comments on commit 6549b7b

Please sign in to comment.