Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions sycl/include/sycl/detail/abi_neutral.hpp
Original file line number Diff line number Diff line change
@@ -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 <sycl/detail/string.hpp>

#include <string>
#include <type_traits>
#include <utility>
#include <vector>

namespace sycl {
inline namespace _V1 {
namespace detail {

template <typename T> 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<std::string>.
// 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<std::string> {
using type = detail::string;
};

template <> struct ABINeutralT<std::vector<std::string>> {
using type = std::vector<detail::string>;
};

template <typename T> using ABINeutralT_t = typename ABINeutralT<T>::type;

template <typename ParamT> auto convert_to_abi_neutral(ParamT &&Info) {
using ParamDecayT = std::decay_t<ParamT>;
if constexpr (std::is_same_v<ParamDecayT, std::string>) {
return detail::string{Info};
} else if constexpr (std::is_same_v<ParamDecayT, std::vector<std::string>>) {
std::vector<detail::string> Res;
Res.reserve(Info.size());
for (std::string &Str : Info) {
Res.push_back(detail::string{Str});
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

template <typename ParamT> auto convert_from_abi_neutral(ParamT &&Info) {
using ParamNoRef = std::remove_reference_t<ParamT>;
if constexpr (std::is_same_v<ParamNoRef, detail::string>) {
return Info.c_str();
} else if constexpr (std::is_same_v<ParamNoRef,
std::vector<detail::string>>) {
std::vector<std::string> Res;
Res.reserve(Info.size());
for (detail::string &Str : Info) {
Res.push_back(Str.c_str());
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

} // namespace detail
} // namespace _V1
} // namespace sycl

#endif //__SYCL_DEVICE_ONLY
50 changes: 1 addition & 49 deletions sycl/include/sycl/detail/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#ifndef __SYCL_DEVICE_ONLY

#include <sycl/detail/abi_neutral.hpp>
#include <sycl/detail/defines.hpp>
#include <sycl/detail/string.hpp>

Expand Down Expand Up @@ -73,55 +74,6 @@ struct CmpCStr {

using SerializedObj = std::vector<unsigned char>;

template <typename T> 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<std::string>.
// 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<std::string> { using type = detail::string; };

template <> struct ABINeutralT<std::vector<std::string>> {
using type = std::vector<detail::string>;
};

template <typename T> using ABINeutralT_t = typename ABINeutralT<T>::type;

template <typename ParamT> auto convert_to_abi_neutral(ParamT &&Info) {
using ParamDecayT = std::decay_t<ParamT>;
if constexpr (std::is_same_v<ParamDecayT, std::string>) {
return detail::string{Info};
} else if constexpr (std::is_same_v<ParamDecayT, std::vector<std::string>>) {
std::vector<detail::string> Res;
Res.reserve(Info.size());
for (std::string &Str : Info) {
Res.push_back(detail::string{Str});
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

template <typename ParamT> auto convert_from_abi_neutral(ParamT &&Info) {
using ParamNoRef = std::remove_reference_t<ParamT>;
if constexpr (std::is_same_v<ParamNoRef, detail::string>) {
return Info.c_str();
} else if constexpr (std::is_same_v<ParamNoRef,
std::vector<detail::string>>) {
std::vector<std::string> Res;
Res.reserve(Info.size());
for (detail::string &Str : Info) {
Res.push_back(Str.c_str());
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

} // namespace detail
} // namespace _V1
} // namespace sycl
Expand Down
13 changes: 9 additions & 4 deletions sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@
#pragma once

#include <sycl/backend_types.hpp>
#include <sycl/detail/abi_neutral.hpp>
#include <sycl/detail/defines_elementary.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/detail/owner_less_base.hpp>
#include <sycl/detail/string.hpp>
#include <sycl/detail/string_view.hpp>
#include <sycl/detail/util.hpp>
#include <sycl/device_selector.hpp>
#include <sycl/info/info_desc.hpp>
#include <unified-runtime/ur_api.h>

#ifdef __SYCL_INTERNAL_API
#include <sycl/detail/cl.h>
#endif

#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <variant>
#include <vector>

// Forward typedef of unified-runtime's `ur_native_handle_t`. Including
// <unified-runtime/ur_api.h> 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
Expand Down
1 change: 1 addition & 0 deletions sycl/test/include_deps/sycl_detail_core.hpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading