diff --git a/sycl/include/sycl/exception_list.hpp b/sycl/include/sycl/exception_list.hpp index 2cad3f7c850fb..9a9a15d062763 100644 --- a/sycl/include/sycl/exception_list.hpp +++ b/sycl/include/sycl/exception_list.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -52,5 +53,23 @@ class __SYCL_EXPORT exception_list { using async_handler = std::function; +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 diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index 9ed308da08e11..d1d2e92d39989 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -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. @@ -125,8 +125,8 @@ class __SYCL_EXPORT queue { detail::EnableIfSYCL2020DeviceSelectorInvocable> 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. @@ -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. @@ -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. diff --git a/sycl/source/backend/level_zero.cpp b/sycl/source/backend/level_zero.cpp index dede0e9729da9..baad64a519b38 100644 --- a/sycl/source/backend/level_zero.cpp +++ b/sycl/source/backend/level_zero.cpp @@ -57,8 +57,8 @@ __SYCL_EXPORT context make_context(const std::vector &DeviceList, NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership, &PiContext); // Construct the SYCL context from PI context. - return detail::createSyclObjFromImpl( - std::make_shared(PiContext, async_handler{}, Plugin)); + return detail::createSyclObjFromImpl(std::make_shared( + PiContext, detail::defaultAsyncHandler, Plugin)); } //---------------------------------------------------------------------------- diff --git a/sycl/source/backend/opencl.cpp b/sycl/source/backend/opencl.cpp index a4eb8fb4ab1de..8dd6aaa4b3931 100644 --- a/sycl/source/backend/opencl.cpp +++ b/sycl/source/backend/opencl.cpp @@ -36,7 +36,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) { //---------------------------------------------------------------------------- // Implementation of opencl::make __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); } //---------------------------------------------------------------------------- diff --git a/sycl/source/context.cpp b/sycl/source/context.cpp index fa42664548d46..470c85005fc6f 100644 --- a/sycl/source/context.cpp +++ b/sycl/source/context.cpp @@ -26,6 +26,7 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { + context::context(const property_list &PropList) : context(default_selector().select_device(), PropList) {} @@ -49,7 +50,7 @@ context::context(const platform &Platform, async_handler AsyncHandler, context::context(const std::vector &DeviceList, const property_list &PropList) - : context(DeviceList, async_handler{}, PropList) {} + : context(DeviceList, detail::defaultAsyncHandler, PropList) {} context::context(const std::vector &DeviceList, async_handler AsyncHandler, const property_list &PropList) { diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 3e3ec40bc2fa9..a1b74927b7992 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -230,10 +230,6 @@ class queue_impl { try { return submit_impl(CGF, Self, Self, SecondQueue, Loc, PostProcess); } catch (...) { - { - std::lock_guard Lock(MMutex); - MExceptions.PushBack(std::current_exception()); - } return SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue, Loc, PostProcess); }