diff --git a/sycl/include/sycl/detail/abi_neutral.hpp b/sycl/include/sycl/detail/abi_neutral.hpp new file mode 100644 index 0000000000000..5c8da357f616a --- /dev/null +++ b/sycl/include/sycl/detail/abi_neutral.hpp @@ -0,0 +1,81 @@ +//==---- abi_neutral.hpp - SYCL ABI-neutral return-type helpers -----------==// +// +// 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 + +#ifndef __SYCL_DEVICE_ONLY + +#include + +#include +#include +#include +#include + +namespace sycl { +inline namespace _V1 { +namespace detail { + +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; + +template auto convert_to_abi_neutral(ParamT &&Info) { + using ParamDecayT = std::decay_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); + } +} + +template auto convert_from_abi_neutral(ParamT &&Info) { + 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); + } +} + +} // namespace detail +} // namespace _V1 +} // namespace sycl + +#endif //__SYCL_DEVICE_ONLY diff --git a/sycl/include/sycl/detail/util.hpp b/sycl/include/sycl/detail/util.hpp index c1da408f89be9..fefbe7ad6fae3 100644 --- a/sycl/include/sycl/detail/util.hpp +++ b/sycl/include/sycl/detail/util.hpp @@ -10,6 +10,7 @@ #ifndef __SYCL_DEVICE_ONLY +#include #include #include @@ -73,55 +74,6 @@ struct CmpCStr { using SerializedObj = std::vector; -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; - -template auto convert_to_abi_neutral(ParamT &&Info) { - using ParamDecayT = std::decay_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); - } -} - -template auto convert_from_abi_neutral(ParamT &&Info) { - 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); - } -} - } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index 7e663bb13a890..4f6f58e5eb2d6 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -9,27 +9,32 @@ #pragma once #include +#include #include #include #include #include -#include #include -#include #include #include -#include #ifdef __SYCL_INTERNAL_API #include #endif #include +#include #include #include -#include #include +// Forward typedef of unified-runtime's `ur_native_handle_t`. Including +// here pulls a large C API surface; we only need +// the typedef name for one private member declaration. The typedef target +// (`uintptr_t`) matches ur_api.h, so a redeclaration in TUs that include both +// is well-formed. +typedef std::uintptr_t ur_native_handle_t; + namespace sycl { inline namespace _V1 { // TODO: make code thread-safe diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index 0df9e57fdd2a6..6c029a975c1ff 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -112,6 +112,7 @@ // CHECK-NEXT: device.hpp // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: ext/oneapi/kernel_properties.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_device.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_device.hpp.cpp index 2747183c65e1b..ac01bdb334394 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_device.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_device.hpp.cpp @@ -61,6 +61,7 @@ // CHECK-NEXT: detail/string.hpp // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-EMPTY: diff --git a/sycl/test/include_deps/sycl_khr_split_headers_handler.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_handler.hpp.cpp index a2a2e6dee77af..9cf2e59f91933 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_handler.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_handler.hpp.cpp @@ -134,6 +134,7 @@ // CHECK-NEXT: info/ext_oneapi_device_traits.def // CHECK-NEXT: info/ext_oneapi_kernel_queue_specific_traits.def // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: detail/reduction_forward.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_images.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_images.hpp.cpp index 4874fba9e43d9..abfacec5c4b54 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_images.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_images.hpp.cpp @@ -85,6 +85,7 @@ // CHECK-NEXT: info/ext_oneapi_kernel_queue_specific_traits.def // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: image.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_kernel_bundle.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_kernel_bundle.hpp.cpp index 6a0d1347cabdc..c3ed3b67b6d77 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_kernel_bundle.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_kernel_bundle.hpp.cpp @@ -59,6 +59,7 @@ // CHECK-NEXT: __spirv/spirv_vars.hpp // CHECK-NEXT: ext/oneapi/weak_object_base.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: detail/string.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: kernel_bundle.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_platform.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_platform.hpp.cpp index bdee99c41ec4d..94ac104fd4d09 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_platform.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_platform.hpp.cpp @@ -10,6 +10,8 @@ // CHECK-NEXT: feature_test.hpp // CHECK-NEXT: platform.hpp // CHECK-NEXT: backend_types.hpp +// CHECK-NEXT: detail/abi_neutral.hpp +// CHECK-NEXT: detail/string.hpp // CHECK-NEXT: detail/export.hpp // CHECK-NEXT: detail/info_desc_helpers.hpp // CHECK-NEXT: aspects.hpp @@ -58,8 +60,6 @@ // CHECK-NEXT: detail/impl_utils.hpp // CHECK-NEXT: __spirv/spirv_vars.hpp // CHECK-NEXT: ext/oneapi/weak_object_base.hpp -// CHECK-NEXT: detail/string.hpp // CHECK-NEXT: detail/string_view.hpp -// CHECK-NEXT: detail/util.hpp // CHECK-NEXT: device_selector.hpp // CHECK-EMPTY: diff --git a/sycl/test/include_deps/sycl_khr_split_headers_queue.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_queue.hpp.cpp index 85d2233286d61..cb29a55736d47 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_queue.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_queue.hpp.cpp @@ -115,6 +115,7 @@ // CHECK-NEXT: device.hpp // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: ext/oneapi/kernel_properties.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_reduction.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_reduction.hpp.cpp index bf7698794c8b2..5a6f2c0b9f46c 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_reduction.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_reduction.hpp.cpp @@ -128,6 +128,7 @@ // CHECK-NEXT: device.hpp // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: event.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_stream.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_stream.hpp.cpp index 3c82fa63e775d..aa4e695641b4b 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_stream.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_stream.hpp.cpp @@ -155,6 +155,7 @@ // CHECK-NEXT: info/ext_oneapi_device_traits.def // CHECK-NEXT: info/ext_oneapi_kernel_queue_specific_traits.def // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: detail/reduction_forward.hpp diff --git a/sycl/test/include_deps/sycl_khr_split_headers_usm.hpp.cpp b/sycl/test/include_deps/sycl_khr_split_headers_usm.hpp.cpp index eba6488996deb..5166451c5d9ed 100644 --- a/sycl/test/include_deps/sycl_khr_split_headers_usm.hpp.cpp +++ b/sycl/test/include_deps/sycl_khr_split_headers_usm.hpp.cpp @@ -85,6 +85,7 @@ // CHECK-NEXT: detail/string.hpp // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp +// CHECK-NEXT: detail/abi_neutral.hpp // CHECK-NEXT: device_selector.hpp // CHECK-NEXT: kernel_bundle_enums.hpp // CHECK-NEXT: platform.hpp