Skip to content
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

[SYCL] Sort platforms in platform::get_platforms() #12719

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ std::vector<platform> platform_impl::get_platforms() {
// may be initialized after.
GlobalHandler::registerDefaultContextReleaseHandler();

// Some applications/libraries prefer to implement their own device selection
// and default to just providing the first available device. Make sure that
// the first platform has the most preferrable device.
auto GetPlatformScore = [](const platform &p) {
auto devs = p.get_devices();
auto it =
std::max_element(devs.begin(), devs.end(), [](auto lhs, auto rhs) {
return default_selector_v(lhs) < default_selector_v(rhs);
});
return default_selector_v(*it);
};
std::stable_sort(Platforms.begin(), Platforms.end(), [&](auto lhs, auto rhs) {
return GetPlatformScore(lhs) > GetPlatformScore(rhs);
});
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved

return Platforms;
}

Expand Down
Loading