Skip to content

Commit

Permalink
Revert "[SYCL] Make host device inaccessible through SYCL API (intel#…
Browse files Browse the repository at this point in the history
…6685)"

This reverts commit 5b13d5b.
  • Loading branch information
PietroGhg committed Feb 2, 2023
1 parent 24e36e8 commit d1907b8
Show file tree
Hide file tree
Showing 51 changed files with 939 additions and 270 deletions.
2 changes: 1 addition & 1 deletion sycl/include/sycl/backend_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

enum class backend : char {
host __SYCL2020_DEPRECATED("'host' backend is no longer supported") = 0,
host = 0,
opencl = 1,
ext_oneapi_level_zero = 2,
level_zero __SYCL2020_DEPRECATED("use 'ext_oneapi_level_zero' instead") =
Expand Down
2 changes: 0 additions & 2 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
/// Checks if this context is a SYCL host context.
///
/// \return true if this context is a SYCL host context.
__SYCL2020_DEPRECATED(
"is_host() is deprecated as the host device is no longer supported.")
bool is_host() const;

/// Returns the backend associated with this context.
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/detail/device_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class device_filter_list {
bool backendCompatible(backend Backend);
bool deviceTypeCompatible(info::device_type DeviceType);
bool deviceNumberCompatible(int DeviceNum);
bool containsHost();
friend std::ostream &operator<<(std::ostream &Out,
const device_filter_list &List);
};
Expand Down
2 changes: 0 additions & 2 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
/// Check if device is a host device
///
/// \return true if SYCL device is a host device
__SYCL2020_DEPRECATED(
"is_host() is deprecated as the host device is no longer supported.")
bool is_host() const;

/// Check if device is a CPU device
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/device_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ __SYCL2020_DEPRECATED("Use the callable sycl::accelerator_selector_v instead.")
///
/// \ingroup sycl_api_dev_sel
class __SYCL_EXPORT
__SYCL2020_DEPRECATED("Host device is no longer supported.") host_selector
__SYCL2020_DEPRECATED("Use a callable function instead.") host_selector
: public device_selector {
public:
int operator()(const device &dev) const override;
Expand Down
2 changes: 0 additions & 2 deletions sycl/include/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
/// Checks if this event is a SYCL host event.
///
/// \return true if this event is a SYCL host event.
__SYCL2020_DEPRECATED(
"is_host() is deprecated as the host device is no longer supported.")
bool is_host() const;

/// Return the list of events that this event waits for.
Expand Down
17 changes: 13 additions & 4 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ class __SYCL_EXPORT handler {

~handler() = default;

// TODO: Private and unusued. Remove when ABI break is allowed.
bool is_host() { return MIsHost; }

#ifdef __SYCL_DEVICE_ONLY__
Expand Down Expand Up @@ -500,10 +499,16 @@ class __SYCL_EXPORT handler {
sizeof(sampler), ArgIndex);
}

// TODO: Unusued. Remove when ABI break is allowed.
void verifyKernelInvoc(const kernel &Kernel) {
std::ignore = Kernel;
return;
if (is_host()) {
throw invalid_object_error(
"This kernel invocation method cannot be used on the host",
PI_ERROR_INVALID_DEVICE);
}
if (Kernel.is_host()) {
throw invalid_object_error("Invalid kernel type, OpenCL expected",
PI_ERROR_INVALID_KERNEL);
}
}

/* The kernel passed to StoreLambda can take an id, an item or an nd_item as
Expand Down Expand Up @@ -1064,6 +1069,7 @@ class __SYCL_EXPORT handler {
template <int Dims>
void parallel_for_impl(range<Dims> NumWorkItems, kernel Kernel) {
throwIfActionIsCreated();
verifyKernelInvoc(Kernel);
MKernel = detail::getSyclObjImpl(std::move(Kernel));
detail::checkValueRange<Dims>(NumWorkItems);
MNDRDesc.set(std::move(NumWorkItems));
Expand Down Expand Up @@ -1682,6 +1688,7 @@ class __SYCL_EXPORT handler {
/// \param Kernel is a SYCL kernel object.
void single_task(kernel Kernel) {
throwIfActionIsCreated();
verifyKernelInvoc(Kernel);
// Ignore any set kernel bundles and use the one associated with the kernel
setHandlerKernelBundle(Kernel);
// No need to check if range is out of INT_MAX limits as it's compile-time
Expand Down Expand Up @@ -1718,6 +1725,7 @@ class __SYCL_EXPORT handler {
void parallel_for(range<Dims> NumWorkItems, id<Dims> WorkItemOffset,
kernel Kernel) {
throwIfActionIsCreated();
verifyKernelInvoc(Kernel);
MKernel = detail::getSyclObjImpl(std::move(Kernel));
detail::checkValueRange<Dims>(NumWorkItems, WorkItemOffset);
MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset));
Expand All @@ -1736,6 +1744,7 @@ class __SYCL_EXPORT handler {
/// \param Kernel is a SYCL kernel function.
template <int Dims> void parallel_for(nd_range<Dims> NDRange, kernel Kernel) {
throwIfActionIsCreated();
verifyKernelInvoc(Kernel);
MKernel = detail::getSyclObjImpl(std::move(Kernel));
detail::checkValueRange<Dims>(NDRange);
MNDRDesc.set(std::move(NDRange));
Expand Down
2 changes: 0 additions & 2 deletions sycl/include/sycl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
/// Check if the associated SYCL context is a SYCL host context.
///
/// \return true if this SYCL kernel is a host kernel.
__SYCL2020_DEPRECATED(
"is_host() is deprecated as the host device is no longer supported.")
bool is_host() const;

/// Get the context that this kernel is defined for.
Expand Down
2 changes: 0 additions & 2 deletions sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
/// Checks if this SYCL platform is a host platform.
///
/// \return true if this SYCL platform is a host platform.
__SYCL2020_DEPRECATED(
"is_host() is deprecated as the host device is no longer supported.")
bool is_host() const;

/// Returns all SYCL devices associated with this platform.
Expand Down
87 changes: 48 additions & 39 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
device get_device() const;

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

/// Queries SYCL queue for information.
Expand All @@ -308,24 +306,28 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
_CODELOCARG(&CodeLoc);

#if __SYCL_USE_FALLBACK_ASSERT
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
event &E) {
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert && !device_has(aspect::accelerator)) {
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is
// performed by program manager class
// Fallback assert isn't supported for FPGA
submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr, CodeLoc);
}
};

auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
return discard_or_return(Event);
#else
auto Event = submit_impl(CGF, CodeLoc);
return discard_or_return(Event);
if (!is_host()) {
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
event &E) {
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert && !device_has(aspect::accelerator)) {
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is
// performed by program manager class
// Fallback assert isn't supported for FPGA
submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr,
CodeLoc);
}
};

auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
return discard_or_return(Event);
} else
#endif // __SYCL_USE_FALLBACK_ASSERT
{
auto Event = submit_impl(CGF, CodeLoc);
return discard_or_return(Event);
}
}

/// Submits a command group function object to the queue, in order to be
Expand All @@ -344,27 +346,34 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
_CODELOCARG(&CodeLoc);

#if __SYCL_USE_FALLBACK_ASSERT
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
bool IsKernel, bool KernelUsesAssert, event &E) {
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert && !device_has(aspect::accelerator)) {
// Only secondary queues on devices need to be added to the assert
// capture.
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is
// performed by program manager class
// Fallback assert isn't supported for FPGA
submitAssertCapture(*this, E, &SecondaryQueue, CodeLoc);
}
};

auto Event =
submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc, PostProcess);
return discard_or_return(Event);
#else
auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
return discard_or_return(Event);
if (!is_host()) {
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
bool IsKernel, bool KernelUsesAssert, event &E) {
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert && !device_has(aspect::accelerator)) {
// Only secondary queues on devices need to be added to the assert
// capture.
// TODO: Handle case where primary queue is host but the secondary
// queue is not.
queue *DeviceSecondaryQueue =
SecondaryQueue.is_host() ? nullptr : &SecondaryQueue;
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is
// performed by program manager class
// Fallback assert isn't supported for FPGA
submitAssertCapture(*this, E, DeviceSecondaryQueue, CodeLoc);
}
};

auto Event = submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc,
PostProcess);
return discard_or_return(Event);
} else
#endif // __SYCL_USE_FALLBACK_ASSERT
{
auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
return discard_or_return(Event);
}
}

/// Prevents any commands submitted afterward to this queue from executing
Expand Down
13 changes: 4 additions & 9 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ context::context(const std::vector<device> &DeviceList,
PI_ERROR_INVALID_VALUE);
}
auto NonHostDeviceIter = std::find_if_not(
DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) {
return detail::getSyclObjImpl(CurrentDevice)->is_host();
});
DeviceList.begin(), DeviceList.end(),
[&](const device &CurrentDevice) { return CurrentDevice.is_host(); });
if (NonHostDeviceIter == DeviceList.end())
impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,
PropList);
Expand All @@ -72,7 +71,7 @@ context::context(const std::vector<device> &DeviceList,
if (std::any_of(DeviceList.begin(), DeviceList.end(),
[&](const device &CurrentDevice) {
return (
detail::getSyclObjImpl(CurrentDevice)->is_host() ||
CurrentDevice.is_host() ||
(detail::getSyclObjImpl(CurrentDevice.get_platform())
->getHandleRef() != NonHostPlatform));
}))
Expand Down Expand Up @@ -124,11 +123,7 @@ context::get_info() const {

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

bool context::is_host() const {
bool IsHost = impl->is_host();
assert(!IsHost && "context::is_host should not be called in implementation.");
return IsHost;
}
bool context::is_host() const { return impl->is_host(); }

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

Expand Down
10 changes: 7 additions & 3 deletions sycl/source/detail/backend_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
//===----------------------------------------------------------------------===//

#pragma once
#include <cassert>
#include <sycl/backend_types.hpp>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {

template <class T> backend getImplBackend(const T &Impl) {
assert(!Impl->is_host() && "Cannot get the backend for host.");
return Impl->getPlugin().getBackend();
backend Result;
if (Impl->is_host())
Result = backend::host;
else
Result = Impl->getPlugin().getBackend();

return Result;
}

} // namespace detail
Expand Down
3 changes: 1 addition & 2 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ namespace detail {
context_impl::context_impl(const device &Device, async_handler AsyncHandler,
const property_list &PropList)
: MAsyncHandler(AsyncHandler), MDevices(1, Device), MContext(nullptr),
MPlatform(), MPropList(PropList),
MHostContext(detail::getSyclObjImpl(Device)->is_host()),
MPlatform(), MPropList(PropList), MHostContext(Device.is_host()),
MSupportBufferLocationByDevices(NotChecked) {
MKernelProgramCache.setContextPtr(this);
}
Expand Down
27 changes: 15 additions & 12 deletions sycl/source/detail/device_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ device_filter::device_filter(const std::string &FilterString) {
else {
Backend = It->second;
TripleValueID++;

if (Backend == backend::host)
std::cerr << "WARNING: The 'host' backend type is no longer supported in "
"device filter."
<< std::endl;
}

// Handle the optional 2nd field of the filter - device type.
Expand All @@ -320,11 +315,6 @@ device_filter::device_filter(const std::string &FilterString) {
else {
DeviceType = Iter->second;
TripleValueID++;

if (DeviceType == info::device_type::host)
std::cerr << "WARNING: The 'host' device type is no longer supported "
"in device filter."
<< std::endl;
}
}

Expand All @@ -338,8 +328,8 @@ device_filter::device_filter(const std::string &FilterString) {
std::string Message =
std::string("Invalid device filter: ") + FilterString +
"\nPossible backend values are "
"{opencl,level_zero,cuda,hip,esimd_emulator,*}.\n"
"Possible device types are {cpu,gpu,acc,*}.\n"
"{host,opencl,level_zero,cuda,hip,esimd_emulator,*}.\n"
"Possible device types are {host,cpu,gpu,acc,*}.\n"
"Device number should be an non-negative integer.\n";
throw sycl::invalid_parameter_error(Message, PI_ERROR_INVALID_VALUE);
}
Expand Down Expand Up @@ -402,6 +392,19 @@ bool device_filter_list::deviceNumberCompatible(int DeviceNum) {
});
}

bool device_filter_list::containsHost() {
for (const device_filter &Filter : FilterList) {
if (Filter.Backend == backend::host || Filter.Backend == backend::all)
if (Filter.DeviceType == info::device_type::host ||
Filter.DeviceType == info::device_type::all)
// SYCL RT never creates more than one HOST device.
// All device numbers other than 0 are rejected.
if (!Filter.DeviceNum || Filter.DeviceNum == 0)
return true;
}
return false;
}

} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
Loading

0 comments on commit d1907b8

Please sign in to comment.