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
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,31 @@ 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::vector<std::pair<platform, int>> PlatformScores;
PlatformScores.reserve(Platforms.size());
for (auto &p : Platforms)
PlatformScores.emplace_back(p, GetPlatformScore(p));

std::stable_sort(PlatformScores.begin(), PlatformScores.end(), [&](auto lhs, auto rhs) {
return lhs.second > rhs.second;
});
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved

Platforms.clear();
for (auto &e : PlatformScores )
Platforms.push_back(e.first);

return Platforms;
}

Expand Down
7 changes: 3 additions & 4 deletions sycl/test-e2e/Basic/get_backend.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Sporadic fails on DG2
// TODO: Reenable when internal ticket is resolved
// UNSUPPORTED: gpu-intel-dg2
// RUN: %{build} -o %t.out
// RUN: %{run-unfiltered-devices} %t.out
// FPGA RT returns random CL_INVALID_CONTEXT in some configurations, tracked
// internally. Avoid FPGA devices until that is fixed.
// RUN: env ONEAPI_DEVICE_SELECTOR="*:gpu;*:cpu" %{run-unfiltered-devices} %t.out
//
//==----------------- get_backend.cpp ------------------------==//
// This is a test of get_backend().
Expand Down
6 changes: 5 additions & 1 deletion sycl/test-e2e/Config/select_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ static std::vector<DevDescT> getAllowListDesc(std::string allowList) {
throw std::runtime_error("Malformed device allowlist");
}
decDescs.back().devDriverVer = allowList.substr(start, pos - start);
pos = pos + 3;
pos = pos + 2;

if (allowList[pos] == ',') {
pos++;
}
}

else if ((allowList.compare(pos, platformName.size(), platformName)) == 0) {
Expand Down
Loading