-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL][UR][OpenCL][L0] Fix platform::get_devices #19810
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
steffenlarsen
merged 8 commits into
intel:sycl
from
steffenlarsen:steffen/fix_platform_get_devices
Aug 19, 2025
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
faafe03
[SYCL] Fix platform::get_devices
steffenlarsen ce27ca7
Fix formatting
steffenlarsen 8d0ad31
Disable warning in test
steffenlarsen 0c51503
Fix UR changes
steffenlarsen 82e46f2
Fix UR_DEVICE_TYPE bound
steffenlarsen 2e21f59
Fix L0 picking multiple devices for default
steffenlarsen c02dd4e
Merge remote-tracking branch 'intel/sycl' into steffen/fix_platform_g…
steffenlarsen 84ba1d8
Move UR device type conversion to separate function
steffenlarsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // RUN: %{build} -Wno-deprecated-declarations -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // | ||
| // Tests platform::get_devices for each device type. | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/platform.hpp> | ||
| #include <unordered_set> | ||
|
|
||
| std::string BackendToString(sycl::backend Backend) { | ||
| switch (Backend) { | ||
| case sycl::backend::host: | ||
| return "host"; | ||
| case sycl::backend::opencl: | ||
| return "opencl"; | ||
| case sycl::backend::ext_oneapi_level_zero: | ||
| return "ext_oneapi_level_zero"; | ||
| case sycl::backend::ext_oneapi_cuda: | ||
| return "ext_oneapi_cuda"; | ||
| case sycl::backend::all: | ||
| return "all"; | ||
| case sycl::backend::ext_oneapi_hip: | ||
| return "ext_oneapi_hip"; | ||
| case sycl::backend::ext_oneapi_native_cpu: | ||
| return "ext_oneapi_native_cpu"; | ||
| case sycl::backend::ext_oneapi_offload: | ||
| return "ext_oneapi_offload"; | ||
| default: | ||
| return "UNKNOWN"; | ||
| } | ||
| } | ||
|
|
||
| std::string DeviceTypeToString(sycl::info::device_type DevType) { | ||
| switch (DevType) { | ||
| case sycl::info::device_type::all: | ||
| return "device_type::all"; | ||
| case sycl::info::device_type::cpu: | ||
| return "device_type::cpu"; | ||
| case sycl::info::device_type::gpu: | ||
| return "device_type::gpu"; | ||
| case sycl::info::device_type::accelerator: | ||
| return "device_type::accelerator"; | ||
| case sycl::info::device_type::custom: | ||
| return "device_type::custom"; | ||
| case sycl::info::device_type::automatic: | ||
| return "device_type::automatic"; | ||
| case sycl::info::device_type::host: | ||
| return "device_type::host"; | ||
| default: | ||
| return "UNKNOWN"; | ||
| } | ||
| } | ||
|
|
||
| template <typename T1, typename T2> | ||
| int Check(const T1 &LHS, const T2 &RHS, std::string TestName) { | ||
| if (LHS != RHS) { | ||
| std::cout << "Failed check " << LHS << " != " << RHS << ": " << TestName | ||
| << std::endl; | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| int CheckDeviceType(const sycl::platform &P, sycl::info::device_type DevType, | ||
| std::unordered_set<sycl::device> &AllDevices) { | ||
| assert(DevType != sycl::info::device_type::all); | ||
| int Failures = 0; | ||
|
|
||
| std::vector<sycl::device> Devices = P.get_devices(DevType); | ||
|
|
||
| if (DevType == sycl::info::device_type::automatic) { | ||
| if (AllDevices.empty()) { | ||
| Failures += Check( | ||
| Devices.size(), 0, | ||
| "No devices reported for all query, but automatic returns a device."); | ||
| } else { | ||
| Failures += Check(Devices.size(), 1, | ||
| "Number of devices for device_type::automatic query."); | ||
| if (Devices.size()) | ||
| Failures += | ||
| Check(AllDevices.count(Devices[0]), 1, | ||
| "Device is in the set of all devices in the platform."); | ||
| } | ||
| return Failures; | ||
| } | ||
|
|
||
| // Count devices with the type; | ||
| size_t DevCount = 0; | ||
| for (sycl::device Device : Devices) | ||
| DevCount += (Device.get_info<sycl::info::device::device_type>() == DevType); | ||
|
|
||
| std::unordered_set<sycl::device> UniqueDevices{Devices.begin(), | ||
| Devices.end()}; | ||
| Check(Devices.size(), UniqueDevices.size(), | ||
| "Duplicate devices for " + DeviceTypeToString(DevType)); | ||
|
|
||
| Failures += | ||
| Check(Devices.size(), DevCount, | ||
| "Unexpected number of devices for " + DeviceTypeToString(DevType)); | ||
|
|
||
| Failures += Check( | ||
| std::all_of(UniqueDevices.begin(), UniqueDevices.end(), | ||
| [&](const auto &Dev) { return AllDevices.count(Dev) == 1; }), | ||
| true, | ||
| "Not all devices for " + DeviceTypeToString(DevType) + | ||
| " appear in the list of all devices"); | ||
|
|
||
| return Failures; | ||
| } | ||
|
|
||
| int main() { | ||
| int Failures = 0; | ||
| for (sycl::platform P : sycl::platform::get_platforms()) { | ||
| std::cout << "Checking platform with backend " | ||
| << BackendToString(P.get_backend()) << std::endl; | ||
|
|
||
| std::vector<sycl::device> Devices = P.get_devices(); | ||
| std::unordered_set<sycl::device> UniqueDevices{Devices.begin(), | ||
| Devices.end()}; | ||
|
|
||
| if (Check(Devices.size(), UniqueDevices.size(), | ||
| "Duplicate devices for device_type::all")) { | ||
| ++Failures; | ||
| // Don't trust this platform, so we continue. | ||
| continue; | ||
| } | ||
|
|
||
| for (sycl::info::device_type DevType : | ||
| {sycl::info::device_type::cpu, sycl::info::device_type::gpu, | ||
| sycl::info::device_type::accelerator, sycl::info::device_type::custom, | ||
| sycl::info::device_type::automatic, sycl::info::device_type::host}) | ||
| Failures += CheckDeviceType(P, DevType, UniqueDevices); | ||
| } | ||
| return Failures; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.