From 6f36d5b9ca751a0973fec22aa65a4cbbc1159b6f Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Fri, 3 Sep 2021 14:09:27 -0700 Subject: [PATCH 1/6] adding errc to SYCL 1.2.1 exceptions for SYCL2020 conformance Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/exception.hpp | 211 ++++++++++++++++++++++------- 1 file changed, 161 insertions(+), 50 deletions(-) diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index e512862d336f9..2dae075e31bb6 100644 --- a/sycl/include/CL/sycl/exception.hpp +++ b/sycl/include/CL/sycl/exception.hpp @@ -24,6 +24,39 @@ namespace sycl { // Forward declaration class context; +enum class errc : unsigned int { + success = 0, + runtime = 1, + kernel = 2, + accessor = 3, + nd_range = 4, + event = 5, + kernel_argument = 6, + build = 7, + invalid = 8, + memory_allocation = 9, + platform = 10, + profiling = 11, + feature_not_supported = 12, + kernel_not_supported = 13, + backend_mismatch = 14, +}; + +template using errc_for = typename backend_traits::errc; + +/// Constructs an error code using e and sycl_category() +__SYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept; + +__SYCL_EXPORT const std::error_category &sycl_category() noexcept; + +namespace detail { +class __SYCL_EXPORT SYCLCategory : public std::error_category { +public: + const char *name() const noexcept override { return "sycl"; } + std::string message(int) const override { return "SYCL Error"; } +}; +} // namespace detail + // Derive from std::exception so uncaught exceptions are printed in c++ default // exception handler. /// \ingroup sycl_api @@ -68,14 +101,18 @@ class __SYCL_EXPORT exception : public std::exception { std::shared_ptr MContext; protected: - exception(const char *Msg, const cl_int CLErr, + // base constructors used by SYCL 1.2.1 exception subclasses + exception(std::error_code ec, const char *Msg, const cl_int CLErr, std::shared_ptr Context = nullptr) - : exception(std::string(Msg), CLErr, Context) {} + : exception(ec, std::string(Msg), CLErr, Context) {} - exception(const std::string &Msg, const cl_int CLErr, + exception(std::error_code ec, const std::string &Msg, const cl_int CLErr, std::shared_ptr Context = nullptr) - : MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr), - MContext(Context) {} + //: MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr), + // MContext(Context) {} + : exception(ec, Context, Msg + " " + detail::codeToString(CLErr)) { + MCLErr = CLErr; + } exception(const string_class &Msg) : MMsg(Msg), MContext(nullptr) {} @@ -95,33 +132,79 @@ class __SYCL2020_DEPRECATED( runtime_error(const char *Msg, cl_int Err) : runtime_error(std::string(Msg), Err) {} - runtime_error(const std::string &Msg, cl_int Err) : exception(Msg, Err) {} + runtime_error(const std::string &Msg, cl_int Err) + : exception(make_error_code(errc::runtime), Msg, Err) {} + +protected: + runtime_error(std::error_code ec, const std::string &Msg, const cl_int CLErr) + : exception(ec, Msg, CLErr) {} }; + class __SYCL2020_DEPRECATED("use sycl::exception with sycl::errc::kernel or " "errc::kernel_argument instead.") kernel_error : public runtime_error { - using runtime_error::runtime_error; +public: + kernel_error() = default; + + kernel_error(const char *Msg, cl_int Err) + : kernel_error(std::string(Msg), Err) {} + + kernel_error(const std::string &Msg, cl_int Err) + : runtime_error(make_error_code(errc::kernel), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::accessor instead.") accessor_error : public runtime_error { - using runtime_error::runtime_error; +public: + accessor_error() = default; + + accessor_error(const char *Msg, cl_int Err) + : accessor_error(std::string(Msg), Err) {} + + accessor_error(const std::string &Msg, cl_int Err) + : runtime_error(make_error_code(errc::accessor), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::nd_range instead.") nd_range_error : public runtime_error { - using runtime_error::runtime_error; +public: + nd_range_error() = default; + + nd_range_error(const char *Msg, cl_int Err) + : nd_range_error(std::string(Msg), Err) {} + + nd_range_error(const std::string &Msg, cl_int Err) + : runtime_error(make_error_code(errc::nd_range), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::event instead.") event_error : public runtime_error { - using runtime_error::runtime_error; +public: + event_error() = default; + + event_error(const char *Msg, cl_int Err) + : event_error(std::string(Msg), Err) {} + + event_error(const std::string &Msg, cl_int Err) + : runtime_error(make_error_code(errc::event), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with a sycl::errc enum value instead.") invalid_parameter_error : public runtime_error { - using runtime_error::runtime_error; +public: + invalid_parameter_error() = default; + + invalid_parameter_error(const char *Msg, cl_int Err) + : invalid_parameter_error(std::string(Msg), Err) {} + + invalid_parameter_error(const std::string &Msg, cl_int Err) + : runtime_error(make_error_code(errc::kernel_argument), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with a sycl::errc enum value instead.") device_error : public exception { @@ -131,76 +214,104 @@ class __SYCL2020_DEPRECATED( device_error(const char *Msg, cl_int Err) : device_error(std::string(Msg), Err) {} - device_error(const std::string &Msg, cl_int Err) : exception(Msg, Err) {} + device_error(const std::string &Msg, cl_int Err) + : exception(make_error_code(errc::invalid), Msg, Err) {} + +protected: + device_error(std::error_code ec, const std::string &Msg, const cl_int CLErr) + : exception(ec, Msg, CLErr) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with a sycl::errc enum value instead.") compile_program_error : public device_error { - using device_error::device_error; +public: + compile_program_error() = default; + + compile_program_error(const char *Msg, cl_int Err) + : compile_program_error(std::string(Msg), Err) {} + + compile_program_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::build), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with a sycl::errc enum value instead.") link_program_error : public device_error { - using device_error::device_error; +public: + link_program_error() = default; + + link_program_error(const char *Msg, cl_int Err) + : link_program_error(std::string(Msg), Err) {} + + link_program_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::build), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with a sycl::errc enum value instead.") invalid_object_error : public device_error { - using device_error::device_error; +public: + invalid_object_error() = default; + + invalid_object_error(const char *Msg, cl_int Err) + : invalid_object_error(std::string(Msg), Err) {} + + invalid_object_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::invalid), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::memory_allocation instead.") memory_allocation_error : public device_error { - using device_error::device_error; +public: + memory_allocation_error() = default; + + memory_allocation_error(const char *Msg, cl_int Err) + : memory_allocation_error(std::string(Msg), Err) {} + + memory_allocation_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::memory_allocation), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::platform instead.") platform_error : public device_error { - using device_error::device_error; +public: + platform_error() = default; + + platform_error(const char *Msg, cl_int Err) + : platform_error(std::string(Msg), Err) {} + + platform_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::platform), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::profiling instead.") profiling_error : public device_error { - using device_error::device_error; +public: + profiling_error() = default; + + profiling_error(const char *Msg, cl_int Err) + : profiling_error(std::string(Msg), Err) {} + + profiling_error(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::profiling), Msg, Err) {} }; + class __SYCL2020_DEPRECATED( "use sycl::exception with sycl::errc::feature_not_supported instead.") feature_not_supported : public device_error { - using device_error::device_error; -}; - -enum class errc : unsigned int { - success = 0, - runtime = 1, - kernel = 2, - accessor = 3, - nd_range = 4, - event = 5, - kernel_argument = 6, - build = 7, - invalid = 8, - memory_allocation = 9, - platform = 10, - profiling = 11, - feature_not_supported = 12, - kernel_not_supported = 13, - backend_mismatch = 14, -}; - -template using errc_for = typename backend_traits::errc; - -/// Constructs an error code using e and sycl_category() -__SYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept; +public: + feature_not_supported() = default; -__SYCL_EXPORT const std::error_category &sycl_category() noexcept; + feature_not_supported(const char *Msg, cl_int Err) + : feature_not_supported(std::string(Msg), Err) {} -namespace detail { -class __SYCL_EXPORT SYCLCategory : public std::error_category { -public: - const char *name() const noexcept override { return "sycl"; } - std::string message(int) const override { return "SYCL Error"; } + feature_not_supported(const std::string &Msg, cl_int Err) + : device_error(make_error_code(errc::feature_not_supported), Msg, Err) {} }; -} // namespace detail } // namespace sycl } // __SYCL_INLINE_NAMESPACE(cl) From e4ab8ca4743ff65a1d4b3c9dacfd022bb519fcae Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Tue, 7 Sep 2021 14:26:33 -0700 Subject: [PATCH 2/6] restore removed constructors. Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/exception.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index 2dae075e31bb6..a013d0aeddfa4 100644 --- a/sycl/include/CL/sycl/exception.hpp +++ b/sycl/include/CL/sycl/exception.hpp @@ -101,6 +101,15 @@ class __SYCL_EXPORT exception : public std::exception { std::shared_ptr MContext; protected: + // these two constructors are no longer used. Kept for ABI compatability. + exception(const char *Msg, const cl_int CLErr, + std::shared_ptr Context = nullptr) + : exception(std::string(Msg), CLErr, Context) {} + exception(const std::string &Msg, const cl_int CLErr, + std::shared_ptr Context = nullptr) + : MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr), + MContext(Context) {} + // base constructors used by SYCL 1.2.1 exception subclasses exception(std::error_code ec, const char *Msg, const cl_int CLErr, std::shared_ptr Context = nullptr) @@ -108,8 +117,6 @@ class __SYCL_EXPORT exception : public std::exception { exception(std::error_code ec, const std::string &Msg, const cl_int CLErr, std::shared_ptr Context = nullptr) - //: MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr), - // MContext(Context) {} : exception(ec, Context, Msg + " " + detail::codeToString(CLErr)) { MCLErr = CLErr; } From 474377dfd834608e81abec5cef55e5ddadc1ea52 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Tue, 14 Sep 2021 13:35:17 -0700 Subject: [PATCH 3/6] updating Windows symbols for new exception constructors Signed-off-by: Chris Perkins --- sycl/test/abi/sycl_symbols_windows.dump | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index ca9b4eda5bc94..0d0c40e8eabb9 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -110,7 +110,6 @@ ??$get_info@$0BAIA@@context@sycl@cl@@QEBAIXZ ??$get_info@$0BAIB@@context@sycl@cl@@QEBA?AV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@XZ ??$get_info@$0BAIE@@context@sycl@cl@@QEBA?AVplatform@12@XZ -?device_has@queue@sycl@cl@@QEBA_NW4aspect@23@@Z ??$get_info@$0BAJA@@queue@sycl@cl@@QEBA?AVcontext@12@XZ ??$get_info@$0BAJB@@queue@sycl@cl@@QEBA?AVdevice@12@XZ ??$get_info@$0BAJC@@queue@sycl@cl@@QEBAIXZ @@ -304,6 +303,8 @@ ??0exception@sycl@cl@@IEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z ??0exception@sycl@cl@@IEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HV?$shared_ptr@Vcontext@sycl@cl@@@4@@Z ??0exception@sycl@cl@@IEAA@PEBDHV?$shared_ptr@Vcontext@sycl@cl@@@std@@@Z +??0exception@sycl@cl@@IEAA@Verror_code@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@HV?$shared_ptr@Vcontext@sycl@cl@@@4@@Z +??0exception@sycl@cl@@IEAA@Verror_code@std@@PEBDHV?$shared_ptr@Vcontext@sycl@cl@@@4@@Z ??0exception@sycl@cl@@IEAA@Verror_code@std@@V?$shared_ptr@Vcontext@sycl@cl@@@4@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z ??0exception@sycl@cl@@QEAA@$$QEAV012@@Z ??0exception@sycl@cl@@QEAA@AEBV012@@Z @@ -1596,6 +1597,7 @@ ?depends_on@handler@sycl@cl@@QEAAXAEBV?$vector@Vevent@sycl@cl@@V?$allocator@Vevent@sycl@cl@@@std@@@std@@@Z ?depends_on@handler@sycl@cl@@QEAAXVevent@23@@Z ?determineHostPtr@SYCLMemObjT@detail@sycl@cl@@IEAAXAEBV?$shared_ptr@Vcontext_impl@detail@sycl@cl@@@std@@_NAEAPEAXAEA_N@Z +?device_has@queue@sycl@cl@@QEBA_NW4aspect@23@@Z ?die@pi@detail@sycl@cl@@YAXPEBD@Z ?distance@__host_std@cl@@YA?AVhalf@half_impl@detail@sycl@2@V34562@0@Z ?distance@__host_std@cl@@YA?AVhalf@half_impl@detail@sycl@2@V?$vec@Vhalf@half_impl@detail@sycl@cl@@$01@62@0@Z @@ -1744,12 +1746,12 @@ ?expm1@__host_std@cl@@YANN@Z ?ext_oneapi_barrier@handler@sycl@cl@@QEAAXAEBV?$vector@Vevent@sycl@cl@@V?$allocator@Vevent@sycl@cl@@@std@@@std@@@Z ?ext_oneapi_barrier@handler@sycl@cl@@QEAAXXZ +?ext_oneapi_get_default_context@platform@sycl@cl@@QEBA?AVcontext@23@XZ ?ext_oneapi_submit_barrier@queue@sycl@cl@@QEAA?AVevent@23@AEBUcode_location@detail@23@@Z ?ext_oneapi_submit_barrier@queue@sycl@cl@@QEAA?AVevent@23@AEBV?$vector@Vevent@sycl@cl@@V?$allocator@Vevent@sycl@cl@@@std@@@std@@AEBUcode_location@detail@23@@Z ?extractArgsAndReqs@handler@sycl@cl@@AEAAXXZ ?extractArgsAndReqsFromLambda@handler@sycl@cl@@AEAAXPEAD_KPEBUkernel_param_desc_t@detail@23@@Z ?extractArgsAndReqsFromLambda@handler@sycl@cl@@AEAAXPEAD_KPEBUkernel_param_desc_t@detail@23@_N@Z -?ext_oneapi_get_default_context@platform@sycl@cl@@QEBA?AVcontext@23@XZ ?fabs@__host_std@cl@@YA?AV?$vec@M$00@sycl@2@V342@@Z ?fabs@__host_std@cl@@YA?AV?$vec@M$01@sycl@2@V342@@Z ?fabs@__host_std@cl@@YA?AV?$vec@M$02@sycl@2@V342@@Z From 2f26c5643fdc7b52cd5376152ea4c0fe32521fb4 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Wed, 15 Sep 2021 13:23:28 -0700 Subject: [PATCH 4/6] string_class is apparently no longer a thing? Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/exception.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index 6c2d1172b668e..9d99c5f4cd9d9 100644 --- a/sycl/include/CL/sycl/exception.hpp +++ b/sycl/include/CL/sycl/exception.hpp @@ -122,7 +122,7 @@ class __SYCL_EXPORT exception : public std::exception { MCLErr = CLErr; } - exception(const string_class &Msg) : MMsg(Msg), MContext(nullptr) {} + exception(const std::string &Msg) : MMsg(Msg), MContext(nullptr) {} // base constructor for all SYCL 2020 constructors From cedbbb734befae16b2c9c2c4c1c4659354d53d4f Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Wed, 15 Sep 2021 13:44:51 -0700 Subject: [PATCH 5/6] everyone's favorite: clang-format! Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/exception.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index 9d99c5f4cd9d9..14ac42c513ef9 100644 --- a/sycl/include/CL/sycl/exception.hpp +++ b/sycl/include/CL/sycl/exception.hpp @@ -124,7 +124,6 @@ class __SYCL_EXPORT exception : public std::exception { exception(const std::string &Msg) : MMsg(Msg), MContext(nullptr) {} - // base constructor for all SYCL 2020 constructors // exception(context *ctxPtr, std::error_code ec, const std::string // &what_arg); From ba7bc46985067b76e010c20f243f3faaa893981c Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Wed, 15 Sep 2021 14:35:40 -0700 Subject: [PATCH 6/6] it's cool that clang-format only emits one error before exiting. So awesome. Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/exception.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index 14ac42c513ef9..276c5facdf3e4 100644 --- a/sycl/include/CL/sycl/exception.hpp +++ b/sycl/include/CL/sycl/exception.hpp @@ -110,7 +110,6 @@ class __SYCL_EXPORT exception : public std::exception { : MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr), MContext(Context) {} - // base constructors used by SYCL 1.2.1 exception subclasses exception(std::error_code ec, const char *Msg, const cl_int CLErr, std::shared_ptr Context = nullptr)