Skip to content

Commit 6cf590f

Browse files
authored
[SYCL] Fix device::get_devices() with a non-host device type (#1235)
This patches fixes a bug where a host device was always included in the device list returned by device::get_devices(). Signed-off-by: Sergey Semenov <[email protected]>
1 parent 5d72e6b commit 6cf590f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

sycl/source/device.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ device::device(const device_selector &deviceSelector) {
3838

3939
vector_class<device> device::get_devices(info::device_type deviceType) {
4040
vector_class<device> devices;
41+
// Host device availability should not depend on the forced type
42+
const bool includeHost =
43+
detail::match_types(deviceType, info::device_type::host);
4144
info::device_type forced_type = detail::get_forced_type();
4245
// Exclude devices which do not match requested device type
4346
if (detail::match_types(deviceType, forced_type)) {
4447
detail::force_type(deviceType, forced_type);
4548
for (const auto &plt : platform::get_platforms()) {
46-
// Host device must always be available.
47-
if (plt.is_host()) {
49+
if (includeHost && plt.is_host()) {
4850
vector_class<device> host_device(
4951
plt.get_devices(info::device_type::host));
5052
if (!host_device.empty())
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: %t.out
3+
4+
// Check that the host device is not included in devices returned by
5+
// get_devices() if a non-host device type is specified.
6+
7+
#include <CL/sycl.hpp>
8+
9+
#include <cassert>
10+
11+
using namespace cl::sycl;
12+
13+
void check(info::device_type DT) {
14+
vector_class<device> Devices = device::get_devices(DT);
15+
for (const auto &Device : Devices)
16+
assert(!Device.is_host());
17+
}
18+
19+
int main() {
20+
check(info::device_type::cpu);
21+
check(info::device_type::gpu);
22+
check(info::device_type::accelerator);
23+
check(info::device_type::custom);
24+
check(info::device_type::automatic);
25+
}

0 commit comments

Comments
 (0)