Skip to content

Commit 72a077a

Browse files
[SYCL] Fix device::get_devices() with a non-host device type
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 0f7e361 commit 72a077a

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
@@ -37,13 +37,15 @@ device::device(const device_selector &deviceSelector) {
3737

3838
vector_class<device> device::get_devices(info::device_type deviceType) {
3939
vector_class<device> devices;
40+
// Host device availability should not depend on the forced type
41+
const bool includeHost =
42+
detail::match_types(deviceType, info::device_type::host);
4043
info::device_type forced_type = detail::get_forced_type();
4144
// Exclude devices which do not match requested device type
4245
if (detail::match_types(deviceType, forced_type)) {
4346
detail::force_type(deviceType, forced_type);
4447
for (const auto &plt : platform::get_platforms()) {
45-
// Host device must always be available.
46-
if (plt.is_host()) {
48+
if (includeHost && plt.is_host()) {
4749
vector_class<device> host_device(
4850
plt.get_devices(info::device_type::host));
4951
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)