Skip to content

[SYCL] Implement SYCL 2020 default async_handler behavior #7162

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sycl/include/sycl/exception_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <sycl/detail/defines.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/stl.hpp>

#include <cstddef>
Expand Down Expand Up @@ -52,5 +53,23 @@ class __SYCL_EXPORT exception_list {

using async_handler = std::function<void(sycl::exception_list)>;

namespace detail {
// Default implementation of async_handler used by queue and context when no
// user-defined async_handler is specified.
inline void defaultAsyncHandler(exception_list Exceptions) {
std::cerr << "Default async_handler caught exceptions:";
for (auto &EIt : Exceptions) {
try {
if (EIt) {
std::rethrow_exception(EIt);
}
} catch (const std::exception &E) {
std::cerr << "\n\t" << E.what();
}
}
std::cerr << std::endl;
std::terminate();
}
} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
11 changes: 6 additions & 5 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class __SYCL_EXPORT queue {
///
/// \param PropList is a list of properties for queue construction.
explicit queue(const property_list &PropList = {})
: queue(default_selector(), async_handler{}, PropList) {}
: queue(default_selector(), detail::defaultAsyncHandler, PropList) {}

/// Constructs a SYCL queue instance with an async_handler using the device
/// returned by an instance of default_selector.
Expand Down Expand Up @@ -125,8 +125,8 @@ class __SYCL_EXPORT queue {
detail::EnableIfSYCL2020DeviceSelectorInvocable<DeviceSelector>>
explicit queue(const DeviceSelector &deviceSelector,
const property_list &PropList = {})
: queue(detail::select_device(deviceSelector), async_handler{},
PropList) {}
: queue(detail::select_device(deviceSelector),
detail::defaultAsyncHandler, PropList) {}

/// Constructs a SYCL queue instance using the device identified by the
/// device selector provided.
Expand Down Expand Up @@ -171,7 +171,8 @@ class __SYCL_EXPORT queue {
"use SYCL 2020 device selectors instead.")
queue(const device_selector &DeviceSelector,
const property_list &PropList = {})
: queue(DeviceSelector.select_device(), async_handler{}, PropList) {}
: queue(DeviceSelector.select_device(), detail::defaultAsyncHandler,
PropList) {}

/// Constructs a SYCL queue instance with an async_handler using the device
/// returned by the DeviceSelector provided.
Expand All @@ -190,7 +191,7 @@ class __SYCL_EXPORT queue {
/// \param SyclDevice is an instance of SYCL device.
/// \param PropList is a list of properties for queue construction.
explicit queue(const device &SyclDevice, const property_list &PropList = {})
: queue(SyclDevice, async_handler{}, PropList) {}
: queue(SyclDevice, detail::defaultAsyncHandler, PropList) {}

/// Constructs a SYCL queue instance with an async_handler using the device
/// provided.
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/backend/level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ __SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
&PiContext);
// Construct the SYCL context from PI context.
return detail::createSyclObjFromImpl<context>(
std::make_shared<context_impl>(PiContext, async_handler{}, Plugin));
return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
PiContext, detail::defaultAsyncHandler, Plugin));
}

//----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/backend/opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
//----------------------------------------------------------------------------
// Implementation of opencl::make<context>
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle) {
return detail::make_context(NativeHandle, async_handler{}, backend::opencl);
return detail::make_context(NativeHandle, detail::defaultAsyncHandler,
backend::opencl);
}

//----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

context::context(const property_list &PropList)
: context(default_selector().select_device(), PropList) {}

Expand All @@ -49,7 +50,7 @@ context::context(const platform &Platform, async_handler AsyncHandler,

context::context(const std::vector<device> &DeviceList,
const property_list &PropList)
: context(DeviceList, async_handler{}, PropList) {}
: context(DeviceList, detail::defaultAsyncHandler, PropList) {}

context::context(const std::vector<device> &DeviceList,
async_handler AsyncHandler, const property_list &PropList) {
Expand Down
4 changes: 0 additions & 4 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ class queue_impl {
try {
return submit_impl(CGF, Self, Self, SecondQueue, Loc, PostProcess);
} catch (...) {
{
std::lock_guard<std::mutex> Lock(MMutex);
MExceptions.PushBack(std::current_exception());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior was incorrect. Synchronous errors during submit should not be reported asynchronously.

return SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue, Loc,
PostProcess);
}
Expand Down