Skip to content

[SYCLNATIVECPU] Re-enable host device #9178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d1907b8
Revert "[SYCL] Make host device inaccessible through SYCL API (#6685)"
PietroGhg Feb 2, 2023
26b1819
Revert "[SYCL] Remove mentions of host device from in-tree LIT tests …
PietroGhg Feb 2, 2023
78c9106
temporary disabling hanging test
PietroGhg Feb 2, 2023
f702e23
re-enable detail::match_types
PietroGhg Feb 6, 2023
6b8b187
Revert "[SYCL][DOCS] Remove references to host device in top-level do…
PietroGhg Feb 6, 2023
38ed878
remove todo comment
PietroGhg Feb 6, 2023
90a8178
fix revert error
PietroGhg Feb 7, 2023
0b873a6
re-enable linear-host-dev test on host
PietroGhg Feb 7, 2023
8b2faa8
Merge branch 'host_compilation/develop' into pietro/host_device
PietroGhg Feb 7, 2023
f9f3008
making stream::flush synchronous to avoid circular event dep
PietroGhg Feb 8, 2023
28a6353
fix device filtering logic
PietroGhg Feb 9, 2023
3ccfda6
wait for stream flush only if dependant event is host
PietroGhg Feb 10, 2023
34a22ff
addressing review comments
PietroGhg Feb 27, 2023
1b02135
Merge branch 'host_compilation/develop' into pietro/host_device
PietroGhg Feb 28, 2023
c1d6f47
update reduction test
PietroGhg Mar 1, 2023
4990407
Merge branch 'host_compilation/develop' into pietro/host_device
PietroGhg Mar 27, 2023
67536aa
removing reduction_ctor test since it has been moved to llvm-test-suite
PietroGhg Mar 28, 2023
6c60c98
Merge branch 'host_compilation/develop' into pietro/host_device
PietroGhg Apr 11, 2023
f15bbcf
fix merge issue
PietroGhg Apr 11, 2023
9a36e04
Revert host device removal in tests
PietroGhg Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 17 additions & 6 deletions sycl/doc/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ compiler provides you with both host and device side compilation. Another
requirement for code offloading to specialized devices is a compatible OpenCL
runtime. Our [Get Started Guide](GetStartedGuide.md) will help you
set up a proper environment. To learn more about using the DPC++ compiler,
please refer to [Users Manual](UsersManual.md).
please refer to [Users Manual](UsersManual.md). If using a special compiler
is not an option for you and/or you would like to experiment without offloading
code to non-host devices, you can exploit SYCL's host device feature. This
gives you the ability to use any C++17 compiler. You will need to link your
application with the DPC++ Runtime library and provide a path to the SYCL
headers directory. Please, refer to your compiler manual to learn about
specific build options.

### Q: How are DPC++ compilation phases different from those of a usual C++ compiler? Can I customize this flow for my applications?
**A:** Due to the fact that both host and device code need to be compiled and
Expand Down Expand Up @@ -57,11 +63,10 @@ design/CompilerAndRuntimeDesign.md) document.

## Using applications built with DPC++

### Q: What happens if I run my SYCL application on a machine without a supported backend?
**A:** If a SYCL application is unable to find a suitable device, the SYCL
objects (`sycl::context`, `sycl::queue`, etc.) or the SYCL device selector (See
[SYCL 2020 specificaion 4.6.1.1](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:device-selection))
will throw a `sycl::exception` with `errc::runtime` error code.
### Q: What happens if I run my application on a machine without OpenCL?
**A:** If you use the default SYCL device selector (or any other selector that
allows host device), then a fallback to the host device will take place.
Otherwise, an exception will be thrown.


## Common issues
Expand Down Expand Up @@ -137,6 +142,12 @@ SPIR-V, a portable intermediate representation format. It is a core feature of
OpenCL 2.1, so any device, capable of OpenCL 2.1, should be supported.
Otherwise, your OpenCL device must support `cl_khr_il_program` extension.

Apart from that, there's also the so-called host device, which can be used when
no suitable OpenCL device is found. The host device will use your host CPU as
the offload target for kernel execution. Since the device code is also compiled
for the host CPU and no JIT is required, you can easily use any classic C++
debugging tools of your choice for the host device code.

Furthermore, developers can extend capabilities of the DPC++ Runtime to
non-OpenCL devices by writing correspondent plugins. To learn more, please
check out our [Plugin Interface Guide](design/PluginInterface.md).
Expand Down
6 changes: 5 additions & 1 deletion sycl/doc/GetStartedGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ more. To find available options, execute:

The `simple-sycl-app.exe` application doesn't specify SYCL device for
execution, so SYCL runtime will use `default_selector` logic to select one
of accelerators available in the system.
of accelerators available in the system or SYCL host device.
In this case, the behavior of the `default_selector` can be altered
using the `ONEAPI_DEVICE_SELECTOR` environment variable, setting `cuda:*` forces
the usage of the CUDA backend (if available), `hip:*` forces
Expand All @@ -711,6 +711,9 @@ ONEAPI_DEVICE_SELECTOR=cuda:* ./simple-sycl-app-cuda.exe
```

The default is the OpenCL backend if available.
If there are no OpenCL or CUDA devices available, the SYCL host device is used.
The SYCL host device executes the SYCL application directly in the host,
without using any low-level API.

**NOTE**: `nvptx64-nvidia-cuda` is usable with `-fsycl-targets`
if clang was built with the cmake option `SYCL_ENABLE_PLUGINS=cuda`.
Expand Down Expand Up @@ -850,6 +853,7 @@ which contains all the symbols required.

* DPC++ device compiler fails if the same kernel was used in different
translation units.
* SYCL host device is not fully supported.
* SYCL 2020 support work is in progress.
* 32-bit host/target is not supported.
* DPC++ works only with OpenCL low level runtimes which support out-of-order
Expand Down
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 @@ -421,7 +421,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 @@ -510,10 +509,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 @@ -1103,6 +1108,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 @@ -1747,6 +1753,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 @@ -1783,6 +1790,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 @@ -1801,6 +1809,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 @@ -462,8 +462,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 @@ -488,24 +486,28 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
_CODELOCARG(&CodeLoc);
detail::tls_code_loc_t TlsCodeLocCapture(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 @@ -524,27 +526,34 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
_CODELOCARG(&CodeLoc);
detail::tls_code_loc_t TlsCodeLocCapture(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
1 change: 1 addition & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ set(SYCL_SOURCES
"detail/error_handling/error_handling.cpp"
"detail/event_impl.cpp"
"detail/filter_selector_impl.cpp"
"detail/force_device.cpp"
"detail/fusion/fusion_wrapper.cpp"
"detail/fusion/fusion_wrapper_impl.cpp"
"detail/global_handler.cpp"
Expand Down
6 changes: 1 addition & 5 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,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
5 changes: 3 additions & 2 deletions sycl/source/detail/backend_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
//===----------------------------------------------------------------------===//

#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.");
if (Impl->is_host())
return backend::host;
return Impl->getPlugin().getBackend();

}

} // namespace detail
Expand Down
Loading