diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index c3e29e81bd89a..6b9dd7fea880f 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -36,7 +36,6 @@ namespace sycl { inline namespace _V1 { // Forward declarations class device; -class platform; namespace detail { class context_impl; diff --git a/sycl/include/sycl/detail/array.hpp b/sycl/include/sycl/detail/array.hpp index 870cd49f07ac7..98c2ccd75817d 100644 --- a/sycl/include/sycl/detail/array.hpp +++ b/sycl/include/sycl/detail/array.hpp @@ -10,7 +10,7 @@ #include // for __SYCL_ALWAYS_INLINE #include // for PI_ERROR_INVALID_VALUE -#include // for invalid_parameter_error +#include #include // for size_t #include // for enable_if_t @@ -20,6 +20,7 @@ inline namespace _V1 { template class id; template class range; namespace detail { +__SYCL_EXPORT void throw_exception(errc Ec, const char *Msg); template class array { static_assert(dimensions >= 1, "Array cannot be 0-dimensional."); @@ -106,8 +107,7 @@ template class array { __SYCL_ALWAYS_INLINE void check_dimension(int dimension) const { #ifndef __SYCL_DEVICE_ONLY__ if (dimension >= dimensions || dimension < 0) { - throw sycl::invalid_parameter_error("Index out of range", - PI_ERROR_INVALID_VALUE); + detail::throw_exception(errc::invalid, "Index out of range"); } #endif (void)dimension; diff --git a/sycl/include/sycl/detail/property_list_base.hpp b/sycl/include/sycl/detail/property_list_base.hpp index 042e3044020df..277e024adf28a 100644 --- a/sycl/include/sycl/detail/property_list_base.hpp +++ b/sycl/include/sycl/detail/property_list_base.hpp @@ -10,7 +10,7 @@ #include // for PI_ERROR_INVALID_VALUE #include // for DataLessPropKind, Propert... -#include // for invalid_object_error +#include #include // for iter_swap #include // for bitset @@ -22,6 +22,8 @@ namespace sycl { inline namespace _V1 { namespace detail { +__SYCL_EXPORT void throw_exception(errc Ec, const char *Msg); + class PropertyListBase { protected: explicit PropertyListBase( @@ -92,15 +94,17 @@ class PropertyListBase { get_property_helper() const { const int PropKind = static_cast(PropT::getKind()); if (PropKind >= PropWithDataKind::PropWithDataKindSize) - throw sycl::invalid_object_error("The property is not found", - PI_ERROR_INVALID_VALUE); + detail::throw_exception(errc::invalid, "The property is not found"); for (const std::shared_ptr &Prop : MPropsWithData) if (Prop->isSame(PropKind)) return *static_cast(Prop.get()); - throw sycl::invalid_object_error("The property is not found", - PI_ERROR_INVALID_VALUE); + detail::throw_exception(errc::invalid, "The property is not found"); + // The above will throw an exception, but compilers complain about no return + // value. So, create an unreachable dummy throw to make it silent. + // We can replace this with std::unreachable() when we switch to C++23. + throw "dummy"; } void add_or_replace_accessor_properties_helper( diff --git a/sycl/include/sycl/errc.hpp b/sycl/include/sycl/errc.hpp new file mode 100644 index 0000000000000..efbb9aa456de0 --- /dev/null +++ b/sycl/include/sycl/errc.hpp @@ -0,0 +1,32 @@ +//==-------------------- errc.hpp - SYCL error code ------------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#pragma once + +namespace sycl { +inline namespace _V1 { + +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, +}; + +} // namespace _V1 +} // namespace sycl diff --git a/sycl/include/sycl/exception.hpp b/sycl/include/sycl/exception.hpp index ea108f43b3463..fc6fe6a10e1af 100644 --- a/sycl/include/sycl/exception.hpp +++ b/sycl/include/sycl/exception.hpp @@ -10,12 +10,14 @@ // 4.9.2 Exception Class Interface -#include // for backend +#include // for backend +#include #include // for cl_int #include // for codeToString #include // for __SYCL2020_DEPRECATED #include // for __SYCL_EXPORT #include // for pi_int32 +#include #include // for exception #include // for allocator, shared_ptr, make... @@ -26,27 +28,6 @@ namespace sycl { inline namespace _V1 { -// 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() @@ -84,10 +65,18 @@ class __SYCL_EXPORT exception : public virtual std::exception { exception(int, const std::error_category &, const char *); exception(int, const std::error_category &); +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + exception(context Ctx, std::error_code Ec, const std::string &WhatArg) + : exception(Ec, std::make_shared(Ctx), WhatArg.c_str()) {} + exception(context Ctx, int EV, const std::error_category &ECat, + const std::string &WhatArg) + : exception(Ctx, {EV, ECat}, WhatArg) {} +#else exception(context, std::error_code, const std::string &); + exception(context, int, const std::error_category &, const std::string &); +#endif exception(context, std::error_code, const char *); exception(context, std::error_code); - exception(context, int, const std::error_category &, const std::string &); exception(context, int, const std::error_category &, const char *); exception(context, int, const std::error_category &); diff --git a/sycl/include/sycl/ext/intel/experimental/online_compiler.hpp b/sycl/include/sycl/ext/intel/experimental/online_compiler.hpp index 15536e9300b90..f9fdb31163407 100644 --- a/sycl/include/sycl/ext/intel/experimental/online_compiler.hpp +++ b/sycl/include/sycl/ext/intel/experimental/online_compiler.hpp @@ -11,6 +11,7 @@ #include #include // for __SYCL_EXPORT #include +#include #include #include diff --git a/sycl/include/sycl/id.hpp b/sycl/include/sycl/id.hpp index bc17ff460e0eb..9bb493c81b484 100644 --- a/sycl/include/sycl/id.hpp +++ b/sycl/include/sycl/id.hpp @@ -9,10 +9,8 @@ #pragma once #include // for array -#include // for InitializedVal #include // for __SYCL_ASSUME_INT #include // for __SYCL_DEPRECATED, __SYCL_A... -#include // for make_error_code, errc, exce... #include // for range #include // for size_t diff --git a/sycl/include/sycl/property_list.hpp b/sycl/include/sycl/property_list.hpp index 9fa47fcd0b447..864e77e640e5c 100644 --- a/sycl/include/sycl/property_list.hpp +++ b/sycl/include/sycl/property_list.hpp @@ -8,14 +8,15 @@ #pragma once -#include // for PI_ERROR_INVALID_VALUE -#include // for DataLessPropKind, Pro... -#include // for PropertyListBase -#include // for invalid_object_error +#include // for PI_ERROR_INVALID_VALUE +#include // for DataLessPropKind, Pro... +#include // for PropertyListBase +#include #include // for is_property -#include // for bitset -#include // for shared_ptr +#include // for bitset +#include // for shared_ptr +#include #include // for conditional_t, enable... #include // for vector @@ -24,7 +25,9 @@ inline namespace _V1 { namespace ext::oneapi { template class accessor_property_list; } // namespace ext::oneapi - +namespace detail { +__SYCL_EXPORT void throw_exception(errc Ec, const char *Msg); +} // namespace detail /// Objects of the property_list class are containers for the SYCL properties /// /// \ingroup sycl_api @@ -45,9 +48,9 @@ class property_list : protected detail::PropertyListBase { } template PropT get_property() const { - if (!has_property()) - throw sycl::invalid_object_error("The property is not found", - PI_ERROR_INVALID_VALUE); + if (!has_property()) { + detail::throw_exception(errc::invalid, "The property is not found"); + } return get_property_helper(); } diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index 6780fd76a325b..363d11ffb9cbf 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -108,3 +109,13 @@ #include #include #include + +namespace sycl { +inline namespace _V1 { +namespace detail { +__SYCL_EXPORT inline void throw_exception(errc Ec, const char *Msg) { + throw sycl::exception(make_error_code(Ec), Msg); +} +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index ed0539f266ee2..abf35babccdf3 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/sycl/source/exception.cpp b/sycl/source/exception.cpp index 595f25c5d8aa2..df762d0c00d50 100644 --- a/sycl/source/exception.cpp +++ b/sycl/source/exception.cpp @@ -29,10 +29,15 @@ exception::exception(int EV, const std::error_category &ECat, exception::exception(int EV, const std::error_category &ECat) : exception({EV, ECat}, nullptr, "") {} +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES exception::exception(context Ctx, std::error_code EC, const std::string &WhatArg) : exception(EC, std::make_shared(Ctx), WhatArg) {} +exception::exception(context Ctx, int EV, const std::error_category &ECat, + const std::string &WhatArg) + : exception(Ctx, {EV, ECat}, WhatArg) {} +#endif exception::exception(context Ctx, std::error_code EC, const char *WhatArg) : exception(Ctx, EC, std::string(WhatArg)) {} @@ -43,10 +48,6 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat, const char *WhatArg) : exception(Ctx, {EV, ECat}, std::string(WhatArg)) {} -exception::exception(context Ctx, int EV, const std::error_category &ECat, - const std::string &WhatArg) - : exception(Ctx, {EV, ECat}, WhatArg) {} - exception::exception(context Ctx, int EV, const std::error_category &ECat) : exception(Ctx, EV, ECat, "") {} diff --git a/sycl/test-e2e/InorderQueue/in_order_get_property.cpp b/sycl/test-e2e/InorderQueue/in_order_get_property.cpp index ccbfd488db323..97544136d1260 100644 --- a/sycl/test-e2e/InorderQueue/in_order_get_property.cpp +++ b/sycl/test-e2e/InorderQueue/in_order_get_property.cpp @@ -24,7 +24,7 @@ int main() { Queue1.get_property(); assert(false && "Queue1 was created without any properties therefore get " "property should fail."); - } catch (const invalid_object_error &e) { + } catch (const exception &e) { std::string ErrorMessage = e.what(); assert( (ErrorMessage.find("The property is not found") != std::string::npos) && diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 28944dad6adba..7f2e8174208aa 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3323,6 +3323,7 @@ _ZN4sycl3_V16detail14tls_code_loc_tC2Ev _ZN4sycl3_V16detail14tls_code_loc_tD1Ev _ZN4sycl3_V16detail14tls_code_loc_tD2Ev _ZN4sycl3_V16detail15getOrWaitEventsESt6vectorINS0_5eventESaIS3_EESt10shared_ptrINS1_12context_implEE +_ZN4sycl3_V16detail15throw_exceptionENS0_4errcEPKc _ZN4sycl3_V16detail16AccessorBaseHost10getAccDataEv _ZN4sycl3_V16detail16AccessorBaseHost14getAccessRangeEv _ZN4sycl3_V16detail16AccessorBaseHost14getMemoryRangeEv @@ -4093,14 +4094,14 @@ _ZNK4sycl3_V16device9getNativeEv _ZNK4sycl3_V16kernel11get_backendEv _ZNK4sycl3_V16kernel11get_contextEv _ZNK4sycl3_V16kernel13getNativeImplEv -_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv -_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv -_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V16kernel13get_info_implINS0_4info6kernel10attributesEEENS0_6detail11ABINeutralTINS6_19is_kernel_info_descIT_E11return_typeEE4typeEv _ZNK4sycl3_V16kernel13get_info_implINS0_4info6kernel13function_nameEEENS0_6detail11ABINeutralTINS6_19is_kernel_info_descIT_E11return_typeEE4typeEv _ZNK4sycl3_V16kernel13get_info_implINS0_4info6kernel15reference_countEEENS0_6detail11ABINeutralTINS6_19is_kernel_info_descIT_E11return_typeEE4typeEv _ZNK4sycl3_V16kernel13get_info_implINS0_4info6kernel7contextEEENS0_6detail11ABINeutralTINS6_19is_kernel_info_descIT_E11return_typeEE4typeEv _ZNK4sycl3_V16kernel13get_info_implINS0_4info6kernel8num_argsEEENS0_6detail11ABINeutralTINS6_19is_kernel_info_descIT_E11return_typeEE4typeEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V16kernel17get_kernel_bundleEv _ZNK4sycl3_V16kernel19ext_oneapi_get_infoINS0_3ext6oneapi12experimental4info21kernel_queue_specific23max_num_work_group_syncEEENT_11return_typeERKNS0_5queueE _ZNK4sycl3_V16kernel3getEv diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index 5dc49a037a721..e9fd5b6e86399 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -4598,6 +4598,7 @@ ?sycl_category@_V1@sycl@@YAAEBVerror_category@std@@XZ ?throwIfActionIsCreated@handler@_V1@sycl@@AEAAXXZ ?throw_asynchronous@queue@_V1@sycl@@QEAAXXZ +?throw_exception@detail@_V1@sycl@@YAXW4errc@23@PEBD@Z ?unmap@MemoryManager@detail@_V1@sycl@@SAXPEAVSYCLMemObjI@234@PEAXV?$shared_ptr@Vqueue_impl@detail@_V1@sycl@@@std@@1V?$vector@PEAU_pi_event@@V?$allocator@PEAU_pi_event@@@std@@@7@AEAPEAU_pi_event@@@Z ?unsampledImageConstructorNotification@detail@_V1@sycl@@YAXPEAX0AEBV?$optional@W4image_target@_V1@sycl@@@std@@W4mode@access@23@PEBXIAEBUcode_location@123@@Z ?unsampledImageConstructorNotification@image_impl@detail@_V1@sycl@@QEAAXAEBUcode_location@234@PEAXPEBXIQEA_KW4image_format@34@@Z diff --git a/sycl/test/include_deps/sycl_accessor.hpp.cpp b/sycl/test/include_deps/sycl_accessor.hpp.cpp index 331926d7642d0..2a7552c2b0403 100644 --- a/sycl/test/include_deps/sycl_accessor.hpp.cpp +++ b/sycl/test/include_deps/sycl_accessor.hpp.cpp @@ -66,13 +66,7 @@ // CHECK-NEXT: detail/info_desc_helpers.hpp // CHECK-NEXT: id.hpp // CHECK-NEXT: detail/array.hpp -// CHECK-NEXT: exception.hpp -// CHECK-NEXT: detail/cl.h -// CHECK-NEXT: CL/cl.h -// CHECK-NEXT: CL/cl_version.h -// CHECK-NEXT: CL/cl_platform.h -// CHECK-NEXT: CL/cl_ext.h -// CHECK-NEXT: detail/common.hpp +// CHECK-NEXT: errc.hpp // CHECK-NEXT: range.hpp // CHECK-NEXT: info/info_desc.hpp // CHECK-NEXT: ext/oneapi/experimental/device_architecture.hpp @@ -106,6 +100,13 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/common.hpp +// CHECK-NEXT: exception.hpp +// CHECK-NEXT: detail/cl.h +// CHECK-NEXT: CL/cl.h +// CHECK-NEXT: CL/cl_version.h +// CHECK-NEXT: CL/cl_platform.h +// CHECK-NEXT: CL/cl_ext.h // CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp diff --git a/sycl/test/include_deps/sycl_buffer.hpp.cpp b/sycl/test/include_deps/sycl_buffer.hpp.cpp index 320403444c959..68a082f306c52 100644 --- a/sycl/test/include_deps/sycl_buffer.hpp.cpp +++ b/sycl/test/include_deps/sycl_buffer.hpp.cpp @@ -28,14 +28,7 @@ // CHECK-NEXT: info/aspects_deprecated.def // CHECK-NEXT: id.hpp // CHECK-NEXT: detail/array.hpp -// CHECK-NEXT: exception.hpp -// CHECK-NEXT: detail/cl.h -// CHECK-NEXT: CL/cl.h -// CHECK-NEXT: CL/cl_version.h -// CHECK-NEXT: CL/cl_platform.h -// CHECK-NEXT: CL/cl_ext.h -// CHECK-NEXT: detail/common.hpp -// CHECK-NEXT: detail/iostream_proxy.hpp +// CHECK-NEXT: errc.hpp // CHECK-NEXT: range.hpp // CHECK-NEXT: info/info_desc.hpp // CHECK-NEXT: detail/type_traits.hpp @@ -74,6 +67,7 @@ // CHECK-NEXT: aliases.hpp // CHECK-NEXT: half_type.hpp // CHECK-NEXT: bit_cast.hpp +// CHECK-NEXT: detail/iostream_proxy.hpp // CHECK-NEXT: detail/vector_traits.hpp // CHECK-NEXT: ext/oneapi/matrix/matrix-unified-utils.hpp // CHECK-NEXT: info/platform_traits.def @@ -103,6 +97,13 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/common.hpp +// CHECK-NEXT: exception.hpp +// CHECK-NEXT: detail/cl.h +// CHECK-NEXT: CL/cl.h +// CHECK-NEXT: CL/cl_version.h +// CHECK-NEXT: CL/cl_platform.h +// CHECK-NEXT: CL/cl_ext.h // CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index 12f0ea220cbc8..76dba80e794a8 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -67,13 +67,7 @@ // CHECK-NEXT: detail/info_desc_helpers.hpp // CHECK-NEXT: id.hpp // CHECK-NEXT: detail/array.hpp -// CHECK-NEXT: exception.hpp -// CHECK-NEXT: detail/cl.h -// CHECK-NEXT: CL/cl.h -// CHECK-NEXT: CL/cl_version.h -// CHECK-NEXT: CL/cl_platform.h -// CHECK-NEXT: CL/cl_ext.h -// CHECK-NEXT: detail/common.hpp +// CHECK-NEXT: errc.hpp // CHECK-NEXT: range.hpp // CHECK-NEXT: info/info_desc.hpp // CHECK-NEXT: ext/oneapi/experimental/device_architecture.hpp @@ -107,6 +101,13 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/common.hpp +// CHECK-NEXT: exception.hpp +// CHECK-NEXT: detail/cl.h +// CHECK-NEXT: CL/cl.h +// CHECK-NEXT: CL/cl_version.h +// CHECK-NEXT: CL/cl_platform.h +// CHECK-NEXT: CL/cl_ext.h // CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp