Skip to content

Commit 1581225

Browse files
[SYCL][NFC] Refactor #includes (#16030)
This patch is a collection of various cleanups made in public headers: - Cleaned up many unnecessary includes. It doesn't change total amount of header files we use in total by `sycl.hpp`, but makes our code cleaner - Made it so there are no headers (except for `backend/%backend_name%.hpp`) depend on `backend.hpp` and it is (almost) only included by `sycl.hpp`, so that we can make it an opt-in header - Removed `types.hpp` in favor of direct use of `vector.hpp` - Added missing includes and forward-declarations to places where we relied on implicit includes - Moved certain helper function declarations/definitions to better places (common utils to utils headers, library-only declarations to library headers, etc.)
1 parent 528d43a commit 1581225

File tree

76 files changed

+142
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+142
-167
lines changed

libdevice/nativecpu_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "device.h"
1818
#include <cstdint>
1919
#include <sycl/__spirv/spirv_ops.hpp>
20-
#include <sycl/types.hpp>
20+
#include <sycl/vector.hpp>
2121

2222
// including state definition from Native CPU UR adapter
2323
#include "nativecpu_state.hpp"

sycl/include/sycl/aliases.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
12-
#include <sycl/half_type.hpp> // for half
1312

1413
#include <cstdint> // for uint8_t, int16_t, int32_t
1514

sycl/include/sycl/backend.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@
1515
#include <sycl/buffer.hpp> // for buffer_allocator
1616
#include <sycl/context.hpp> // for context, get_na...
1717
#include <sycl/detail/backend_traits.hpp> // for InteropFeatureS...
18-
#include <sycl/detail/cl.h> // for _cl_event
1918
#include <sycl/detail/defines_elementary.hpp> // for __SYCL_DEPRECATED
2019
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
2120
#include <sycl/detail/impl_utils.hpp> // for createSyclObjFr...
2221
#include <sycl/device.hpp> // for device, get_native
2322
#include <sycl/event.hpp> // for event, get_native
2423
#include <sycl/exception.hpp> // for make_error_code
2524
#include <sycl/feature_test.hpp> // for SYCL_BACKEND_OP...
26-
#include <sycl/handler.hpp> // for buffer
2725
#include <sycl/image.hpp> // for image, image_al...
28-
#include <sycl/kernel.hpp> // for kernel, get_native
2926
#include <sycl/kernel_bundle.hpp> // for kernel_bundle
3027
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
3128
#include <sycl/platform.hpp> // for platform, get_n...
32-
#include <sycl/property_list.hpp> // for property_list
3329
#include <sycl/queue.hpp> // for queue, get_native
3430
#include <ur_api.h> // for ur_native_handle_t
3531

