diff --git a/sycl/include/CL/sycl/exception.hpp b/sycl/include/CL/sycl/exception.hpp index e512862d336f9..44e6c3b60c347 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,20 +101,29 @@ 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) + : exception(ec, std::string(Msg), CLErr, Context) {} + + exception(std::error_code ec, const std::string &Msg, const cl_int CLErr, + std::shared_ptr Context = nullptr) + : exception(ec, Context, Msg + " " + detail::codeToString(CLErr)) { + MCLErr = CLErr; + } + exception(const string_class &Msg) : MMsg(Msg), MContext(nullptr) {} // base constructor for all SYCL 2020 constructors - // exception(context *ctxPtr, std::error_code ec, const std::string - // &what_arg); exception(std::error_code ec, std::shared_ptr SharedPtrCtx, const std::string &what_arg); }; @@ -95,33 +137,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 +219,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; +public: + feature_not_supported() = default; -/// Constructs an error code using e and sycl_category() -__SYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept; + feature_not_supported(const char *Msg, cl_int Err) + : feature_not_supported(std::string(Msg), Err) {} -__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"; } + 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) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index df43934451c18..3e08742392033 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -8,10 +8,8 @@ # UNSUPPORTED: libcxx ??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$00@INTEL@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@5@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@5@@Z -??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$00@experimental@intel@ext@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@7@@Z ??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$00@intel@ext@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@6@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@6@@Z ??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$0A@@INTEL@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@5@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@5@@Z -??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$0A@@experimental@intel@ext@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@7@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@7@@Z ??$compile@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@?$online_compiler@$0A@@intel@ext@sycl@cl@@QEAA?AV?$vector@EV?$allocator@E@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@6@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@6@@Z ??$create_sub_devices@$0BAIG@@device@sycl@cl@@QEBA?AV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@_K@Z ??$create_sub_devices@$0BAIH@@device@sycl@cl@@QEBA?AV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@AEBV?$vector@_KV?$allocator@_K@std@@@4@@Z @@ -110,7 +108,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 +301,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 @@ -1741,14 +1740,9 @@ ?expm1@__host_std@cl@@YA?AVhalf@half_impl@detail@sycl@2@V34562@@Z ?expm1@__host_std@cl@@YAMM@Z ?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_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 @@ -2553,33 +2547,25 @@ ?mad@__host_std@cl@@YANNNN@Z ?makeDir@OSUtil@detail@sycl@cl@@SAHPEBD@Z ?make_context@detail@sycl@cl@@YA?AVcontext@23@_KAEBV?$function@$$A6AXVexception_list@sycl@cl@@@Z@std@@W4backend@23@@Z -?make_context@level_zero@oneapi@ext@sycl@cl@@YA?AVcontext@45@AEBV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@_K@Z -?make_context@level_zero@oneapi@ext@sycl@cl@@YA?AVcontext@45@AEBV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@_K_N@Z ?make_context@level_zero@sycl@cl@@YA?AVcontext@23@AEBV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@_K@Z ?make_context@level_zero@sycl@cl@@YA?AVcontext@23@AEBV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@_K_N@Z ?make_context@opencl@sycl@cl@@YA?AVcontext@23@_K@Z ?make_device@detail@sycl@cl@@YA?AVdevice@23@_KW4backend@23@@Z -?make_device@level_zero@oneapi@ext@sycl@cl@@YA?AVdevice@45@AEBVplatform@45@_K@Z ?make_device@level_zero@sycl@cl@@YA?AVdevice@23@AEBVplatform@23@_K@Z ?make_device@opencl@sycl@cl@@YA?AVdevice@23@_K@Z ?make_error_code@sycl@cl@@YA?AVerror_code@std@@W4errc@12@@Z ?make_event@detail@sycl@cl@@YA?AVevent@23@_KAEBVcontext@23@W4backend@23@@Z ?make_event@detail@sycl@cl@@YA?AVevent@23@_KAEBVcontext@23@_NW4backend@23@@Z -?make_event@level_zero@oneapi@ext@sycl@cl@@YA?AVevent@45@AEBVcontext@45@_K_N@Z ?make_event@level_zero@sycl@cl@@YA?AVevent@23@AEBVcontext@23@_K_N@Z ?make_kernel@detail@sycl@cl@@YA?AVkernel@23@_KAEBVcontext@23@W4backend@23@@Z ?make_kernel_bundle@detail@sycl@cl@@YA?AV?$shared_ptr@Vkernel_bundle_impl@detail@sycl@cl@@@std@@_KAEBVcontext@23@W4bundle_state@23@W4backend@23@@Z ?make_platform@detail@sycl@cl@@YA?AVplatform@23@_KW4backend@23@@Z -?make_platform@level_zero@oneapi@ext@sycl@cl@@YA?AVplatform@45@_K@Z ?make_platform@level_zero@sycl@cl@@YA?AVplatform@23@_K@Z ?make_platform@opencl@sycl@cl@@YA?AVplatform@23@_K@Z -?make_program@level_zero@oneapi@ext@sycl@cl@@YA?AVprogram@45@AEBVcontext@45@_K@Z ?make_program@level_zero@sycl@cl@@YA?AVprogram@23@AEBVcontext@23@_K@Z ?make_program@opencl@sycl@cl@@YA?AVprogram@23@AEBVcontext@23@_K@Z ?make_queue@detail@sycl@cl@@YA?AVqueue@23@_KAEBVcontext@23@AEBV?$function@$$A6AXVexception_list@sycl@cl@@@Z@std@@W4backend@23@@Z ?make_queue@detail@sycl@cl@@YA?AVqueue@23@_KAEBVcontext@23@_NAEBV?$function@$$A6AXVexception_list@sycl@cl@@@Z@std@@W4backend@23@@Z -?make_queue@level_zero@oneapi@ext@sycl@cl@@YA?AVqueue@45@AEBVcontext@45@_K@Z -?make_queue@level_zero@oneapi@ext@sycl@cl@@YA?AVqueue@45@AEBVcontext@45@_K_N@Z ?make_queue@level_zero@sycl@cl@@YA?AVqueue@23@AEBVcontext@23@_K@Z ?make_queue@level_zero@sycl@cl@@YA?AVqueue@23@AEBVcontext@23@_K_N@Z ?make_queue@opencl@sycl@cl@@YA?AVqueue@23@AEBVcontext@23@_K@Z