Skip to content

Commit 6104f16

Browse files
jbrodmanbader
authored andcommitted
[SYCL] Make host device and host platform always available (#992)
Make host device and host platform always available, even when forcing a device type with SYCL_DEVICE_TYPE Signed-off-by: James Brodman <[email protected]>
1 parent 1eed329 commit 6104f16

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ vector_class<platform> platform_impl::get_platforms() {
4141
}
4242
}
4343

44-
if (ForcedType == info::device_type::host || ForcedType == info::device_type::all)
45-
Platforms.emplace_back(platform());
44+
// The host platform should always be available.
45+
Platforms.emplace_back(platform());
4646

4747
return Platforms;
4848
}

sycl/source/device.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ vector_class<device> device::get_devices(info::device_type deviceType) {
4141
if (detail::match_types(deviceType, forced_type)) {
4242
detail::force_type(deviceType, forced_type);
4343
for (const auto &plt : platform::get_platforms()) {
44-
vector_class<device> found_devices(plt.get_devices(deviceType));
45-
if (!found_devices.empty())
46-
devices.insert(devices.end(), found_devices.begin(),
47-
found_devices.end());
44+
// Host device must always be available.
45+
if (plt.is_host()) {
46+
vector_class<device> host_device(
47+
plt.get_devices(info::device_type::host));
48+
if (!host_device.empty())
49+
devices.insert(devices.end(), host_device.begin(), host_device.end());
50+
} else {
51+
vector_class<device> found_devices(plt.get_devices(deviceType));
52+
if (!found_devices.empty())
53+
devices.insert(devices.end(), found_devices.begin(),
54+
found_devices.end());
55+
}
4856
}
4957
}
5058
return devices;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clangxx -fsycl %s -o %t1.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t1.out
6+
7+
//==------ host_always_works.cpp - Host Device Availability test -----------==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
17+
using namespace cl::sycl;
18+
19+
int main() {
20+
device(host_selector{});
21+
22+
return 0;
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clangxx -fsycl %s -o %t1.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t1.out
6+
7+
//==------ host_platform_avail.cpp - Host Platform Availability test -------==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
17+
using namespace cl::sycl;
18+
19+
int main() {
20+
auto plats = platform::get_platforms();
21+
bool found_host = false;
22+
23+
// Look for a host platform
24+
for (const auto &plat : plats) {
25+
if (plat.is_host()) {
26+
found_host = true;
27+
}
28+
}
29+
30+
// Fail if we didn't find a host platform
31+
return (!found_host);
32+
}

0 commit comments

Comments
 (0)