Skip to content

Commit 12ac4c3

Browse files
[SYCL] Fix C++14/C++20 compatibility issues (#6410)
* Show that stdcpp_compat.cpp test misses some warnings * Fix -std=C++XX incompatibilities * Clarify comment pointing that it's a workaround for clang ...and not something mandated by the C++20.
1 parent 6b8761a commit 12ac4c3

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

sycl/include/CL/sycl/id.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ template <int dimensions = 1> class id : public detail::array<dimensions> {
118118
// OP is: ==, !=
119119
#ifndef __SYCL_DISABLE_ID_TO_INT_CONV__
120120
using detail::array<dimensions>::operator==;
121+
// Needed for clang in C++20 mode as the above operator== would be ambigious
122+
// between regular/reversed call for "Id == Id" case.
123+
bool operator==(const id<dimensions> &rhs) const {
124+
return this->detail::array<dimensions>::operator==(rhs);
125+
}
121126
#if __cpp_impl_three_way_comparison < 201907
122127
using detail::array<dimensions>::operator!=;
123128
#endif

sycl/include/sycl/ext/oneapi/device_global/properties.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct implement_in_csr_key {
4545
property_value<implement_in_csr_key, sycl::detail::bool_constant<Enable>>;
4646
};
4747

48+
#if __cplusplus >= 201703L // inline variables
4849
inline constexpr device_image_scope_key::value_t device_image_scope;
4950

5051
template <host_access_enum Access>
@@ -68,6 +69,7 @@ template <bool Enable>
6869
inline constexpr implement_in_csr_key::value_t<Enable> implement_in_csr;
6970
inline constexpr implement_in_csr_key::value_t<true> implement_in_csr_on;
7071
inline constexpr implement_in_csr_key::value_t<false> implement_in_csr_off;
72+
#endif // __cplusplus >= 201703L
7173

7274
template <> struct is_property_key<device_image_scope_key> : std::true_type {};
7375
template <> struct is_property_key<host_access_key> : std::true_type {};

sycl/include/sycl/ext/oneapi/experimental/cuda/barrier.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#include <cstddef>
1515

1616
__SYCL_INLINE_NAMESPACE(cl) {
17-
namespace sycl::ext::oneapi::experimental::cuda {
17+
namespace sycl {
18+
namespace ext {
19+
namespace oneapi {
20+
namespace experimental {
21+
namespace cuda {
1822

1923
class barrier {
2024
int64_t state;
@@ -141,6 +145,9 @@ class barrier {
141145
static constexpr uint64_t max() { return (1 << 20) - 1; }
142146
#pragma pop_macro("max")
143147
};
144-
145-
} // namespace sycl::ext::oneapi::experimental::cuda
148+
} // namespace cuda
149+
} // namespace experimental
150+
} // namespace oneapi
151+
} // namespace ext
152+
} // namespace sycl
146153
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/oneapi/matrix/matrix-jit.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ __SYCL_INLINE_NAMESPACE(cl) {
1717
namespace sycl {
1818
namespace ext {
1919
namespace oneapi {
20-
namespace experimental::matrix {
20+
namespace experimental {
21+
namespace matrix {
2122

2223
enum class matrix_layout { row_major, col_major, packed_a, packed_b };
2324

@@ -171,6 +172,7 @@ joint_matrix_store(Group sg,
171172
#endif // __SYCL_DEVICE_ONLY__
172173
}
173174

175+
#if __cplusplus >= 201703L // if constexpr
174176
template <typename Group, typename T1, typename T2, typename T3, size_t M,
175177
size_t K, size_t N, matrix_layout LayoutA, matrix_layout LayoutB,
176178
matrix_layout LayoutC>
@@ -202,6 +204,7 @@ joint_matrix_mad(Group sg, joint_matrix<T1, M, K, LayoutA, Group> &mA,
202204
PI_ERROR_INVALID_DEVICE);
203205
#endif // __SYCL_DEVICE_ONLY__
204206
}
207+
#endif // __cplusplus >= 201703L
205208

206209
template <typename Group, typename T, size_t NumRows, size_t NumCols,
207210
matrix_layout Layout, typename T2>
@@ -624,7 +627,8 @@ class wi_data {
624627
}
625628
};
626629

627-
} // namespace experimental::matrix
630+
} // namespace matrix
631+
} // namespace experimental
628632
} // namespace oneapi
629633
} // namespace ext
630634
} // namespace sycl

sycl/include/sycl/ext/oneapi/matrix/static-query.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ __SYCL_INLINE_NAMESPACE(cl) {
2626
namespace sycl {
2727
namespace ext {
2828
namespace oneapi {
29-
namespace experimental::matrix {
29+
namespace experimental {
30+
namespace matrix {
3031

3132
enum class tpu {
3233
dpas,
@@ -416,7 +417,8 @@ struct tpu_params<
416417
scope_t scope = scope_t::sub_group;
417418
};
418419
#endif
419-
} // namespace experimental::matrix
420+
} // namespace matrix
421+
} // namespace experimental
420422
} // namespace oneapi
421423
} // namespace ext
422424
} // namespace sycl

sycl/include/sycl/ext/oneapi/properties/property_value.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct property_value
4848
using key_t = PropertyT;
4949
};
5050

51+
#if __cplusplus >= 201703L // pack fold expressions
5152
template <typename PropertyT, typename... A, typename... B>
5253
constexpr std::enable_if_t<detail::IsCompileTimeProperty<PropertyT>::value,
5354
bool>
@@ -63,6 +64,7 @@ operator!=(const property_value<PropertyT, A...> &,
6364
const property_value<PropertyT, B...> &) {
6465
return (!std::is_same<A, B>::value || ...);
6566
}
67+
#endif // __cplusplus >= 201703L
6668

6769
template <typename V, typename = void> struct is_property_value {
6870
static constexpr bool value =

sycl/include/sycl/ext/oneapi/reduction.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ template <class Reducer> class combiner {
226226
}
227227

228228
template <class _T, access::address_space Space, class BinaryOperation>
229-
static inline constexpr bool BasicCheck =
229+
static constexpr bool BasicCheck =
230230
std::is_same<typename remove_AS<_T>::type, T>::value &&
231231
(Space == access::address_space::global_space ||
232232
Space == access::address_space::local_space);
@@ -2089,6 +2089,7 @@ void reduCGFuncImplArrayHelper(nd_item<Dims> NDIt, LocalAccT LocalReds,
20892089
}
20902090
}
20912091

2092+
#if __cplusplus >= 201703L // pack fold expressions
20922093
template <bool Pow2WG, bool IsOneWG, typename... Reductions, int Dims,
20932094
typename... LocalAccT, typename... OutAccT, typename... ReducerT,
20942095
typename... Ts, typename... BOPsT, size_t... Is>
@@ -2169,6 +2170,7 @@ void reduCGFuncImpl(handler &CGH, KernelType KernelFunc,
21692170
BOPsTuple, InitToIdentityProps, ArrayIs);
21702171
});
21712172
}
2173+
#endif // __cplusplus >= 201703L
21722174

