Skip to content

Commit 28a6353

Browse files
committed
fix device filtering logic
1 parent f9f3008 commit 28a6353

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

sycl/source/detail/device_filter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ bool ods_target_list::backendCompatible(backend Backend) {
277277
});
278278
}
279279

280+
bool ods_target_list::containsHost() {
281+
for (const auto &Filter : TargetList) {
282+
if (Filter.Backend == backend::host || Filter.Backend == backend::all)
283+
if (Filter.DeviceType == info::device_type::host ||
284+
Filter.DeviceType == info::device_type::all || !Filter.DeviceType)
285+
// SYCL RT never creates more than one HOST device.
286+
// All device numbers other than 0 are rejected.
287+
if (!Filter.DeviceNum || Filter.DeviceNum == 0)
288+
return true;
289+
}
290+
return false;
291+
}
292+
280293
// ---------------------------------------
281294
// SYCL_DEVICE_FILTER support
282295

sycl/source/detail/platform_impl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ std::vector<platform> platform_impl::get_platforms() {
151151
// SYCL_DEVICE_FILTER
152152
detail::device_filter_list *FilterList =
153153
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
154-
if (!FilterList || FilterList->backendCompatible(backend::host))
154+
detail::ods_target_list *OdsTargetList =
155+
detail::SYCLConfig<detail::ONEAPI_DEVICE_SELECTOR>::get();
156+
if ((!FilterList || FilterList->backendCompatible(backend::host)) &&
157+
(!OdsTargetList || OdsTargetList->backendCompatible(backend::host)))
155158
Platforms.emplace_back(
156159
createSyclObjFromImpl<platform>(platform_impl::getHostPlatformImpl()));
157160

@@ -474,7 +477,8 @@ platform_impl::get_devices(info::device_type DeviceType) const {
474477
DeviceType == info::device_type::all)) {
475478
// If SYCL_DEVICE_FILTER is set, check if filter contains host.
476479
device_filter_list *FilterList = SYCLConfig<SYCL_DEVICE_FILTER>::get();
477-
if (!FilterList || FilterList->containsHost()) {
480+
if ((!FilterList || FilterList->containsHost()) &&
481+
(!OdsTargetList || OdsTargetList->containsHost())) {
478482
Res.push_back(
479483
createSyclObjFromImpl<device>(device_impl::getHostDeviceImpl()));
480484
}

sycl/source/device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ std::vector<device> device::get_devices(info::device_type deviceType) {
6666
includeHost = false;
6767
else
6868
includeHost = FilterList->containsHost();
69+
} else if (OdsTargetList) {
70+
if (deviceType != info::device_type::host &&
71+
deviceType != info::device_type::all)
72+
includeHost = false;
73+
else
74+
includeHost = OdsTargetList->containsHost();
6975
} else {
7076
includeHost = detail::match_types(deviceType, info::device_type::host);
7177
}

0 commit comments

Comments
 (0)