Skip to content

Commit b469f03

Browse files
author
Artem Gindinson
authored
[SYCL][NFC] Improve type traits' usage in headers & runtime (#2768)
The patch aims to: 1. Facilitate consistent usage of type traits accross the SYCL library. 2. Make a potential switch to C++14 STL type traits easier to perform. The following traits were affected: - `enable_if` - `remove_const` - `remove_reference` - `conditional` - `remove_pointer` - `remove_cv` An overview of the changes: 1. Wherever possible, `std::[trait]<>::type` usages were replaced with `detail::[trait]_t<>`. 2. The corresponding `std::[trait]_t<>` usages were also replaced, as we're still supposed to comply with C++11. 3. The type traits-related `#include` directives were slightly re-organized with some removal of obsolete ones. 4. Some duplicating code was removed from `detail/stl_type_traits.hpp`. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 6b95820 commit b469f03

38 files changed

+653
-655
lines changed

sycl/include/CL/sycl/INTEL/esimd/detail/esimd_types.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <CL/sycl/detail/stl_type_traits.hpp> // to define C++14,17 extensions
1717
#include <CL/sycl/half_type.hpp>
1818
#include <cstdint>
19-
#include <type_traits>
2019

2120
__SYCL_INLINE_NAMESPACE(cl) {
2221
namespace sycl {
@@ -208,8 +207,8 @@ template <typename T1, typename T2> struct computation_type {
208207
template <typename U> constexpr bool is_type() { return false; }
209208

210209
template <typename U, typename T, typename... Ts> constexpr bool is_type() {
211-
using UU = typename std::remove_const<U>::type;
212-
using TT = typename std::remove_const<T>::type;
210+
using UU = typename detail::remove_const_t<U>;
211+
using TT = typename detail::remove_const_t<T>;
213212
return std::is_same<UU, TT>::value || is_type<UU, Ts...>();
214213
}
215214

@@ -228,10 +227,10 @@ struct bitcast_helper {
228227
// Change the element type of a simd vector.
229228
template <typename ToEltTy, typename FromEltTy, int FromN,
230229
typename = csd::enable_if_t<is_vectorizable<ToEltTy>::value>>
231-
ESIMD_INLINE typename std::conditional<
230+
ESIMD_INLINE typename detail::conditional_t<
232231
std::is_same<FromEltTy, ToEltTy>::value, vector_type_t<FromEltTy, FromN>,
233232
vector_type_t<ToEltTy,
234-
bitcast_helper<ToEltTy, FromEltTy, FromN>::nToElems()>>::type
233+
bitcast_helper<ToEltTy, FromEltTy, FromN>::nToElems()>>
235234
bitcast(vector_type_t<FromEltTy, FromN> Val) {
236235
// Noop.
237236
if constexpr (std::is_same<FromEltTy, ToEltTy>::value)

sycl/include/CL/sycl/INTEL/esimd/detail/esimd_util.hpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ struct is_esimd_scalar
100100
template <typename T>
101101
struct is_dword_type
102102
: std::integral_constant<
103-
bool, std::is_same<int, typename std::remove_const<T>::type>::value ||
104-
std::is_same<unsigned int,
105-
typename std::remove_const<T>::type>::value> {
106-
};
103+
bool,
104+
std::is_same<int, typename sycl::detail::remove_const_t<T>>::value ||
105+
std::is_same<unsigned int,
106+
typename sycl::detail::remove_const_t<T>>::value> {};
107107

108108
template <typename T, int N>
109109
struct is_dword_type<sycl::INTEL::gpu::vector_type<T, N>> {
@@ -119,9 +119,10 @@ template <typename T>
119119
struct is_word_type
120120
: std::integral_constant<
121121
bool,
122-
std::is_same<short, typename std::remove_const<T>::type>::value ||
122+
std::is_same<short,
123+
typename sycl::detail::remove_const_t<T>>::value ||
123124
std::is_same<unsigned short,
124-
typename std::remove_const<T>::type>::value> {};
125+
typename sycl::detail::remove_const_t<T>>::value> {};
125126

126127
template <typename T, int N>
127128
struct is_word_type<sycl::INTEL::gpu::vector_type<T, N>> {
@@ -136,9 +137,9 @@ template <typename T>
136137
struct is_byte_type
137138
: std::integral_constant<
138139
bool,
139-
std::is_same<char, typename std::remove_const<T>::type>::value ||
140+
std::is_same<char, typename sycl::detail::remove_const_t<T>>::value ||
140141
std::is_same<unsigned char,
141-
typename std::remove_const<T>::type>::value> {};
142+
typename sycl::detail::remove_const_t<T>>::value> {};
142143

143144
template <typename T, int N>
144145
struct is_byte_type<sycl::INTEL::gpu::vector_type<T, N>> {
@@ -152,31 +153,36 @@ template <typename T, int N> struct is_byte_type<sycl::INTEL::gpu::simd<T, N>> {
152153
template <typename T>
153154
struct is_fp_type
154155
: std::integral_constant<
155-
bool,
156-
std::is_same<float, typename std::remove_const<T>::type>::value> {};
156+
bool, std::is_same<float,
157+
typename sycl::detail::remove_const_t<T>>::value> {
158+
};
157159

158160
template <typename T>
159161
struct is_df_type
160162
: std::integral_constant<
161-
bool,
162-
std::is_same<double, typename std::remove_const<T>::type>::value> {};
163+
bool, std::is_same<double,
164+
typename sycl::detail::remove_const_t<T>>::value> {
165+
};
163166

164167
template <typename T>
165168
struct is_fp_or_dword_type
166169
: std::integral_constant<
167170
bool,
168-
std::is_same<float, typename std::remove_const<T>::type>::value ||
169-
std::is_same<int, typename std::remove_const<T>::type>::value ||
171+
std::is_same<float,
172+
typename sycl::detail::remove_const_t<T>>::value ||
173+
std::is_same<int,
174+
typename sycl::detail::remove_const_t<T>>::value ||
170175
std::is_same<unsigned int,
171-
typename std::remove_const<T>::type>::value> {};
176+
typename sycl::detail::remove_const_t<T>>::value> {};
172177

173178
template <typename T>
174179
struct is_qword_type
175180
: std::integral_constant<
176181
bool,
177-
std::is_same<long long, typename std::remove_const<T>::type>::value ||
182+
std::is_same<long long,
183+
typename sycl::detail::remove_const_t<T>>::value ||
178184
std::is_same<unsigned long long,
179-
typename std::remove_const<T>::type>::value> {};
185+
typename sycl::detail::remove_const_t<T>>::value> {};
180186

181187
template <typename T, int N>
182188
struct is_qword_type<sycl::INTEL::gpu::vector_type<T, N>> {

sycl/include/CL/sycl/INTEL/esimd/esimd.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,9 @@ template <typename Ty, int N> class simd {
328328
//
329329
// @return 1 if any element is set, 0 otherwise
330330

331-
template <typename T1 = element_type, typename T2 = Ty,
332-
typename = std::enable_if_t<std::is_integral<T1>::value, T2>>
331+
template <
332+
typename T1 = element_type, typename T2 = Ty,
333+
typename = sycl::detail::enable_if_t<std::is_integral<T1>::value, T2>>
333334
uint16_t any() {
334335
return __esimd_any<Ty, N>(data());
335336
}
@@ -338,8 +339,9 @@ template <typename Ty, int N> class simd {
338339
//
339340
// @return 1 if all elements are set, 0 otherwise
340341

341-
template <typename T1 = element_type, typename T2 = Ty,
342-
typename = std::enable_if_t<std::is_integral<T1>::value, T2>>
342+
template <
343+
typename T1 = element_type, typename T2 = Ty,
344+
typename = sycl::detail::enable_if_t<std::is_integral<T1>::value, T2>>
343345
uint16_t all() {
344346
return __esimd_all<Ty, N>(data());
345347
}

0 commit comments

Comments
 (0)