Skip to content

[NFC][SYCL] Minor refactor after #6896 #6947

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
merged 1 commit into from
Oct 4, 2022
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
43 changes: 23 additions & 20 deletions sycl/source/device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,30 @@ device select_device(DSelectorInvocableType DeviceSelectorInvocable,
return *res;
}

auto Selector = DeviceSelectorInvocable.target<int (*)(const sycl::device &)>();
if ((Selector && *Selector == gpu_selector_v)
|| DeviceSelectorInvocable.target<sycl::gpu_selector>()) {
throw sycl::runtime_error(
"No device of requested type 'info::device_type::gpu' available.",
PI_ERROR_DEVICE_NOT_FOUND);
std::string Message;
constexpr const char Prefix[] = "No device of requested type ";
constexpr const char Cpu[] = "'info::device_type::cpu' ";
constexpr const char Gpu[] = "'info::device_type::gpu' ";
constexpr const char Acc[] = "'info::device_type::accelerator' ";
constexpr const char Suffix[] = "available.";
constexpr auto ReserveSize = sizeof(Prefix) + sizeof(Suffix) + sizeof(Acc);
Message.reserve(ReserveSize);
Message += Prefix;

auto Selector =
DeviceSelectorInvocable.target<int (*)(const sycl::device &)>();
if ((Selector && *Selector == gpu_selector_v) ||
DeviceSelectorInvocable.target<sycl::gpu_selector>()) {
Message += Gpu;
} else if ((Selector && *Selector == cpu_selector_v) ||
DeviceSelectorInvocable.target<sycl::cpu_selector>()) {
Message += Cpu;
} else if ((Selector && *Selector == accelerator_selector_v) ||
DeviceSelectorInvocable.target<sycl::accelerator_selector>()) {
Message += Acc;
}
if ((Selector && *Selector == cpu_selector_v)
|| DeviceSelectorInvocable.target<sycl::cpu_selector>()) {
throw sycl::runtime_error(
"No device of requested type 'info::device_type::cpu' available.",
PI_ERROR_DEVICE_NOT_FOUND);
}
if ((Selector && *Selector == accelerator_selector_v)
|| DeviceSelectorInvocable.target<sycl::accelerator_selector>()) {
throw sycl::runtime_error("No device of requested type "
"'info::device_type::accelerator' available.",
PI_ERROR_DEVICE_NOT_FOUND);
}
throw sycl::runtime_error("No device of requested type available.",
PI_ERROR_DEVICE_NOT_FOUND);
Message += Suffix;
throw sycl::runtime_error(Message, PI_ERROR_DEVICE_NOT_FOUND);
}

// select_device(selector)
Expand Down