From 839f421ae1502c49cbdd346f7ed7cc83004c5f89 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 14 Feb 2024 13:17:21 -0800 Subject: [PATCH 1/3] [SYCL] Sort platforms in platform::get_platforms() So that the first one would contain the most preferrable device in case SYCL applications/library performs manual device selection and defaults to the first available device. --- sycl/source/detail/platform_impl.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index 57b4a2f48030b..5c26d24dc7b62 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -203,6 +203,21 @@ std::vector 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); + }); + return Platforms; } From 06e8a3970434476668e5cf8d103917ef8b9119d1 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 16 Feb 2024 09:15:45 -0800 Subject: [PATCH 2/3] Address CR + fix a test --- sycl/source/detail/platform_impl.cpp | 14 ++++++++++++-- sycl/test-e2e/Config/select_device.cpp | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index 5c26d24dc7b62..1506cfdf0c28f 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -214,10 +214,20 @@ std::vector platform_impl::get_platforms() { }); return default_selector_v(*it); }; - std::stable_sort(Platforms.begin(), Platforms.end(), [&](auto lhs, auto rhs) { - return GetPlatformScore(lhs) > GetPlatformScore(rhs); + + std::vector> 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; }); + Platforms.clear(); + for (auto &e : PlatformScores ) + Platforms.push_back(e.first); + return Platforms; } diff --git a/sycl/test-e2e/Config/select_device.cpp b/sycl/test-e2e/Config/select_device.cpp index 16d1e24340c1e..970e3088b3e71 100644 --- a/sycl/test-e2e/Config/select_device.cpp +++ b/sycl/test-e2e/Config/select_device.cpp @@ -123,7 +123,11 @@ static std::vector 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) { From 500d91b3e050d2750929c59383bdb066c8762065 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Tue, 20 Feb 2024 16:25:21 -0800 Subject: [PATCH 3/3] Don't run get_backend.cpp on FPGA --- sycl/test-e2e/Basic/get_backend.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sycl/test-e2e/Basic/get_backend.cpp b/sycl/test-e2e/Basic/get_backend.cpp index 975b3a7c7456a..c3930b607b78a 100644 --- a/sycl/test-e2e/Basic/get_backend.cpp +++ b/sycl/test-e2e/Basic/get_backend.cpp @@ -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().