From 459e122a19ff4f112260c45cc735192814374a1f Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 1 Mar 2024 08:23:11 -0800 Subject: [PATCH] [SYCL] Initial changes for C++11 ABI=0 support (#12193) This PR attempts to support the usage case where the user sets _GLIBCXX_USE_CXX11_ABI=0 to use pre-C++11 ABI. In fact, this change addresses a specific issue with using different versions of the libstdc++ library (https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html has more details on this issue). One of the major changes I made in this PR involves calling `get_info<>()` API, which can return `stdA::string` as the requested information. Due to the ABI incompatibility issues, this API internally splits into 3 cases depending on the template parameter ``. 1. ``s that return a `std::string`. 2. ``s that return a `std::vector` 3. ``s that return something other than 1 or 2 above. The case 1 and 2 should return `detail::string` and `std::vector` instead and reconstruct `std::string`s. This is required because ABIs can be different between the header and CPP files. All these 3 cases are implemented using `get_info_impl`. Then, I changed the macro definition of `__SYCL_PARAM_TRAITS_SPEC` to return different types depending on the `` return_types. This way, we can only change the boundary between the header file and the entry point of the libsycl. --------- Signed-off-by: Byoungro So Co-authored-by: Alexey Bader Co-authored-by: Victor Perez Co-authored-by: Julian Oppermann Co-authored-by: aelovikov-intel Co-authored-by: Sergey Semenov --- sycl/include/sycl/detail/string.hpp | 72 ++++++++++++++ sycl/include/sycl/detail/string_view.hpp | 52 ++++++++++ sycl/include/sycl/detail/util.hpp | 24 ++++- sycl/include/sycl/device.hpp | 60 ++++++++---- sycl/include/sycl/exception.hpp | 42 +++++--- sycl/include/sycl/handler.hpp | 41 +++++++- sycl/include/sycl/kernel_bundle.hpp | 20 +++- sycl/include/sycl/platform.hpp | 95 +++++++++++++++---- sycl/source/detail/queue_impl.hpp | 7 +- sycl/source/device.cpp | 40 ++++++-- sycl/source/exception.cpp | 13 +++ sycl/source/handler.cpp | 42 +++++++- sycl/source/kernel_bundle.cpp | 7 +- sycl/source/platform.cpp | 19 +++- .../arg_mask/EliminatedArgMask.cpp | 4 + .../scheduler/SchedulerTestUtils.hpp | 4 + 16 files changed, 467 insertions(+), 75 deletions(-) create mode 100644 sycl/include/sycl/detail/string.hpp create mode 100644 sycl/include/sycl/detail/string_view.hpp diff --git a/sycl/include/sycl/detail/string.hpp b/sycl/include/sycl/detail/string.hpp new file mode 100644 index 0000000000000..28caa74d37357 --- /dev/null +++ b/sycl/include/sycl/detail/string.hpp @@ -0,0 +1,72 @@ +//==----------------- string.hpp - SYCL standard header file ---------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +#pragma once + +namespace sycl { +inline namespace _V1 { +namespace detail { + +// This class and detail::string_view class are intended to support +// different ABIs between libsycl and the user program. +// This class is not inteded to replace std::string for general purpose usage. +class string { + char *str = nullptr; + +public: + string() noexcept = default; + ~string() { delete[] str; } + + string(std::string_view strn) { + size_t len = strn.length(); + str = new char[len + 1]; + strn.copy(str, len); + str[len] = 0; + } + + friend void swap(string &lhs, string &rhs) noexcept { + std::swap(lhs.str, rhs.str); + } + + string(string &&other) noexcept { swap(*this, other); } + string(const string &other) { + if (other.str == nullptr) + return; + *this = string{other.str}; + } + + string &operator=(string &&other) noexcept { + swap(*this, other); + return *this; + } + string &operator=(const string &other) { + *this = string{other}; + return *this; + } + + string &operator=(std::string_view strn) { + *this = string{strn}; + return *this; + } + + const char *c_str() const noexcept { return str ? str : ""; } + + friend bool operator==(const string &lhs, std::string_view rhs) noexcept { + return rhs == lhs.c_str(); + } + friend bool operator==(std::string_view lhs, const string &rhs) noexcept { + return lhs == rhs.c_str(); + } +}; + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/include/sycl/detail/string_view.hpp b/sycl/include/sycl/detail/string_view.hpp new file mode 100644 index 0000000000000..7815ecc4ce676 --- /dev/null +++ b/sycl/include/sycl/detail/string_view.hpp @@ -0,0 +1,52 @@ +//==-------------- string_view.hpp - SYCL standard header file -------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +#pragma once + +namespace sycl { +inline namespace _V1 { +namespace detail { + +// This class and detail::string class are intended to support +// different ABIs between libsycl and the user program. +// This class is not inteded to replace std::string_view for general purpose +// usage. +class string_view { + const char *str = nullptr; + +public: + string_view() noexcept = default; + string_view(const string_view &strn) noexcept = default; + string_view(string_view &&strn) noexcept = default; + string_view(std::string_view strn) noexcept : str(strn.data()) {} + + string_view &operator=(string_view &&strn) noexcept = default; + string_view &operator=(const string_view &strn) noexcept = default; + + string_view &operator=(std::string_view strn) noexcept { + str = strn.data(); + return *this; + } + + const char *data() const noexcept { return str; } + + friend bool operator==(const string_view &lhs, + std::string_view rhs) noexcept { + return rhs == lhs.data(); + } + friend bool operator==(std::string_view lhs, + const string_view &rhs) noexcept { + return lhs == rhs.data(); + } +}; + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/include/sycl/detail/util.hpp b/sycl/include/sycl/detail/util.hpp index 1ce0a059bee19..4b831e2e38e8f 100644 --- a/sycl/include/sycl/detail/util.hpp +++ b/sycl/include/sycl/detail/util.hpp @@ -11,7 +11,9 @@ #ifndef __SYCL_DEVICE_ONLY #include - +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#include +#endif #include #include #include @@ -67,6 +69,26 @@ struct CmpCStr { using SerializedObj = std::vector; +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +template struct ABINeutralT { using type = T; }; +// We need special handling of std::string to handle ABI incompatibility +// for get_info<>() when it returns std::string and vector. +// For this purpose, get_info_impl<>() is created to handle special +// cases, and it is only called internally and not exposed to the user. +// The following ReturnType structure is intended for general return type, +// and special return types (std::string and vector of it). + +template <> struct ABINeutralT { using type = detail::string; }; + +template <> struct ABINeutralT> { + using type = std::vector; +}; + +template using ABINeutralT_t = typename ABINeutralT::type; +#else +template using ABINeutralT_t = T; +#endif + } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 03b5a8f10ca33..df265e1585e83 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -8,24 +8,30 @@ #pragma once -#include // for aspect -#include // for backend -#include // for __SY... -#include // for __SY... -#include // for is_d... -#include // for Owne... -#include // for pi_n... -#include // for Enab... -#include // for arch... -#include // for part... -#include // for plat... - -#include // for size_t -#include // for shar... -#include // for string -#include // for add_... -#include // for hash -#include // for vector +#include +#include +#include +#include +#include +#include +#include +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#include +#include +#endif +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include namespace sycl { inline namespace _V1 { @@ -214,8 +220,17 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { /// type associated with the param parameter. /// /// \return device info of type described in Table 4.20. +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + template + typename detail::is_device_info_desc::return_type get_info() const { + return detail::convert_from_abi_neutral(get_info_impl()); + } +#else template - typename detail::is_device_info_desc::return_type get_info() const; + detail::ABINeutralT_t< + typename detail::is_device_info_desc::return_type> + get_info() const; +#endif /// Check SYCL extension support by device /// @@ -291,6 +306,13 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; + +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + template + typename detail::ABINeutralT_t< + typename detail::is_device_info_desc::return_type> + get_info_impl() const; +#endif }; } // namespace _V1 diff --git a/sycl/include/sycl/exception.hpp b/sycl/include/sycl/exception.hpp index f5c52ff3d8257..59bbd9bcdf774 100644 --- a/sycl/include/sycl/exception.hpp +++ b/sycl/include/sycl/exception.hpp @@ -74,11 +74,21 @@ class __SYCL_EXPORT exception : public virtual std::exception { exception(std::error_code, const char *Msg); +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + exception(std::error_code Ec, const std::string &Msg) + : exception(Ec, nullptr, Msg.c_str()) {} +#else exception(std::error_code, const std::string &Msg); +#endif // new SYCL 2020 constructors exception(std::error_code); +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + exception(int EV, const std::error_category &ECat, const std::string &WhatArg) + : exception(EV, ECat, WhatArg.c_str()) {} +#else exception(int, const std::error_category &, const std::string &); +#endif exception(int, const std::error_category &, const char *); exception(int, const std::error_category &); @@ -111,13 +121,13 @@ class __SYCL_EXPORT exception : public virtual std::exception { protected: // base constructors used by SYCL 1.2.1 exception subclasses - exception(std::error_code ec, const char *Msg, const pi_int32 PIErr, + exception(std::error_code Ec, const char *Msg, const pi_int32 PIErr, std::shared_ptr Context = nullptr) - : exception(ec, std::string(Msg), PIErr, Context) {} + : exception(Ec, std::string(Msg), PIErr, Context) {} - exception(std::error_code ec, const std::string &Msg, const pi_int32 PIErr, + exception(std::error_code Ec, const std::string &Msg, const pi_int32 PIErr, std::shared_ptr Context = nullptr) - : exception(ec, Context, Msg + " " + detail::codeToString(PIErr)) { + : exception(Ec, Context, Msg + " " + detail::codeToString(PIErr)) { MPIErr = PIErr; } @@ -125,10 +135,18 @@ class __SYCL_EXPORT exception : public virtual std::exception { : MMsg(std::make_shared(Msg)), MContext(nullptr) {} // base constructor for all SYCL 2020 constructors - // exception(context *ctxPtr, std::error_code ec, const std::string + // exception(context *ctxPtr, std::error_code Ec, const std::string // &what_arg); - exception(std::error_code ec, std::shared_ptr SharedPtrCtx, +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + exception(std::error_code Ec, std::shared_ptr SharedPtrCtx, + const std::string &what_arg) + : exception(Ec, SharedPtrCtx, what_arg.c_str()) {} + exception(std::error_code Ec, std::shared_ptr SharedPtrCtx, + const char *WhatArg); +#else + exception(std::error_code Ec, std::shared_ptr SharedPtrCtx, const std::string &what_arg); +#endif }; class __SYCL2020_DEPRECATED( @@ -143,12 +161,12 @@ class __SYCL2020_DEPRECATED( runtime_error(const std::string &Msg, pi_int32 Err) : exception(make_error_code(errc::runtime), Msg, Err) {} - runtime_error(std::error_code ec, const std::string &Msg, + runtime_error(std::error_code Ec, const std::string &Msg, const pi_int32 PIErr) - : exception(ec, Msg, PIErr) {} + : exception(Ec, Msg, PIErr) {} protected: - runtime_error(std::error_code ec) : exception(ec) {} + runtime_error(std::error_code Ec) : exception(Ec) {} }; class __SYCL2020_DEPRECATED("use sycl::exception with sycl::errc::kernel or " @@ -230,10 +248,10 @@ class __SYCL2020_DEPRECATED( : exception(make_error_code(errc::invalid), Msg, Err) {} protected: - device_error(std::error_code ec) : exception(ec) {} + device_error(std::error_code Ec) : exception(Ec) {} - device_error(std::error_code ec, const std::string &Msg, const pi_int32 PIErr) - : exception(ec, Msg, PIErr) {} + device_error(std::error_code Ec, const std::string &Msg, const pi_int32 PIErr) + : exception(Ec, Msg, PIErr) {} }; class __SYCL2020_DEPRECATED( diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 7a6371624b3ef..51e2f41de9d75 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -21,6 +21,10 @@ #include #include #include +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#include +#include +#endif #include #include #include @@ -415,6 +419,10 @@ template bool range_size_fits_in_size_t(const range &r) { } return true; } +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES +using string = std::string; +using string_view = std::string; +#endif } // namespace detail @@ -543,7 +551,7 @@ class __SYCL_EXPORT handler { bool IsKernelCreatedFromSource, bool IsESIMD); /// \return a string containing name of SYCL kernel. - std::string getKernelName(); + detail::string getKernelName(); template bool lambdaAndKernelHaveEqualName() { // TODO It is unclear a kernel and a lambda/functor must to be equal or not @@ -553,8 +561,8 @@ class __SYCL_EXPORT handler { // values of arguments for the kernel. assert(MKernel && "MKernel is not initialized"); const std::string LambdaName = detail::KernelInfo::getName(); - const std::string KernelName = getKernelName(); - return LambdaName == KernelName; + detail::string KernelName = getKernelName(); + return KernelName == LambdaName; } /// Saves the location of user's code passed in \p CodeLoc for future usage in @@ -837,7 +845,14 @@ class __SYCL_EXPORT handler { /// /// \param KernelName is the name of the SYCL kernel to check that the used /// kernel bundle contains. +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + void verifyUsedKernelBundle(const std::string &KernelName) { + verifyUsedKernelBundleInternal(detail::string_view{KernelName}); + } + void verifyUsedKernelBundleInternal(detail::string_view KernelName); +#else void verifyUsedKernelBundle(const std::string &KernelName); +#endif /// Stores lambda to the template-free object /// @@ -3307,7 +3322,7 @@ class __SYCL_EXPORT handler { std::vector MAssociatedAccesors; /// Struct that encodes global size, local size, ... detail::NDRDescT MNDRDesc; - std::string MKernelName; + detail::string MKernelName; /// Storage for a sycl::kernel object. std::shared_ptr MKernel; /// Type of the command group, e.g. kernel, fill. Can also encode version. @@ -3409,8 +3424,17 @@ class __SYCL_EXPORT handler { /// expr m_Storage member /// \param Size the size of data getting read back / to. /// \param Block if read operation is blocking, default to false. +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, size_t Size, + bool Block = false) { + ext_intel_read_host_pipe(detail::string_view(Name), Ptr, Size, Block); + } + void ext_intel_read_host_pipe(detail::string_view Name, void *Ptr, + size_t Size, bool Block = false); +#else void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block = false); +#endif /// Write to host pipes given a host address and /// \param Name name of the host pipe to be passed into lower level runtime @@ -3418,8 +3442,17 @@ class __SYCL_EXPORT handler { /// expr m_Storage member /// \param Size the size of data getting read back / to. /// \param Block if write opeartion is blocking, default to false. +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES void ext_intel_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block = false) { + ext_intel_write_host_pipe(detail::string_view(Name), Ptr, Size, Block); + } + void ext_intel_write_host_pipe(detail::string_view Name, void *Ptr, size_t Size, bool Block = false); +#else + void ext_intel_write_host_pipe(const std::string &Name, void *Ptr, + size_t Size, bool Block = false); +#endif friend class ext::oneapi::experimental::detail::graph_impl; bool DisableRangeRounding(); diff --git a/sycl/include/sycl/kernel_bundle.hpp b/sycl/include/sycl/kernel_bundle.hpp index d48cf27b3d531..6114defc47f21 100644 --- a/sycl/include/sycl/kernel_bundle.hpp +++ b/sycl/include/sycl/kernel_bundle.hpp @@ -15,10 +15,13 @@ #include // for OwnerLessBase #include // for pi_native_handle #include // for cast -#include // for device -#include // for kernel, kernel_bundle -#include // for bundle_state -#include // for property_list +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#include +#endif +#include // for device +#include // for kernel, kernel_bundle +#include // for bundle_state +#include // for property_list #include // PropertyT #include // build_options @@ -447,9 +450,12 @@ kernel_bundle(kernel_bundle &&) -> kernel_bundle; ///////////////////////// namespace detail { +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES +using string_view = std::string; +#endif // Internal non-template versions of get_kernel_id API which is used by public // onces -__SYCL_EXPORT kernel_id get_kernel_id_impl(std::string KernelName); +__SYCL_EXPORT kernel_id get_kernel_id_impl(string_view KernelName); } // namespace detail /// \returns the kernel_id associated with the KernelName @@ -457,7 +463,11 @@ template kernel_id get_kernel_id() { // FIXME: This must fail at link-time if KernelName not in any available // translation units. using KI = sycl::detail::KernelInfo; +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + return detail::get_kernel_id_impl(detail::string_view{KI::getName()}); +#else return detail::get_kernel_id_impl(KI::getName()); +#endif } /// \returns a vector with all kernel_id's defined in the application diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index 8cffdcd99e67e..32a93acd0a873 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -8,26 +8,31 @@ #pragma once -#include // for aspect -#include // for backend, backend_return_t -#include // for context -#include // for __SYCL2020_DEPRECATED -#include // for __SYCL_EXPORT -#include // for is_platform_info_desc -#include // for OwnerLessBase -#include // for pi_native_handle -#include // for EnableIfSYCL2020DeviceS... -#include // for device_type +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +#include +#include +#endif +#include +#include +#include #ifdef __SYCL_INTERNAL_API #include #endif -#include // for size_t -#include // for shared_ptr, hash, opera... -#include // for string -#include // for hash -#include // for vector +#include +#include +#include +#include +#include namespace sycl { inline namespace _V1 { @@ -51,6 +56,47 @@ class platform_impl; /// /// \param Val Indicates if extension should be enabled/disabled void __SYCL_EXPORT enable_ext_oneapi_default_context(bool Val); + +template auto convert_to_abi_neutral(ParamT &&Info) { +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + using ParamNoRef = std::remove_reference_t; + if constexpr (std::is_same_v) { + return detail::string{Info}; + } else if constexpr (std::is_same_v>) { + std::vector Res; + Res.reserve(Info.size()); + for (std::string &Str : Info) { + Res.push_back(detail::string{Str}); + } + return Res; + } else { + return std::forward(Info); + } +#else + return std::forward(Info); +#endif +} + +template auto convert_from_abi_neutral(ParamT &&Info) { +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + using ParamNoRef = std::remove_reference_t; + if constexpr (std::is_same_v) { + return Info.c_str(); + } else if constexpr (std::is_same_v>) { + std::vector Res; + Res.reserve(Info.size()); + for (detail::string &Str : Info) { + Res.push_back(Str.c_str()); + } + return Res; + } else { + return std::forward(Info); + } +#else + return std::forward(Info); +#endif +} } // namespace detail namespace ext::oneapi { // Forward declaration @@ -144,9 +190,17 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { /// Queries this SYCL platform for info. /// /// The return type depends on information being queried. +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES template - typename detail::is_platform_info_desc::return_type get_info() const; - + typename detail::is_platform_info_desc::return_type get_info() const { + return detail::convert_from_abi_neutral(get_info_impl()); + } +#else + template + detail::ABINeutralT_t< + typename detail::is_platform_info_desc::return_type> + get_info() const; +#endif /// Returns all available SYCL platforms in the system. /// /// The resulting vector always contains a single SYCL host platform instance. @@ -206,6 +260,13 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { template friend auto get_native(const SyclObjectT &Obj) -> backend_return_t; + +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + template + typename detail::ABINeutralT_t< + typename detail::is_platform_info_desc::return_type> + get_info_impl() const; +#endif }; // class platform } // namespace _V1 } // namespace sycl diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index c6b7be77803c7..ad06891ebe568 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -836,10 +836,9 @@ class queue_impl { if (IsKernel) // Kernel only uses assert if it's non interop one - KernelUsesAssert = - !(Handler.MKernel && Handler.MKernel->isInterop()) && - ProgramManager::getInstance().kernelUsesAssert(Handler.MKernelName); - + KernelUsesAssert = !(Handler.MKernel && Handler.MKernel->isInterop()) && + ProgramManager::getInstance().kernelUsesAssert( + Handler.MKernelName.c_str()); finalizeHandler(Handler, Event); (*PostProcess)(IsKernel, KernelUsesAssert, Event); diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 73a05080c5b0d..2bf76a3fa9407 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -15,8 +15,6 @@ #include #include -#include - namespace sycl { inline namespace _V1 { namespace detail { @@ -135,14 +133,23 @@ bool device::has_extension(const std::string &extension_name) const { } template -typename detail::is_device_info_desc::return_type +detail::ABINeutralT_t::return_type> +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +device::get_info_impl() const { +#else device::get_info() const { - return impl->template get_info(); +#endif + return detail::convert_to_abi_neutral(impl->template get_info()); } // Explicit override. Not fulfilled by #include device_traits.def below. template <> +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +__SYCL_EXPORT device +device::get_info_impl() const { +#else __SYCL_EXPORT device device::get_info() const { +#endif // With ONEAPI_DEVICE_SELECTOR the impl.MRootDevice is preset and may be // overridden (ie it may be nullptr on a sub-device) The PI of the sub-devices // have parents, but we don't want to return them. They must pretend to be @@ -157,7 +164,11 @@ __SYCL_EXPORT device device::get_info() const { template <> __SYCL_EXPORT std::vector +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +device::get_info_impl() const { +#else device::get_info() const { +#endif std::vector DeviceAspects{ #define __SYCL_ASPECT(ASPECT, ID) aspect::ASPECT, #include @@ -181,14 +192,25 @@ device::get_info() const { } template <> +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +__SYCL_EXPORT bool device::get_info_impl() const { +#else __SYCL_EXPORT bool device::get_info() const { +#endif // Explicit specialization is needed due to the class of info handle. The // implementation is done in get_device_info_impl. return impl->template get_info(); } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ - template __SYCL_EXPORT ReturnT device::get_info() const; + template __SYCL_EXPORT detail::ABINeutralT_t \ + device::get_info_impl() const; +#else +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ + template __SYCL_EXPORT detail::ABINeutralT_t \ + device::get_info() const; +#endif #define __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(DescType, Desc, ReturnT, PiCode) @@ -196,9 +218,15 @@ __SYCL_EXPORT bool device::get_info() const { #undef __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED #undef __SYCL_PARAM_TRAITS_SPEC +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES #define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \ - template __SYCL_EXPORT ReturnT \ + template __SYCL_EXPORT detail::ABINeutralT_t \ + device::get_info_impl() const; +#else +#define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \ + template __SYCL_EXPORT typename detail::ABINeutralT_t \ device::get_info() const; +#endif #include #include diff --git a/sycl/source/exception.cpp b/sycl/source/exception.cpp index 88141f613fd53..ad1d39e3dae18 100644 --- a/sycl/source/exception.cpp +++ b/sycl/source/exception.cpp @@ -19,15 +19,19 @@ inline namespace _V1 { exception::exception(std::error_code EC, const char *Msg) : exception(EC, nullptr, Msg) {} +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES exception::exception(std::error_code EC, const std::string &Msg) : exception(EC, nullptr, Msg) {} +#endif // new SYCL 2020 constructors exception::exception(std::error_code EC) : exception(EC, nullptr, "") {} +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES exception::exception(int EV, const std::error_category &ECat, const std::string &WhatArg) : exception({EV, ECat}, nullptr, WhatArg) {} +#endif exception::exception(int EV, const std::error_category &ECat, const char *WhatArg) @@ -58,12 +62,21 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat) : exception(Ctx, EV, ECat, "") {} // protected base constructor for all SYCL 2020 constructors +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +exception::exception(std::error_code EC, std::shared_ptr SharedPtrCtx, + const char *WhatArg) + : MMsg(std::make_shared(WhatArg)), + MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) { + detail::GlobalHandler::instance().TraceEventXPTI(MMsg->c_str()); +} +#else exception::exception(std::error_code EC, std::shared_ptr SharedPtrCtx, const std::string &WhatArg) : MMsg(std::make_shared(WhatArg)), MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) { detail::GlobalHandler::instance().TraceEventXPTI(MMsg->c_str()); } +#endif exception::~exception() {} diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 94baf075b8c23..5b40f1b3b07c3 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -173,7 +173,12 @@ event handler::finalize() { !MImpl->isStateExplicitKernelBundle()) { auto Dev = MGraph ? MGraph->getDevice() : MQueue->get_device(); kernel_id KernelID = +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + detail::ProgramManager::getInstance().getSYCLKernelID( + MKernelName.c_str()); +#else detail::ProgramManager::getInstance().getSYCLKernelID(MKernelName); +#endif bool KernelInserted = KernelBundleImpPtr->add_kernel(KernelID, Dev); // If kernel was not inserted and the bundle is in input mode we try // building it and trying to find the kernel in executable mode @@ -232,7 +237,11 @@ event handler::finalize() { // uint32_t StreamID, uint64_t InstanceID, xpti_td* TraceEvent, int32_t StreamID = xptiRegisterStream(detail::SYCL_STREAM_NAME); auto [CmdTraceEvent, InstanceID] = emitKernelInstrumentationData( +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + StreamID, MKernel, MCodeLoc, MKernelName.c_str(), MQueue, MNDRDesc, +#else StreamID, MKernel, MCodeLoc, MKernelName, MQueue, MNDRDesc, +#endif KernelBundleImpPtr, MArgs); auto EnqueueKernel = [&, CmdTraceEvent = CmdTraceEvent, InstanceID = InstanceID]() { @@ -282,7 +291,11 @@ event handler::finalize() { } else { Result = enqueueImpKernel( MQueue, MNDRDesc, MArgs, KernelBundleImpPtr, MKernel, +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + MKernelName.c_str(), RawEvents, NewEvent, nullptr, +#else MKernelName, RawEvents, NewEvent, nullptr, +#endif MImpl->MKernelCacheConfig, MImpl->MKernelIsCooperative); } } @@ -304,7 +317,12 @@ event handler::finalize() { // Kernel only uses assert if it's non interop one bool KernelUsesAssert = !(MKernel && MKernel->isInterop()) && +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + detail::ProgramManager::getInstance().kernelUsesAssert( + MKernelName.c_str()); +#else detail::ProgramManager::getInstance().kernelUsesAssert(MKernelName); +#endif DiscardEvent = !KernelUsesAssert; } @@ -340,7 +358,11 @@ event handler::finalize() { CommandGroup.reset(new detail::CGExecKernel( std::move(MNDRDesc), std::move(MHostKernel), std::move(MKernel), std::move(MImpl->MKernelBundle), std::move(CGData), std::move(MArgs), +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + MKernelName.c_str(), std::move(MStreamStorage), +#else MKernelName, std::move(MStreamStorage), +#endif std::move(MImpl->MAuxiliaryResources), MCGType, MImpl->MKernelCacheConfig, MImpl->MKernelIsCooperative, MCodeLoc)); break; @@ -866,11 +888,15 @@ void handler::extractArgsAndReqsFromLambda( // Calling methods of kernel_impl requires knowledge of class layout. // As this is impossible in header, there's a function that calls necessary // method inside the library and returns the result. -std::string handler::getKernelName() { - return MKernel->get_info(); +detail::string handler::getKernelName() { + return detail::string{MKernel->get_info()}; } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +void handler::verifyUsedKernelBundleInternal(detail::string_view KernelName) { +#else void handler::verifyUsedKernelBundle(const std::string &KernelName) { +#endif auto UsedKernelBundleImplPtr = getOrInsertHandlerKernelBundle(/*Insert=*/false); if (!UsedKernelBundleImplPtr) @@ -1385,9 +1411,15 @@ id<2> handler::computeFallbackKernelBounds(size_t Width, size_t Height) { return id<2>{std::min(ItemLimit[0], Height), std::min(ItemLimit[1], Width)}; } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +void handler::ext_intel_read_host_pipe(detail::string_view Name, void *Ptr, + size_t Size, bool Block) { + MImpl->HostPipeName = Name.data(); +#else void handler::ext_intel_read_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block) { MImpl->HostPipeName = Name; +#endif MImpl->HostPipePtr = Ptr; MImpl->HostPipeTypeSize = Size; MImpl->HostPipeBlocking = Block; @@ -1395,9 +1427,15 @@ void handler::ext_intel_read_host_pipe(const std::string &Name, void *Ptr, setType(detail::CG::ReadWriteHostPipe); } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +void handler::ext_intel_write_host_pipe(detail::string_view Name, void *Ptr, + size_t Size, bool Block) { + MImpl->HostPipeName = Name.data(); +#else void handler::ext_intel_write_host_pipe(const std::string &Name, void *Ptr, size_t Size, bool Block) { MImpl->HostPipeName = Name; +#endif MImpl->HostPipePtr = Ptr; MImpl->HostPipeTypeSize = Size; MImpl->HostPipeBlocking = Block; diff --git a/sycl/source/kernel_bundle.cpp b/sycl/source/kernel_bundle.cpp index e7a2fd0902d17..5fcad0af99ca3 100644 --- a/sycl/source/kernel_bundle.cpp +++ b/sycl/source/kernel_bundle.cpp @@ -139,8 +139,13 @@ removeDuplicateDevices(const std::vector &Devs) { return UniqueDevices; } -kernel_id get_kernel_id_impl(std::string KernelName) { +kernel_id get_kernel_id_impl(string_view KernelName) { +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + return detail::ProgramManager::getInstance().getSYCLKernelID( + KernelName.data()); +#else return detail::ProgramManager::getInstance().getSYCLKernelID(KernelName); +#endif } detail::KernelBundleImplPtr diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 5cc2a49801902..c991f27eda51b 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -57,18 +57,29 @@ std::vector platform::get_platforms() { backend platform::get_backend() const noexcept { return impl->getBackend(); } template -typename detail::is_platform_info_desc::return_type +detail::ABINeutralT_t< + typename detail::is_platform_info_desc::return_type> +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES +platform::get_info_impl() const { +#else platform::get_info() const { - return impl->get_info(); +#endif + return detail::convert_to_abi_neutral(impl->template get_info()); } pi_native_handle platform::getNative() const { return impl->getNative(); } bool platform::has(aspect Aspect) const { return impl->has(Aspect); } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ - template __SYCL_EXPORT ReturnT platform::get_info() \ - const; + template __SYCL_EXPORT detail::ABINeutralT_t \ + platform::get_info_impl() const; +#else +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ + template __SYCL_EXPORT detail::ABINeutralT_t \ + platform::get_info() const; +#endif #include #undef __SYCL_PARAM_TRAITS_SPEC diff --git a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp index b3b27a502bcee..f9f580022ccad 100644 --- a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp +++ b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp @@ -122,7 +122,11 @@ class MockHandler : public sycl::handler { std::move(CGH->MNDRDesc), std::move(CGH->MHostKernel), std::move(CGH->MKernel), std::move(MImpl->MKernelBundle), std::move(CGH->CGData), std::move(CGH->MArgs), +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + CGH->MKernelName.c_str(), std::move(CGH->MStreamStorage), +#else std::move(CGH->MKernelName), std::move(CGH->MStreamStorage), +#endif std::move(MImpl->MAuxiliaryResources), CGH->MCGType, {}, MImpl->MKernelIsCooperative, CGH->MCodeLoc)); break; diff --git a/sycl/unittests/scheduler/SchedulerTestUtils.hpp b/sycl/unittests/scheduler/SchedulerTestUtils.hpp index a1d1eb8058826..2a2f20c297a25 100644 --- a/sycl/unittests/scheduler/SchedulerTestUtils.hpp +++ b/sycl/unittests/scheduler/SchedulerTestUtils.hpp @@ -258,7 +258,11 @@ class MockHandler : public sycl::handler { return CGData.MEvents; } std::vector &getArgs() { return MArgs; } +#ifdef __INTEL_PREVIEW_BREAKING_CHANGES + std::string getKernelName() { return MKernelName.c_str(); } +#else std::string &getKernelName() { return MKernelName; } +#endif std::shared_ptr &getKernel() { return MKernel; } std::unique_ptr &getHostTask() { return MHostTask; } std::shared_ptr &getQueue() { return MQueue; }