Skip to content

Commit ad35628

Browse files
authored
[SYCL][NFC] Refactor includes in DPC++ headers (#10458)
The main goal of this refactoring is to reduce amount of includes to the context.hpp header. Two new includes are added: 1. sycl/include/sycl/detail/impl_utils.hpp is intended to replace sycl/include/sycl/detail/common.hpp when only interopability with "impl" class is needed. common.hpp include is overloaded with a bunch of other functionality. 2. sycl/include/sycl/async_handler.hpp separates async_handler definiton from exception.hpp.
1 parent 195a437 commit ad35628

22 files changed

+111
-58
lines changed

sycl/include/sycl/async_handler.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- async_handler.hpp --------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/detail/defines_elementary.hpp>
12+
13+
#include <functional>
14+
15+
namespace sycl {
16+
__SYCL_INLINE_VER_NAMESPACE(_V1) {
17+
18+
// Forward declaration
19+
class exception_list;
20+
21+
using async_handler = std::function<void(sycl::exception_list)>;
22+
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
23+
} // namespace sycl

sycl/include/sycl/backend_types.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
#pragma once
1010

11-
#include <sycl/detail/defines.hpp>
12-
#include <sycl/detail/iostream_proxy.hpp>
11+
#include <sycl/detail/defines_elementary.hpp>
12+
13+
#include <ostream>
1314

1415
namespace sycl {
1516
__SYCL_INLINE_VER_NAMESPACE(_V1) {

sycl/include/sycl/buffer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <sycl/exception.hpp>
1717
#include <sycl/ext/oneapi/accessor_property_list.hpp>
1818
#include <sycl/ext/oneapi/weak_object_base.hpp>
19+
#include <sycl/id.hpp>
1920
#include <sycl/property_list.hpp>
2021
#include <sycl/range.hpp>
2122
#include <sycl/stl.hpp>

sycl/include/sycl/context.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
#pragma once
1010

11-
#include <sycl/detail/backend_traits.hpp>
12-
#include <sycl/detail/cl.h>
13-
#include <sycl/detail/common.hpp>
11+
#include <sycl/async_handler.hpp>
12+
#include <sycl/backend_types.hpp>
1413
#include <sycl/detail/export.hpp>
1514
#include <sycl/detail/info_desc_helpers.hpp>
1615
#include <sycl/detail/owner_less_base.hpp>
17-
#include <sycl/detail/stl_type_traits.hpp>
18-
#include <sycl/exception_list.hpp>
19-
#include <sycl/ext/oneapi/weak_object_base.hpp>
20-
#include <sycl/info/info_desc.hpp>
2116
#include <sycl/property_list.hpp>
2217

2318
// 4.6.2 Context class
@@ -27,6 +22,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
2722
// Forward declarations
2823
class device;
2924
class platform;
25+
3026
namespace detail {
3127
class context_impl;
3228
}

sycl/include/sycl/detail/common.hpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -259,41 +259,6 @@ inline std::string codeToString(pi_int32 code) {
259259
namespace sycl {
260260
__SYCL_INLINE_VER_NAMESPACE(_V1) {
261261
namespace detail {
262-
263-
// Helper function for extracting implementation from SYCL's interface objects.
264-
// Note! This function relies on the fact that all SYCL interface classes
265-
// contain "impl" field that points to implementation object. "impl" field
266-
// should be accessible from this function.
267-
//
268-
// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
269-
// may not recognize the usage of this function in friend member declarations
270-
// if the template parameter name there is not equal to the name used here,
271-
// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
272-
// would trigger that error in MSVC:
273-
// template <class T>
274-
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
275-
template <class Obj> decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) {
276-
assert(SyclObject.impl && "every constructor should create an impl");
277-
return SyclObject.impl;
278-
}
279-
280-
// Returns the raw pointer to the impl object of given face object. The caller
281-
// must make sure the returned pointer is not captured in a field or otherwise
282-
// stored - i.e. must live only as on-stack value.
283-
template <class T>
284-
typename std::add_pointer_t<typename decltype(T::impl)::element_type>
285-
getRawSyclObjImpl(const T &SyclObject) {
286-
return SyclObject.impl.get();
287-
}
288-
289-
// Helper function for creation SYCL interface objects from implementations.
290-
// Note! This function relies on the fact that all SYCL interface classes
291-
// contain "impl" field that points to implementation object. "impl" field
292-
// should be accessible from this function.
293-
template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
294-
return T(ImplObj);
295-
}
296-
297262
// Produces N-dimensional object of type T whose all components are initialized
298263
// to given integer value.
299264
template <int N, template <int> class T> struct InitializedVal {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===- impl_utils.hpp -----------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/detail/defines_elementary.hpp>
12+
13+
#include <cassert>
14+
15+
namespace sycl {
16+
__SYCL_INLINE_VER_NAMESPACE(_V1) {
17+
namespace detail {
18+
19+
// Helper function for extracting implementation from SYCL's interface objects.
20+
// Note! This function relies on the fact that all SYCL interface classes
21+
// contain "impl" field that points to implementation object. "impl" field
22+
// should be accessible from this function.
23+
//
24+
// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
25+
// may not recognize the usage of this function in friend member declarations
26+
// if the template parameter name there is not equal to the name used here,
27+
// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
28+
// would trigger that error in MSVC:
29+
// template <class T>
30+
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
31+
template <class Obj> decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) {
32+
assert(SyclObject.impl && "every constructor should create an impl");
33+
return SyclObject.impl;
34+
}
35+
36+
// Returns the raw pointer to the impl object of given face object. The caller
37+
// must make sure the returned pointer is not captured in a field or otherwise
38+
// stored - i.e. must live only as on-stack value.
39+
template <class T>
40+
typename std::add_pointer_t<typename decltype(T::impl)::element_type>
41+
getRawSyclObjImpl(const T &SyclObject) {
42+
return SyclObject.impl.get();
43+
}
44+
45+
// Helper function for creation SYCL interface objects from implementations.
46+
// Note! This function relies on the fact that all SYCL interface classes
47+
// contain "impl" field that points to implementation object. "impl" field
48+
// should be accessible from this function.
49+
template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
50+
return T(ImplObj);
51+
}
52+
53+
} // namespace detail
54+
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
55+
} // namespace sycl

sycl/include/sycl/detail/info_desc_helpers.hpp

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

1111
#include <sycl/aspects.hpp>
12-
#include <sycl/detail/pi.hpp>
12+
#include <sycl/detail/pi.h>
13+
#include <sycl/id.hpp>
1314
#include <sycl/info/info_desc.hpp>
1415

1516
namespace sycl {

sycl/include/sycl/detail/owner_less_base.hpp

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

99
#pragma once
1010

11-
#include <sycl/detail/common.hpp>
1211
#include <sycl/detail/defines_elementary.hpp>
12+
#include <sycl/detail/impl_utils.hpp>
1313
#include <sycl/ext/oneapi/weak_object_base.hpp>
1414

1515
namespace sycl {

sycl/include/sycl/detail/property_helper.hpp

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

99
#pragma once
1010

11-
#include <sycl/detail/common.hpp>
11+
#include <sycl/detail/defines_elementary.hpp>
1212

1313
namespace sycl {
1414
__SYCL_INLINE_VER_NAMESPACE(_V1) {

sycl/include/sycl/detail/property_list_base.hpp

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

99
#pragma once
1010

11-
#include <sycl/detail/common.hpp>
1211
#include <sycl/detail/property_helper.hpp>
1312
#include <sycl/detail/stl_type_traits.hpp>
13+
#include <sycl/exception.hpp>
1414

1515
#include <bitset>
1616
#include <memory>

sycl/include/sycl/detail/stl_type_traits.hpp

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

99
#pragma once
1010

11+
#include <sycl/detail/defines_elementary.hpp>
12+
1113
#include <iterator>
12-
#include <memory>
13-
#include <sycl/detail/defines.hpp>
1414
#include <type_traits>
1515

1616
namespace sycl {

sycl/include/sycl/device_selector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
2121

2222
// Forward declarations
2323
class device;
24+
class context;
2425
enum class aspect;
2526

2627
namespace ext::oneapi {

sycl/include/sycl/exception_list.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// 4.9.2 Exception Class Interface
1212

13+
#include <sycl/async_handler.hpp>
1314
#include <sycl/detail/defines.hpp>
1415
#include <sycl/detail/export.hpp>
1516
#include <sycl/detail/iostream_proxy.hpp>
@@ -52,8 +53,6 @@ class __SYCL_EXPORT exception_list {
5253
std::vector<std::exception_ptr> MList;
5354
};
5455

55-
using async_handler = std::function<void(sycl::exception_list)>;
56-
5756
namespace detail {
5857
// Default implementation of async_handler used by queue and context when no
5958
// user-defined async_handler is specified.

sycl/include/sycl/ext/oneapi/experimental/device_architecture.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//===- device_architecture.hpp --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
19
#pragma once
210

311
#include <sycl/detail/defines_elementary.hpp>

sycl/include/sycl/ext/oneapi/experimental/graph.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sycl/detail/common.hpp>
1212
#include <sycl/detail/defines_elementary.hpp>
13+
#include <sycl/detail/impl_utils.hpp>
1314
#include <sycl/property_list.hpp>
1415

1516
#include <functional>

sycl/include/sycl/info/info_desc.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#pragma once
1010

1111
#include <sycl/aspects.hpp>
12-
#include <sycl/detail/common.hpp>
13-
#include <sycl/detail/pi.hpp>
12+
#include <sycl/detail/pi.h>
1413
#include <sycl/ext/oneapi/experimental/device_architecture.hpp>
15-
#include <sycl/id.hpp>
14+
#include <sycl/range.hpp>
1615

1716
namespace sycl {
1817
__SYCL_INLINE_VER_NAMESPACE(_V1) {
@@ -21,6 +20,7 @@ class device;
2120
class platform;
2221
class kernel_id;
2322
enum class memory_scope;
23+
enum class memory_order;
2424

2525
// TODO: stop using OpenCL directly, use PI.
2626
namespace info {

sycl/include/sycl/property_list.hpp

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

99
#pragma once
1010

11-
#include <sycl/detail/common.hpp>
1211
#include <sycl/detail/property_list_base.hpp>
1312
#include <sycl/properties/property_traits.hpp>
1413

sycl/include/sycl/queue.hpp

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

1111
#include <sycl/detail/assert_happened.hpp>
12-
#include <sycl/detail/common.hpp>
1312
#include <sycl/detail/service_kernel_names.hpp>
1413
#include <sycl/device_selector.hpp>
14+
#include <sycl/exception_list.hpp>
1515
#include <sycl/handler.hpp>
1616
#include <sycl/property_list.hpp>
1717

sycl/source/detail/config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sycl/detail/defines.hpp>
1414
#include <sycl/detail/device_filter.hpp>
1515
#include <sycl/detail/pi.hpp>
16+
#include <sycl/exception.hpp>
1617
#include <sycl/info/info_desc.hpp>
1718

1819
#include <algorithm>

sycl/source/detail/posix_pi.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <sycl/detail/defines.hpp>
10+
#include <sycl/detail/iostream_proxy.hpp>
1011
#include <sycl/detail/pi.hpp>
1112

1213
#include <dlfcn.h>

sycl/source/detail/sampler_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <CL/__spirv/spirv_types.hpp>
1212
#include <sycl/context.hpp>
1313
#include <sycl/detail/export.hpp>
14+
#include <sycl/detail/pi.hpp>
1415
#include <sycl/property_list.hpp>
1516

1617
#include <mutex>

sycl/source/detail/sycl_mem_obj_t.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <sycl/properties/buffer_properties.hpp>
1818
#include <sycl/properties/image_properties.hpp>
1919
#include <sycl/property_list.hpp>
20-
#include <sycl/stl.hpp>
20+
#include <sycl/range.hpp>
2121

2222
#include <cstring>
2323
#include <memory>

0 commit comments

Comments
 (0)