Skip to content

Commit e87adfd

Browse files
[SYCL][NFC] Fix use of common macro names in type_list.hpp and common.hpp (#6493)
This commit renames a number of template parameters in the DPC++ headers to reduce chance of conflicts with user-defined macros. Most notable of these renamings are VL, DIM and NDIMS. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent fe18839 commit e87adfd

File tree

3 files changed

+86
-77
lines changed

3 files changed

+86
-77
lines changed

sycl/include/sycl/detail/common.hpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,33 @@ template <template <int> class T> struct InitializedVal<3, T> {
244244
};
245245

246246
/// Helper class for the \c NDLoop.
247-
template <int NDIMS, int DIM, template <int> class LoopBoundTy, typename FuncTy,
247+
template <int NDims, int Dim, template <int> class LoopBoundTy, typename FuncTy,
248248
template <int> class LoopIndexTy>
249249
struct NDLoopIterateImpl {
250-
NDLoopIterateImpl(const LoopIndexTy<NDIMS> &LowerBound,
251-
const LoopBoundTy<NDIMS> &Stride,
252-
const LoopBoundTy<NDIMS> &UpperBound, FuncTy f,
253-
LoopIndexTy<NDIMS> &Index) {
254-
constexpr size_t AdjIdx = NDIMS - 1 - DIM;
250+
NDLoopIterateImpl(const LoopIndexTy<NDims> &LowerBound,
251+
const LoopBoundTy<NDims> &Stride,
252+
const LoopBoundTy<NDims> &UpperBound, FuncTy f,
253+
LoopIndexTy<NDims> &Index) {
254+
constexpr size_t AdjIdx = NDims - 1 - Dim;
255255
for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
256256
Index[AdjIdx] += Stride[AdjIdx]) {
257257

258-
NDLoopIterateImpl<NDIMS, DIM - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
258+
NDLoopIterateImpl<NDims, Dim - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
259259
LowerBound, Stride, UpperBound, f, Index};
260260
}
261261
}
262262
};
263263

