Skip to content

Commit 4cf9065

Browse files
[NFC][SYCL] Reduce dependencies of <sycl/detail/generic_type_traits.hpp> (#20074)
1 parent db68f2d commit 4cf9065

File tree

12 files changed

+93
-57
lines changed

12 files changed

+93
-57
lines changed

sycl/include/sycl/detail/builtins/builtins.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@
6363

6464
#pragma once
6565

66+
#include <sycl/detail/helpers.hpp>
6667
#include <sycl/detail/type_traits.hpp>
6768
#include <sycl/detail/type_traits/vec_marray_traits.hpp>
6869
#include <sycl/detail/vector_convert.hpp>
69-
#include <sycl/marray.hpp> // for marray
70-
#include <sycl/vector.hpp> // for vec
70+
#include <sycl/marray.hpp>
71+
#include <sycl/multi_ptr.hpp>
72+
#include <sycl/vector.hpp>
7173

7274
namespace sycl {
7375
inline namespace _V1 {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===----------------------------------------------------------------------===//
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 <cstdint>
12+
13+
namespace sycl {
14+
inline namespace _V1 {
15+
namespace detail::half_impl {
16+
class half;
17+
18+
// Several aliases are defined below:
19+
// - StorageT: actual representation of half data type. It is used by scalar
20+
// half values. On device side, it points to some native half data type, while
21+
// on host it is represented by a 16-bit integer that the implementation
22+
// manipulates to emulate half-precision floating-point behavior.
23+
//
24+
// - BIsRepresentationT: data type which is used by built-in functions. It is
25+
// distinguished from StorageT, because on host, we can still operate on the
26+
// wrapper itself and there is no sense in direct usage of underlying data
27+
// type (too many changes required for BIs implementation without any
28+
// foreseeable profits)
29+
//
30+
// - VecElemT: representation of each element in the vector. On device it is
31+
// the same as StorageT to carry a native vector representation, while on
32+
// host it stores the sycl::half implementation directly.
33+
//
34+
// - VecNStorageT: representation of N-element vector of halfs. Follows the
35+
// same logic as VecElemT.
36+
#ifdef __SYCL_DEVICE_ONLY__
37+
using StorageT = _Float16;
38+
using BIsRepresentationT = _Float16;
39+
using VecElemT = _Float16;
40+
#else // SYCL_DEVICE_ONLY
41+
using StorageT = uint16_t;
42+
// No need to extract underlying data type for built-in functions operating on
43+
// host
44+
using BIsRepresentationT = half;
45+
using VecElemT = half;
46+
#endif // SYCL_DEVICE_ONLY
47+
} // namespace detail::half_impl
48+
using half = detail::half_impl::half;
49+
50+
} // namespace _V1
51+
} // namespace sycl

sycl/include/sycl/detail/generic_type_traits.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
#pragma once
1010

11-
#include <sycl/access/access.hpp> // for decorated, address_space
12-
#include <sycl/aliases.hpp> // for half, cl_char, cl_double
13-
#include <sycl/detail/helpers.hpp> // for marray
14-
#include <sycl/detail/type_traits.hpp> // for is_gen_based_on_type_s...
15-
#include <sycl/half_type.hpp> // for BIsRepresentationT
16-
#include <sycl/multi_ptr.hpp> // for multi_ptr, address_spa...
17-
18-
#include <sycl/ext/oneapi/bfloat16.hpp> // for bfloat16 storage type.
11+
#include <sycl/access/access.hpp>
12+
#include <sycl/aliases.hpp>
13+
#include <sycl/bit_cast.hpp>
14+
#include <sycl/detail/fwd/half.hpp>
15+
#include <sycl/detail/type_traits.hpp>
1916

2017
#include <cstddef> // for byte
2118
#include <cstdint> // for uint8_t
@@ -24,6 +21,9 @@
2421

2522
namespace sycl {
2623
inline namespace _V1 {
24+
namespace ext::oneapi {
25+
class bfloat16;
26+
}
2727
namespace detail {
2828
template <typename T>
2929
using is_byte = typename
@@ -166,13 +166,16 @@ template <typename T> auto convertToOpenCLType(T &&x) {
166166
static_assert(sizeof(OpenCLType) == sizeof(T));
167167
return static_cast<OpenCLType>(x);
168168
} else if constexpr (std::is_same_v<no_ref, half>) {
169-
using OpenCLType = sycl::detail::half_impl::BIsRepresentationT;
169+
// Make it template-param-dependent to compile with incomplete `half`:
170+
using OpenCLType =
171+
std::enable_if_t<std::is_same_v<no_ref, half>,
172+
sycl::detail::half_impl::BIsRepresentationT>;
170173
static_assert(sizeof(OpenCLType) == sizeof(T));
171174
return static_cast<OpenCLType>(x);
172175
} else if constexpr (std::is_same_v<no_ref, ext::oneapi::bfloat16>) {
173176
// On host, don't interpret BF16 as uint16.
174177
#ifdef __SYCL_DEVICE_ONLY__
175-
using OpenCLType = sycl::ext::oneapi::bfloat16::Bfloat16StorageT;
178+
using OpenCLType = typename no_ref::Bfloat16StorageT;
176179
return sycl::bit_cast<OpenCLType>(x);
177180
#else
178181
return std::forward<T>(x);

sycl/include/sycl/detail/spirv.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sycl/access/access.hpp>
2121
#include <sycl/detail/generic_type_traits.hpp>
2222
#include <sycl/id.hpp>
23+
#include <sycl/memory_enums.hpp>
2324
#include <sycl/multi_ptr.hpp>
2425

2526
#if defined(__NVPTX__)

sycl/include/sycl/detail/usm_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace sycl {
1515
inline namespace _V1 {
1616
class device;
17+
class context;
1718

1819
namespace detail::usm {
1920

sycl/include/sycl/detail/vector_convert.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
#include <sycl/exception.hpp> // for errc
5959

6060
#include <sycl/detail/memcpy.hpp>
61-
#include <sycl/ext/oneapi/bfloat16.hpp> // bfloat16
61+
#include <sycl/ext/oneapi/bfloat16.hpp>
62+
#include <sycl/half_type.hpp>
6263
#include <sycl/vector.hpp>
6364

6465
#ifndef __SYCL_DEVICE_ONLY__

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#pragma once
1212

1313
#include <sycl/detail/address_space_cast.hpp>
14+
#include <sycl/detail/helpers.hpp>
1415
#include <sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp>
1516
#include <sycl/ext/oneapi/properties/properties.hpp>
1617
#include <sycl/group_barrier.hpp>

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

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

1111
#include <sycl/__spirv/spirv_ops.hpp>
12+
#include <sycl/detail/address_space_cast.hpp>
1213
#include <sycl/ext/oneapi/properties/properties.hpp>
14+
#include <sycl/id.hpp>
1315
#include <sycl/vector.hpp>
1416

1517
namespace sycl {

sycl/include/sycl/half_type.hpp

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

1111
#include <sycl/bit_cast.hpp> // for bit_cast
1212
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
13+
#include <sycl/detail/fwd/half.hpp>
1314

1415
#ifdef __SYCL_DEVICE_ONLY__
1516
#include <sycl/aspects.hpp>
@@ -154,36 +155,6 @@ inline __SYCL_CONSTEXPR_HALF float half2Float(const uint16_t &Val) {
154155
namespace half_impl {
155156
class half;
156157

157-
// Several aliases are defined below:
158-
// - StorageT: actual representation of half data type. It is used by scalar
159-
// half values. On device side, it points to some native half data type, while
160-
// on host it is represented by a 16-bit integer that the implementation
161-
// manipulates to emulate half-precision floating-point behavior.
162-
//
163-
// - BIsRepresentationT: data type which is used by built-in functions. It is
164-
// distinguished from StorageT, because on host, we can still operate on the
165-
// wrapper itself and there is no sense in direct usage of underlying data
166-
// type (too many changes required for BIs implementation without any
167-
// foreseeable profits)
168-
//
169-
// - VecElemT: representation of each element in the vector. On device it is
170-
// the same as StorageT to carry a native vector representation, while on
171-
// host it stores the sycl::half implementation directly.
172-
//
173-
// - VecNStorageT: representation of N-element vector of halfs. Follows the
174-
// same logic as VecElemT.
175-
#ifdef __SYCL_DEVICE_ONLY__
176-
using StorageT = _Float16;
177-
using BIsRepresentationT = _Float16;
178-
using VecElemT = _Float16;
179-
#else // SYCL_DEVICE_ONLY
180-
using StorageT = uint16_t;
181-
// No need to extract underlying data type for built-in functions operating on
182-
// host
183-
using BIsRepresentationT = half;
184-
using VecElemT = half;
185-
#endif // SYCL_DEVICE_ONLY
186-
187158
// Creation token to disambiguate constructors.
188159
struct RawHostHalfToken {
189160
constexpr explicit RawHostHalfToken(uint16_t Val) : Value{Val} {}

sycl/include/sycl/vector.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
#error "SYCL device compiler is built without ext_vector_type support"
3232
#endif
3333

34-
#include <sycl/access/access.hpp> // for decorated, address_space
35-
#include <sycl/aliases.hpp> // for half, cl_char, cl_int
36-
#include <sycl/detail/common.hpp> // for ArrayCreator
37-
#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
34+
#include <sycl/access/access.hpp> // for decorated, address_space
35+
#include <sycl/aliases.hpp> // for half, cl_char, cl_int
36+
#include <sycl/detail/common.hpp> // for ArrayCreator
37+
#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
38+
#include <sycl/detail/fwd/accessor.hpp>
3839
#include <sycl/detail/generic_type_traits.hpp> // for is_sigeninteger, is_s...
3940
#include <sycl/detail/memcpy.hpp> // for memcpy
4041
#include <sycl/detail/named_swizzles_mixin.hpp>

0 commit comments

Comments
 (0)