@@ -60,13 +56,12 @@
6056
namespace sycl {
6157
inline namespace _V1 {
6258

59+
class property_list;
60+
6361
namespace detail {
6462
// TODO each backend can have its own custom errc enumeration
6563
// but the details for this are not fully specified yet
6664
enum class backend_errc : unsigned int {};
67-
68-
// Convert from UR backend to SYCL backend enum
69-
backend convertUrBackend(ur_platform_backend_t UrBackend);
7065
} // namespace detail
7166

7267
template <backend Backend> class backend_traits {
@@ -78,14 +73,6 @@ template <backend Backend> class backend_traits {
7873
using return_type = typename detail::BackendReturn<Backend, T>::type;
7974
};
8075

81-
template <backend Backend, typename SyclType>
82-
using backend_input_t =
83-
typename backend_traits<Backend>::template input_type<SyclType>;
84-
85-
template <backend Backend, typename SyclType>
86-
using backend_return_t =
87-
typename backend_traits<Backend>::template return_type<SyclType>;
88-
8976
namespace detail {
9077
template <backend Backend, typename DataT, int Dimensions, typename AllocatorT>
9178
struct BufferInterop {

sycl/include/sycl/builtins_esimd.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <sycl/detail/common.hpp>
1212
#include <sycl/detail/generic_type_traits.hpp>
1313
#include <sycl/ext/intel/esimd/detail/math_intrin.hpp>
14-
#include <sycl/types.hpp>
14+
#include <sycl/vector.hpp>
1515

1616
// TODO Decide whether to mark functions with this attribute.
1717
#define __NOEXC /*noexcept*/

sycl/include/sycl/builtins_utils_vec.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include <sycl/builtins_utils_scalar.hpp>
1414

1515
#include <sycl/detail/type_traits.hpp>
16+
#include <sycl/detail/vector_convert.hpp>
1617
#include <sycl/marray.hpp> // for marray
17-
#include <sycl/types.hpp> // for vec
18+
#include <sycl/vector.hpp> // for vec
1819

1920
namespace sycl {
2021
inline namespace _V1 {

sycl/include/sycl/detail/backend_traits.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
#pragma once
1010

11-
#include <sycl/backend_types.hpp>
12-
1311
namespace sycl {
1412
inline namespace _V1 {
13+
enum class backend : char;
1514
namespace detail {
1615

1716
template <backend Backend, typename SYCLObjectT> struct interop;

sycl/include/sycl/detail/device_filter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010

11-
#include <sycl/backend_types.hpp>
1211
#include <sycl/detail/defines.hpp>
1312
#include <sycl/info/info_desc.hpp>
1413

@@ -18,6 +17,7 @@
1817

1918
namespace sycl {
2019
inline namespace _V1 {
20+
enum class backend : char;
2121
namespace detail {
2222

2323
// ---------------------------------------

sycl/include/sycl/detail/image_accessor_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <sycl/image.hpp> // for image_channel_type
2424
#include <sycl/range.hpp> // for range
2525
#include <sycl/sampler.hpp> // for addressing_mode, coor...
26-
#include <sycl/types.hpp> // for vec, operator*, round...
26+
#include <sycl/vector.hpp> // for vec, operator*, round...
2727

2828
#include <cstdint> // for int32_t, uint16_t
2929
#include <stddef.h> // for size_t

sycl/include/sycl/detail/ur.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include <sycl/backend_types.hpp>
1817
#include <sycl/detail/export.hpp>
1918
#include <sycl/detail/os_util.hpp>
2019
#include <ur_api.h>
@@ -42,6 +41,7 @@ struct trace_event_data_t;
4241
namespace sycl {
4342
inline namespace _V1 {
4443

44+
enum class backend : char;
4545
class context;
4646

4747
namespace detail {

sycl/include/sycl/detail/util.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include <cstring>
1717
#include <mutex>
18+
#include <string>
19+
#include <type_traits>
20+
#include <utility>
1821
#include <vector>
1922

2023
namespace sycl {
@@ -83,6 +86,40 @@ template <> struct ABINeutralT<std::vector<std::string>> {
8386
};
8487

8588
template <typename T> using ABINeutralT_t = typename ABINeutralT<T>::type;
89+
90+
template <typename ParamT> auto convert_to_abi_neutral(ParamT &&Info) {
91+
using ParamNoRef = std::remove_reference_t<ParamT>;
92+
if constexpr (std::is_same_v<ParamNoRef, std::string>) {
93+
return detail::string{Info};
94+
} else if constexpr (std::is_same_v<ParamNoRef, std::vector<std::string>>) {
95+
std::vector<detail::string> Res;
96+
Res.reserve(Info.size());
97+
for (std::string &Str : Info) {
98+
Res.push_back(detail::string{Str});
99+
}
100+
return Res;
101+
} else {
102+
return std::forward<ParamT>(Info);
103+
}
104+
}
105+
106+
template <typename ParamT> auto convert_from_abi_neutral(ParamT &&Info) {
107+
using ParamNoRef = std::remove_reference_t<ParamT>;
108+
if constexpr (std::is_same_v<ParamNoRef, detail::string>) {
109+
return Info.c_str();
110+
} else if constexpr (std::is_same_v<ParamNoRef,
111+
std::vector<detail::string>>) {
112+
std::vector<std::string> Res;
113+
Res.reserve(Info.size());
114+
for (detail::string &Str : Info) {
115+
Res.push_back(Str.c_str());
116+
}
117+
return Res;
118+
} else {
119+
return std::forward<ParamT>(Info);
120+
}
121+
}
122+
86123
} // namespace detail
87124
} // namespace _V1
88125
} // namespace sycl

0 commit comments

Comments
 (0)