264-
// Specialization for DIM=0 to terminate recursion
265-
template <int NDIMS, template <int> class LoopBoundTy, typename FuncTy,
264+
// Specialization for Dim=0 to terminate recursion
265+
template <int NDims, template <int> class LoopBoundTy, typename FuncTy,
266266
template <int> class LoopIndexTy>
267-
struct NDLoopIterateImpl<NDIMS, 0, LoopBoundTy, FuncTy, LoopIndexTy> {
268-
NDLoopIterateImpl(const LoopIndexTy<NDIMS> &LowerBound,
269-
const LoopBoundTy<NDIMS> &Stride,
270-
const LoopBoundTy<NDIMS> &UpperBound, FuncTy f,
271-
LoopIndexTy<NDIMS> &Index) {
267+
struct NDLoopIterateImpl<NDims, 0, LoopBoundTy, FuncTy, LoopIndexTy> {
268+
NDLoopIterateImpl(const LoopIndexTy<NDims> &LowerBound,
269+
const LoopBoundTy<NDims> &Stride,
270+
const LoopBoundTy<NDims> &UpperBound, FuncTy f,
271+
LoopIndexTy<NDims> &Index) {
272272

273-
constexpr size_t AdjIdx = NDIMS - 1;
273+
constexpr size_t AdjIdx = NDims - 1;
274274
for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
275275
Index[AdjIdx] += Stride[AdjIdx]) {
276276

@@ -279,43 +279,43 @@ struct NDLoopIterateImpl<NDIMS, 0, LoopBoundTy, FuncTy, LoopIndexTy> {
279279
}
280280
};
281281

282-
/// Generates an NDIMS-dimensional perfect loop nest. The purpose of this class
282+
/// Generates an NDims-dimensional perfect loop nest. The purpose of this class
283283
/// is to better support handling of situations where there must be a loop nest
284284
/// over a multi-dimensional space - it allows to avoid generating unnecessary
285285
/// outer loops like 'for (int z=0; z<1; z++)' in case of 1D and 2D iteration
286286
/// spaces or writing specializations of the algorithms for 1D, 2D and 3D cases.
287287
/// Loop is unrolled in a reverse directions, i.e. ID = 0 is the inner-most one.
288-
template <int NDIMS> struct NDLoop {
288+
template <int NDims> struct NDLoop {
289289
/// Generates ND loop nest with {0,..0} .. \c UpperBound bounds with unit
290290
/// stride. Applies \c f at each iteration, passing current index of
291-
/// \c LoopIndexTy<NDIMS> type as the parameter.
291+
/// \c LoopIndexTy<NDims> type as the parameter.
292292
template <template <int> class LoopBoundTy, typename FuncTy,
293293
template <int> class LoopIndexTy = LoopBoundTy>
294-
static __SYCL_ALWAYS_INLINE void iterate(const LoopBoundTy<NDIMS> &UpperBound,
294+
static __SYCL_ALWAYS_INLINE void iterate(const LoopBoundTy<NDims> &UpperBound,
295295
FuncTy f) {
296-
const LoopIndexTy<NDIMS> LowerBound =
297-
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
298-
const LoopBoundTy<NDIMS> Stride =
299-
InitializedVal<NDIMS, LoopBoundTy>::template get<1>();
300-
LoopIndexTy<NDIMS> Index =
301-
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
302-
303-
NDLoopIterateImpl<NDIMS, NDIMS - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
296+
const LoopIndexTy<NDims> LowerBound =
297+
InitializedVal<NDims, LoopIndexTy>::template get<0>();
298+
const LoopBoundTy<NDims> Stride =
299+
InitializedVal<NDims, LoopBoundTy>::template get<1>();
300+
LoopIndexTy<NDims> Index =
301+
InitializedVal<NDims, LoopIndexTy>::template get<0>();
302+
303+
NDLoopIterateImpl<NDims, NDims - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
304304
LowerBound, Stride, UpperBound, f, Index};
305305
}
306306

307307
/// Generates ND loop nest with \c LowerBound .. \c UpperBound bounds and
308308
/// stride \c Stride. Applies \c f at each iteration, passing current index of
309-
/// \c LoopIndexTy<NDIMS> type as the parameter.
309+
/// \c LoopIndexTy<NDims> type as the parameter.
310310
template <template <int> class LoopBoundTy, typename FuncTy,
311311
template <int> class LoopIndexTy = LoopBoundTy>
312-
static __SYCL_ALWAYS_INLINE void iterate(const LoopIndexTy<NDIMS> &LowerBound,
313-
const LoopBoundTy<NDIMS> &Stride,
314-
const LoopBoundTy<NDIMS> &UpperBound,
312+
static __SYCL_ALWAYS_INLINE void iterate(const LoopIndexTy<NDims> &LowerBound,
313+
const LoopBoundTy<NDims> &Stride,
314+
const LoopBoundTy<NDims> &UpperBound,
315315
FuncTy f) {
316-
LoopIndexTy<NDIMS> Index =
317-
InitializedVal<NDIMS, LoopIndexTy>::template get<0>();
318-
NDLoopIterateImpl<NDIMS, NDIMS - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
316+
LoopIndexTy<NDims> Index =
317+
InitializedVal<NDims, LoopIndexTy>::template get<0>();
318+
NDLoopIterateImpl<NDims, NDims - 1, LoopBoundTy, FuncTy, LoopIndexTy>{
319319
LowerBound, Stride, UpperBound, f, Index};
320320
}
321321
};

sycl/include/sycl/detail/type_list.hpp

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,59 @@ struct is_empty_type_list
3131

3232
template <> struct type_list<> {};
3333

34-
template <typename H, typename... T> struct type_list<H, T...> {
35-
using head = H;
36-
using tail = type_list<T...>;
34+
template <typename Head, typename... Tail> struct type_list<Head, Tail...> {
35+
using head = Head;
36+
using tail = type_list<Tail...>;
3737
};
3838

39-
template <typename H, typename... T, typename... T2>
40-
struct type_list<type_list<H, T...>, T2...> {
39+
template <typename Head, typename... Tail, typename... Tail2>
40+
struct type_list<type_list<Head, Tail...>, Tail2...> {
4141
private:
42-
using remainder = tail_t<type_list<H>>;
42+
using remainder = tail_t<type_list<Head>>;
4343
static constexpr bool has_remainder = !is_empty_type_list<remainder>::value;
44-
using without_remainder = type_list<T..., T2...>;
45-
using with_remainder = type_list<remainder, T..., T2...>;
44+
using without_remainder = type_list<Tail..., Tail2...>;
45+
using with_remainder = type_list<remainder, Tail..., Tail2...>;
4646

4747
public:
48-
using head = head_t<type_list<H>>;
48+
using head = head_t<type_list<Head>>;
4949
using tail = conditional_t<has_remainder, with_remainder, without_remainder>;
5050
};
5151

5252
// is_contained
53-
template <typename T, typename L>
53+
template <typename T, typename TypeList>
5454
struct is_contained
55-
: conditional_t<std::is_same<remove_cv_t<T>, head_t<L>>::value,
56-
std::true_type, is_contained<T, tail_t<L>>> {};
55+
: conditional_t<std::is_same<remove_cv_t<T>, head_t<TypeList>>::value,
56+
std::true_type, is_contained<T, tail_t<TypeList>>> {};
5757

5858
template <typename T>
5959
struct is_contained<T, empty_type_list> : std::false_type {};
6060

6161
// value_list
62-
template <typename T, T... V> struct value_list;
62+
template <typename T, T... Values> struct value_list;
6363

64-
template <typename T, T H, T... V> struct value_list<T, H, V...> {
65-
static constexpr T head = H;
66-
using tail = value_list<T, V...>;
64+
template <typename T, T Head, T... Tail> struct value_list<T, Head, Tail...> {
65+
static constexpr T head = Head;
66+
using tail = value_list<T, Tail...>;
6767
};
6868

6969
template <typename T> struct value_list<T> {};
7070

7171
// is_contained_value
72-
template <typename T, T V, typename TL>
72+
template <typename T, T Value, typename ValueList>
7373
struct is_contained_value
74-
: conditional_t<V == TL::head, std::true_type,
75-
is_contained_value<T, V, tail_t<TL>>> {};
74+
: conditional_t<Value == ValueList::head, std::true_type,
75+
is_contained_value<T, Value, tail_t<ValueList>>> {};
7676

77-
template <typename T, T V>
78-
struct is_contained_value<T, V, value_list<T>> : std::false_type {};
77+
template <typename T, T Value>
78+
struct is_contained_value<T, Value, value_list<T>> : std::false_type {};
7979

8080
// address_space_list
81-
template <access::address_space... V>
82-
using address_space_list = value_list<access::address_space, V...>;
81+
template <access::address_space... Values>
82+
using address_space_list = value_list<access::address_space, Values...>;
8383

84-
template <access::address_space AS, typename VL>
85-
using is_one_of_spaces = is_contained_value<access::address_space, AS, VL>;
84+
template <access::address_space AddressSpace, typename ValueList>
85+
using is_one_of_spaces =
86+
is_contained_value<access::address_space, AddressSpace, ValueList>;
8687

8788
// size type predicates
8889
template <typename T1, typename T2>
@@ -103,35 +104,39 @@ struct is_type_size_half_of : bool_constant<(sizeof(T1) == (sizeof(T2) / 2))> {
103104
};
104105

105106
// find required type
106-
template <typename TL, template <typename, typename> class C, typename T>
107+
template <typename TypeList, template <typename, typename> class Comp,
108+
typename T>
107109
struct find_type {
108-
using head = head_t<TL>;
109-
using tail = typename find_type<tail_t<TL>, C, T>::type;
110-
using type = conditional_t<C<head, T>::value, head, tail>;
110+
using head = head_t<TypeList>;
111+
using tail = typename find_type<tail_t<TypeList>, Comp, T>::type;
112+
using type = conditional_t<Comp<head, T>::value, head, tail>;
111113
};
112114

113-
template <template <typename, typename> class C, typename T>
114-
struct find_type<empty_type_list, C, T> {
115+
template <template <typename, typename> class Comp, typename T>
116+
struct find_type<empty_type_list, Comp, T> {
115117
using type = void;
116118
};
117119

118-
template <typename TL, template <typename, typename> class C, typename T>
119-
using find_type_t = typename find_type<TL, C, T>::type;
120+
template <typename TypeList, template <typename, typename> class Comp,
121+
typename T>
122+
using find_type_t = typename find_type<TypeList, Comp, T>::type;
120123

121-
template <typename TL, typename T>
122-
using find_same_size_type_t = find_type_t<TL, is_type_size_equal, T>;
124+
template <typename TypeList, typename T>
125+
using find_same_size_type_t = find_type_t<TypeList, is_type_size_equal, T>;
123126

124-
template <typename TL, typename T>
125-
using find_smaller_type_t = find_type_t<TL, is_type_size_less, T>;
127+
template <typename TypeList, typename T>
128+
using find_smaller_type_t = find_type_t<TypeList, is_type_size_less, T>;
126129

127-
template <typename TL, typename T>
128-
using find_larger_type_t = find_type_t<TL, is_type_size_greater, T>;
130+
template <typename TypeList, typename T>
131+
using find_larger_type_t = find_type_t<TypeList, is_type_size_greater, T>;
129132

130-
template <typename TL, typename T>
131-
using find_twice_as_small_type_t = find_type_t<TL, is_type_size_half_of, T>;
133+
template <typename TypeList, typename T>
134+
using find_twice_as_small_type_t =
135+
find_type_t<TypeList, is_type_size_half_of, T>;
132136

133-
template <typename TL, typename T>
134-
using find_twice_as_large_type_t = find_type_t<TL, is_type_size_double_of, T>;
137+
template <typename TypeList, typename T>
138+
using find_twice_as_large_type_t =
139+
find_type_t<TypeList, is_type_size_double_of, T>;
135140

136141
} // namespace detail
137142
} // namespace sycl

sycl/test/regression/check_simple_name_collisions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#define BUFFER
2121
#define IMAGE
2222
#define UNDEFINED
23+
#define VL
24+
#define DIM
25+
#define DIMS
26+
#define NDIMS
2327

2428
#include <sycl/sycl.hpp>
2529

0 commit comments

Comments
 (0)