Skip to content

[SYCL] Throw exception when selected device is not in context #8052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions sycl/source/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,16 @@ select_device(const DSelectorInvocableType &DeviceSelectorInvocable) {
__SYCL_EXPORT device
select_device(const DSelectorInvocableType &DeviceSelectorInvocable,
const context &SyclContext) {
std::vector<device> devices = SyclContext.get_devices();
device SelectedDevice = select_device(DeviceSelectorInvocable);

return select_device(DeviceSelectorInvocable, devices);
// Throw exception if selected device is not in context.
std::vector<device> Devices = SyclContext.get_devices();
if (std::find(Devices.begin(), Devices.end(), SelectedDevice) ==
Devices.end())
throw sycl::exception(sycl::make_error_code(errc::invalid),
"Selected device is not in the given context.");

return SelectedDevice;
}

} // namespace detail
Expand Down