Skip to content

Commit 7331d28

Browse files
[SYCL] Fix device selector bug introduced in #12288 (#12328)
The very last commit in #12288 (f9a1377) accidentally removed one condition needed to add the device into allowed devices list. Restore it here.
1 parent 3eca2d4 commit 7331d28

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,26 @@ std::vector<int> platform_impl::filterDeviceFilter(
266266
MPlugin->call<PiApiKind::piDeviceGetInfo>(
267267
Device, PI_DEVICE_INFO_TYPE, sizeof(sycl::detail::pi::PiDeviceType),
268268
&PiDevType, nullptr);
269+
// Assumption here is that there is 1-to-1 mapping between PiDevType and
270+
// Sycl device type for GPU, CPU, and ACC.
271+
info::device_type DeviceType = pi::cast<info::device_type>(PiDevType);
269272

270273
for (const FilterT &Filter : FilterList->get()) {
271274
backend FilterBackend = Filter.Backend.value_or(backend::all);
272275
// First, match the backend entry.
273276
if (FilterBackend != Backend && FilterBackend != backend::all)
274277
continue;
278+
info::device_type FilterDevType =
279+
Filter.DeviceType.value_or(info::device_type::all);
275280

276281
// Match the device_num entry.
277282
if (Filter.DeviceNum && DeviceNum != Filter.DeviceNum.value())
278283
continue;
279284

285+
if (FilterDevType != info::device_type::all &&
286+
FilterDevType != DeviceType)
287+
continue;
288+
280289
if constexpr (is_ods_target) {
281290
// Dealing with ONEAPI_DEVICE_SELECTOR - check for negative filters.
282291
if (Blacklist[DeviceNum]) // already blacklisted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %if any-device-is-cpu %{ env SYCL_DEVICE_FILTER=cpu %{run-unfiltered-devices} %t.out %}
3+
// RUN: %if any-device-is-gpu %{ env SYCL_DEVICE_FILTER=gpu %{run-unfiltered-devices} %t.out %}
4+
// RUN: %if any-device-is-acc %{ env SYCL_DEVICE_FILTER=acc %{run-unfiltered-devices} %t.out %}
5+
6+
#include <sycl/sycl.hpp>
7+
8+
int main() {
9+
namespace dev_info = sycl::info::device;
10+
11+
auto device_type = [](sycl::device d) -> std::string_view {
12+
switch (d.get_info<dev_info::device_type>()) {
13+
case sycl::info::device_type::cpu:
14+
return "cpu";
15+
case sycl::info::device_type::gpu:
16+
return "gpu";
17+
case sycl::info::device_type::accelerator:
18+
return "acc";
19+
default:
20+
return "unknown";
21+
}
22+
};
23+
24+
auto devices = sycl::device::get_devices();
25+
for (sycl::device d : devices) {
26+
std::cout << device_type(d) << " " << d.get_info<dev_info::name>()
27+
<< std::endl;
28+
}
29+
assert(!devices.empty());
30+
auto expected_type = std::getenv("SYCL_DEVICE_FILTER");
31+
assert(std::all_of(devices.begin(), devices.end(),
32+
[=](auto d) { return expected_type == device_type(d); }));
33+
return 0;
34+
}

0 commit comments

Comments
 (0)