21732175
template <typename KernelName, typename KernelType, int Dims,
21742176
typename... Reductions, size_t... Is>
@@ -2391,6 +2393,9 @@ void reduAuxCGFuncImplArrayHelper(nd_item<Dims> NDIt, size_t LID, size_t GID,
23912393
}
23922394
}
23932395

2396+
// Pack fold expressions are used either in the function itself or down its
2397+
// callstack.
2398+
#if __cplusplus >= 201703L
23942399
template <bool UniformPow2WG, bool IsOneWG, typename... Reductions, int Dims,
23952400
typename... LocalAccT, typename... InAccT, typename... OutAccT,
23962401
typename... Ts, typename... BOPsT, size_t... Is>
@@ -2466,6 +2471,7 @@ void reduAuxCGFuncImpl(handler &CGH, size_t NWorkItems, size_t NWorkGroups,
24662471
OutAccsTuple, IdentitiesTuple, BOPsTuple, InitToIdentityProps, ArrayIs);
24672472
});
24682473
}
2474+
#endif // __cplusplus >= 201703L
24692475

24702476
template <typename KernelName, typename KernelType, typename... Reductions,
24712477
size_t... Is>

sycl/test/basic_tests/stdcpp_compat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=expected,cxx14 %s -c -o %t.out
22
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out -DSYCL_DISABLE_CPP_VERSION_CHECK_WARNING=1
3-
// RUN: %clangxx -std=c++14 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=cxx14,warning_extension,expected %s -c -o %t.out
4-
// RUN: %clangxx -std=c++17 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
5-
// RUN: %clangxx -std=c++20 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
6-
// RUN: %clangxx -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
3+
// RUN: %clangxx -std=c++14 -fsycl --no-system-header-prefix=CL/sycl --no-system-header-prefix=sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=cxx14,warning_extension,expected %s -c -o %t.out
4+
// RUN: %clangxx -std=c++17 -fsycl --no-system-header-prefix=CL/sycl --no-system-header-prefix=sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
5+
// RUN: %clangxx -std=c++20 -fsycl --no-system-header-prefix=CL/sycl --no-system-header-prefix=sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
6+
// RUN: %clangxx -fsycl --no-system-header-prefix=CL/sycl --no-system-header-prefix=sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out
77

88
// The test checks SYCL headers C++ compiance and that a warning is emitted
99
// when compiling in < C++17 mode.

0 commit comments

Comments
 (0)