Skip to content

Commit 5b13d5b

Browse files
[SYCL] Make host device inaccessible through SYCL API (intel#6685)
This commit removes the host device from the device list and as such the host device will no longer be available in user code. The following changes are a result of this: * Device filters using 'host' as either backend or device type will cause a warning at runtime. Since there is no host device selectable for these filters, the resulting device list will not contain a host device. * is_host() on SYCL objects has been deprecated. Any use of them internally on a host device should cause an assertion to fail. * host_selector deprecation message has been changed to better reflect that there is no alternative. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent ed7cb4b commit 5b13d5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+304
-692
lines changed

sycl/include/sycl/backend_types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace sycl {
1919
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2020

2121
enum class backend : char {
22-
host = 0,
22+
host __SYCL2020_DEPRECATED("'host' backend is no longer supported") = 0,
2323
opencl = 1,
2424
ext_oneapi_level_zero = 2,
2525
level_zero __SYCL2020_DEPRECATED("use 'ext_oneapi_level_zero' instead") =

sycl/include/sycl/context.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ class __SYCL_EXPORT context {
200200
/// Checks if this context is a SYCL host context.
201201
///
202202
/// \return true if this context is a SYCL host context.
203+
__SYCL2020_DEPRECATED(
204+
"is_host() is deprecated as the host device is no longer supported.")
203205
bool is_host() const;
204206

205207
/// Returns the backend associated with this context.

sycl/include/sycl/detail/device_filter.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class device_filter_list {
4646
bool backendCompatible(backend Backend);
4747
bool deviceTypeCompatible(info::device_type DeviceType);
4848
bool deviceNumberCompatible(int DeviceNum);
49-
bool containsHost();
5049
friend std::ostream &operator<<(std::ostream &Out,
5150
const device_filter_list &List);
5251
};

sycl/include/sycl/device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class __SYCL_EXPORT device {
9999
/// Check if device is a host device
100100
///
101101
/// \return true if SYCL device is a host device
102+
__SYCL2020_DEPRECATED(
103+
"is_host() is deprecated as the host device is no longer supported.")
102104
bool is_host() const;
103105

104106
/// Check if device is a CPU device

sycl/include/sycl/device_selector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ __SYCL2020_DEPRECATED("Use the callable sycl::accelerator_selector_v instead.")
9696
///
9797
/// \ingroup sycl_api_dev_sel
9898
class __SYCL_EXPORT
99-
__SYCL2020_DEPRECATED("Use a callable function instead.") host_selector
99+
__SYCL2020_DEPRECATED("Host device is no longer supported.") host_selector
100100
: public device_selector {
101101
public:
102102
int operator()(const device &dev) const override;

sycl/include/sycl/event.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class __SYCL_EXPORT event {
6767
/// Checks if this event is a SYCL host event.
6868
///
6969
/// \return true if this event is a SYCL host event.
70+
__SYCL2020_DEPRECATED(
71+
"is_host() is deprecated as the host device is no longer supported.")
7072
bool is_host() const;
7173

7274
/// Return the list of events that this event waits for.

sycl/include/sycl/handler.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ class __SYCL_EXPORT handler {
468468

469469
~handler() = default;
470470

471-
bool is_host() { return MIsHost; }
472-
473471
#ifdef __SYCL_DEVICE_ONLY__
474472
// In device compilation accessor isn't inherited from AccessorBaseHost, so
475473
// can't detect by it. Since we don't expect it to be ever called in device
@@ -543,18 +541,6 @@ class __SYCL_EXPORT handler {
543541
sizeof(sampler), ArgIndex);
544542
}
545543

546-
void verifyKernelInvoc(const kernel &Kernel) {
547-
if (is_host()) {
548-
throw invalid_object_error(
549-
"This kernel invocation method cannot be used on the host",
550-
PI_ERROR_INVALID_DEVICE);
551-
}
552-
if (Kernel.is_host()) {
553-
throw invalid_object_error("Invalid kernel type, OpenCL expected",
554-
PI_ERROR_INVALID_KERNEL);
555-
}
556-
}
557-
558544
/* The kernel passed to StoreLambda can take an id, an item or an nd_item as
559545
* its argument. Since esimd plugin directly invokes the kernel (doesn’t use
560546
* piKernelSetArg), the kernel argument type must be known to the plugin.
@@ -1066,7 +1052,6 @@ class __SYCL_EXPORT handler {
10661052
template <int Dims>
10671053
void parallel_for_impl(range<Dims> NumWorkItems, kernel Kernel) {
10681054
throwIfActionIsCreated();
1069-
verifyKernelInvoc(Kernel);
10701055
MKernel = detail::getSyclObjImpl(std::move(Kernel));
10711056
detail::checkValueRange<Dims>(NumWorkItems);
10721057
MNDRDesc.set(std::move(NumWorkItems));
@@ -1877,7 +1862,6 @@ class __SYCL_EXPORT handler {
18771862
/// \param Kernel is a SYCL kernel object.
18781863
void single_task(kernel Kernel) {
18791864
throwIfActionIsCreated();
1880-
verifyKernelInvoc(Kernel);
18811865
// Ignore any set kernel bundles and use the one associated with the kernel
18821866
setHandlerKernelBundle(Kernel);
18831867
// No need to check if range is out of INT_MAX limits as it's compile-time
@@ -1914,7 +1898,6 @@ class __SYCL_EXPORT handler {
19141898
void parallel_for(range<Dims> NumWorkItems, id<Dims> WorkItemOffset,
19151899
kernel Kernel) {
19161900
throwIfActionIsCreated();
1917-
verifyKernelInvoc(Kernel);
19181901
MKernel = detail::getSyclObjImpl(std::move(Kernel));
19191902
detail::checkValueRange<Dims>(NumWorkItems, WorkItemOffset);
19201903
MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset));
@@ -1933,7 +1916,6 @@ class __SYCL_EXPORT handler {
19331916
/// \param Kernel is a SYCL kernel function.
19341917
template <int Dims> void parallel_for(nd_range<Dims> NDRange, kernel Kernel) {
19351918
throwIfActionIsCreated();
1936-
verifyKernelInvoc(Kernel);
19371919
MKernel = detail::getSyclObjImpl(std::move(Kernel));
19381920
detail::checkValueRange<Dims>(NDRange);
19391921
MNDRDesc.set(std::move(NDRange));

sycl/include/sycl/kernel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class __SYCL_EXPORT kernel {
105105
/// Check if the associated SYCL context is a SYCL host context.
106106
///
107107
/// \return true if this SYCL kernel is a host kernel.
108+
__SYCL2020_DEPRECATED(
109+
"is_host() is deprecated as the host device is no longer supported.")
108110
bool is_host() const;
109111

110112
/// Get the context that this kernel is defined for.

sycl/include/sycl/platform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class __SYCL_EXPORT platform {
109109
/// Checks if this SYCL platform is a host platform.
110110
///
111111
/// \return true if this SYCL platform is a host platform.
112+
__SYCL2020_DEPRECATED(
113+
"is_host() is deprecated as the host device is no longer supported.")
112114
bool is_host() const;
113115

114116
/// Returns all SYCL devices associated with this platform.

sycl/include/sycl/queue.hpp

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ class __SYCL_EXPORT queue {
278278
device get_device() const;
279279

280280
/// \return true if this queue is a SYCL host queue.
281+
__SYCL2020_DEPRECATED(
282+
"is_host() is deprecated as the host device is no longer supported.")
281283
bool is_host() const;
282284

283285
/// Queries SYCL queue for information.
@@ -302,28 +304,24 @@ class __SYCL_EXPORT queue {
302304
_CODELOCARG(&CodeLoc);
303305

304306
#if __SYCL_USE_FALLBACK_ASSERT
305-
if (!is_host()) {
306-
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
307-
event &E) {
308-
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
309-
KernelUsesAssert && !device_has(aspect::accelerator)) {
310-
// __devicelib_assert_fail isn't supported by Device-side Runtime
311-
// Linking against fallback impl of __devicelib_assert_fail is
312-
// performed by program manager class
313-
// Fallback assert isn't supported for FPGA
314-
submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr,
315-
CodeLoc);
316-
}
317-
};
318-
319-
auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
320-
return discard_or_return(Event);
321-
} else
307+
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
308+
event &E) {
309+
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
310+
KernelUsesAssert && !device_has(aspect::accelerator)) {
311+
// __devicelib_assert_fail isn't supported by Device-side Runtime
312+
// Linking against fallback impl of __devicelib_assert_fail is
313+
// performed by program manager class
314+
// Fallback assert isn't supported for FPGA
315+
submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr, CodeLoc);
316+
}
317+
};
318+
319+
auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
320+
return discard_or_return(Event);
321+
#else
322+
auto Event = submit_impl(CGF, CodeLoc);
323+
return discard_or_return(Event);
322324
#endif // __SYCL_USE_FALLBACK_ASSERT
323-
{
324-
auto Event = submit_impl(CGF, CodeLoc);
325-
return discard_or_return(Event);
326-
}
327325
}
328326

329327
/// Submits a command group function object to the queue, in order to be
@@ -342,34 +340,27 @@ class __SYCL_EXPORT queue {
342340
_CODELOCARG(&CodeLoc);
343341

344342
#if __SYCL_USE_FALLBACK_ASSERT
345-
if (!is_host()) {
346-
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
347-
bool IsKernel, bool KernelUsesAssert, event &E) {
348-
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
349-
KernelUsesAssert && !device_has(aspect::accelerator)) {
350-
// Only secondary queues on devices need to be added to the assert
351-
// capture.
352-
// TODO: Handle case where primary queue is host but the secondary
353-
// queue is not.
354-
queue *DeviceSecondaryQueue =
355-
SecondaryQueue.is_host() ? nullptr : &SecondaryQueue;
356-
// __devicelib_assert_fail isn't supported by Device-side Runtime
357-
// Linking against fallback impl of __devicelib_assert_fail is
358-
// performed by program manager class
359-
// Fallback assert isn't supported for FPGA
360-
submitAssertCapture(*this, E, DeviceSecondaryQueue, CodeLoc);
361-
}
362-
};
363-
364-
auto Event = submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc,
365-
PostProcess);
366-
return discard_or_return(Event);
367-
} else
343+
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
344+
bool IsKernel, bool KernelUsesAssert, event &E) {
345+
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
346+
KernelUsesAssert && !device_has(aspect::accelerator)) {
347+
// Only secondary queues on devices need to be added to the assert
348+
// capture.
349+
// __devicelib_assert_fail isn't supported by Device-side Runtime
350+
// Linking against fallback impl of __devicelib_assert_fail is
351+
// performed by program manager class
352+
// Fallback assert isn't supported for FPGA
353+
submitAssertCapture(*this, E, &SecondaryQueue, CodeLoc);
354+
}
355+
};
356+
357+
auto Event =
358+
submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc, PostProcess);
359+
return discard_or_return(Event);
360+
#else
361+
auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
362+
return discard_or_return(Event);
368363
#endif // __SYCL_USE_FALLBACK_ASSERT
369-
{
370-
auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
371-
return discard_or_return(Event);
372-
}
373364
}
374365

375366
/// Prevents any commands submitted afterward to this queue from executing

sycl/source/context.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ context::context(const std::vector<device> &DeviceList,
5858
PI_ERROR_INVALID_VALUE);
5959
}
6060
auto NonHostDeviceIter = std::find_if_not(
61-
DeviceList.begin(), DeviceList.end(),
62-
[&](const device &CurrentDevice) { return CurrentDevice.is_host(); });
61+
DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) {
62+
return detail::getSyclObjImpl(CurrentDevice)->is_host();
63+
});
6364
if (NonHostDeviceIter == DeviceList.end())
6465
impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,
6566
PropList);
@@ -70,7 +71,7 @@ context::context(const std::vector<device> &DeviceList,
7071
if (std::any_of(DeviceList.begin(), DeviceList.end(),
7172
[&](const device &CurrentDevice) {
7273
return (
73-
CurrentDevice.is_host() ||
74+
detail::getSyclObjImpl(CurrentDevice)->is_host() ||
7475
(detail::getSyclObjImpl(CurrentDevice.get_platform())
7576
->getHandleRef() != NonHostPlatform));
7677
}))
@@ -122,7 +123,11 @@ context::get_info() const {
122123

123124
cl_context context::get() const { return impl->get(); }
124125

125-
bool context::is_host() const { return impl->is_host(); }
126+
bool context::is_host() const {
127+
bool IsHost = impl->is_host();
128+
assert(!IsHost && "context::is_host should not be called in implementation.");
129+
return IsHost;
130+
}
126131

127132
backend context::get_backend() const noexcept { return getImplBackend(impl); }
128133

sycl/source/detail/backend_impl.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@
77
//===----------------------------------------------------------------------===//
88

99
#pragma once
10+
#include <cassert>
1011
#include <sycl/backend_types.hpp>
1112

1213
namespace sycl {
1314
__SYCL_INLINE_VER_NAMESPACE(_V1) {
1415
namespace detail {
1516

1617
template <class T> backend getImplBackend(const T &Impl) {
17-
backend Result;
18-
if (Impl->is_host())
19-
Result = backend::host;
20-
else
21-
Result = Impl->getPlugin().getBackend();
22-
23-
return Result;
18+
assert(!Impl->is_host() && "Cannot get the backend for host.");
19+
return Impl->getPlugin().getBackend();
2420
}
2521

2622
} // namespace detail

sycl/source/detail/context_impl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace detail {
2828
context_impl::context_impl(const device &Device, async_handler AsyncHandler,
2929
const property_list &PropList)
3030
: MAsyncHandler(AsyncHandler), MDevices(1, Device), MContext(nullptr),
31-
MPlatform(), MPropList(PropList), MHostContext(Device.is_host()),
31+
MPlatform(), MPropList(PropList),
32+
MHostContext(detail::getSyclObjImpl(Device)->is_host()),
3233
MSupportBufferLocationByDevices(NotChecked) {
3334
MKernelProgramCache.setContextPtr(this);
3435
}

sycl/source/detail/device_filter.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ device_filter::device_filter(const std::string &FilterString) {
6161
else {
6262
Backend = It->second;
6363
TripleValueID++;
64+
65+
if (Backend == backend::host)
66+
std::cerr << "WARNING: The 'host' backend type is no longer supported in "
67+
"device filter."
68+
<< std::endl;
6469
}
6570

6671
// Handle the optional 2nd field of the filter - device type.
@@ -77,6 +82,11 @@ device_filter::device_filter(const std::string &FilterString) {
7782
else {
7883
DeviceType = Iter->second;
7984
TripleValueID++;
85+
86+
if (DeviceType == info::device_type::host)
87+
std::cerr << "WARNING: The 'host' device type is no longer supported "
88+
"in device filter."
89+
<< std::endl;
8090
}
8191
}
8292

@@ -91,8 +101,8 @@ device_filter::device_filter(const std::string &FilterString) {
91101
std::string Message =
92102
std::string("Invalid device filter: ") + FilterString +
93103
"\nPossible backend values are "
94-
"{host,opencl,level_zero,cuda,hip,esimd_emulator,*}.\n"
95-
"Possible device types are {host,cpu,gpu,acc,*}.\n"
104+
"{opencl,level_zero,cuda,hip,esimd_emulator,*}.\n"
105+
"Possible device types are {cpu,gpu,acc,*}.\n"
96106
"Device number should be an non-negative integer.\n";
97107
throw sycl::invalid_parameter_error(Message, PI_ERROR_INVALID_VALUE);
98108
}
@@ -157,19 +167,6 @@ bool device_filter_list::deviceNumberCompatible(int DeviceNum) {
157167
return false;
158168
}
159169

160-
bool device_filter_list::containsHost() {
161-
for (const device_filter &Filter : FilterList) {
162-
if (Filter.Backend == backend::host || Filter.Backend == backend::all)
163-
if (Filter.DeviceType == info::device_type::host ||
164-
Filter.DeviceType == info::device_type::all)
165-
// SYCL RT never creates more than one HOST device.
166-
// All device numbers other than 0 are rejected.
167-
if (!Filter.HasDeviceNum || Filter.DeviceNum == 0)
168-
return true;
169-
}
170-
return false;
171-
}
172-
173170
} // namespace detail
174171
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
175172
} // namespace sycl

0 commit comments

Comments
 (0)