Skip to content

Commit 347b114

Browse files
authored
[SYCL] Disable std::byte code by _HAS_STD_BYTE (#4834)
MS VS allows to disable std::byte type using __HAS_STD_BYTE=0 (https://devblogs.microsoft.com/cppblog/c17-features-and-stl-fixes-in-vs-2017-15-3/). This patch disables SYCL code which relies on this type in this case.
1 parent a0342b3 commit 347b114

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

sycl/include/CL/sycl/detail/generic_type_lists.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ using vector_long_integer_list = type_list<vector_signed_long_integer_list,
287287
using long_integer_list =
288288
type_list<scalar_long_integer_list, vector_long_integer_list>;
289289

290-
#if __cplusplus >= 201703L
290+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
291291
// std::byte
292292
using scalar_byte_list = type_list<std::byte>;
293293

@@ -321,7 +321,7 @@ using scalar_unsigned_integer_list =
321321
scalar_unsigned_char_list>,
322322
scalar_unsigned_short_list, scalar_unsigned_int_list,
323323
scalar_unsigned_long_list, scalar_unsigned_longlong_list
324-
#if __cplusplus >= 201703L
324+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
325325
,
326326
scalar_byte_list
327327
#endif
@@ -334,7 +334,7 @@ using vector_unsigned_integer_list =
334334
vector_unsigned_char_list>,
335335
vector_unsigned_short_list, vector_unsigned_int_list,
336336
vector_unsigned_long_list, vector_unsigned_longlong_list
337-
#if __cplusplus >= 201703L
337+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
338338
,
339339
vector_byte_list
340340
#endif

sycl/include/CL/sycl/detail/generic_type_traits.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ struct select_cl_mptr_or_vector_or_scalar;
433433
// which is not supported on device
434434
template <typename T> struct TypeHelper { using RetType = T; };
435435

436-
#if __cplusplus >= 201703L
436+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
437437
template <> struct TypeHelper<std::byte> { using RetType = std::uint8_t; };
438438
#endif
439439

sycl/include/CL/sycl/stream.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,12 @@ EnableIfFP<T, unsigned> floatingPointToDecStr(T AbsVal, char *Digits,
326326
for (unsigned I = 0; I < FractionLength; ++I)
327327
Digits[Offset++] = digitToChar(FractionDigits[I]);
328328

329+
auto AbsExp = Exp < 0 ? -Exp : Exp;
329330
// Exponent part
330331
Digits[Offset++] = 'e';
331332
Digits[Offset++] = Exp >= 0 ? '+' : '-';
332-
Digits[Offset++] = digitToChar(abs(Exp) / 10);
333-
Digits[Offset++] = digitToChar(abs(Exp) % 10);
333+
Digits[Offset++] = digitToChar(AbsExp / 10);
334+
Digits[Offset++] = digitToChar(AbsExp % 10);
334335
} else { // normal mode
335336
if (Exp < 0) {
336337
Digits[Offset++] = '0';
@@ -958,7 +959,7 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS stream {
958959
const h_item<Dimensions> &RHS);
959960
};
960961

961-
#if __cplusplus >= 201703L
962+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
962963
// Byte (has to be converted to a numeric value)
963964
template <typename T>
964965
inline std::enable_if_t<std::is_same<T, std::byte>::value, const stream &>

sycl/include/CL/sycl/types.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ template <typename T> struct vec_helper {
103103
static constexpr RetType get(T value) { return value; }
104104
};
105105

106-
#if __cplusplus >= 201703L
106+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
107107
template <> struct vec_helper<std::byte> {
108108
using RetType = std::uint8_t;
109109
static constexpr RetType get(std::byte value) { return (RetType)value; }
@@ -2206,7 +2206,7 @@ using select_apply_cl_t =
22062206
__SYCL_GET_CL_TYPE(int, num), __SYCL_GET_CL_TYPE(long, num)>; \
22072207
};
22082208

2209-
#if __cplusplus >= 201703L
2209+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
22102210
#define __SYCL_DECLARE_BYTE_CONVERTER(num) \
22112211
template <> class BaseCLTypeConverter<std::byte, num> { \
22122212
public: \
@@ -2231,7 +2231,7 @@ using select_apply_cl_t =
22312231
using DataType = bool; \
22322232
};
22332233

2234-
#if __cplusplus >= 201703L
2234+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
22352235
#define __SYCL_DECLARE_SCALAR_BYTE_CONVERTER \
22362236
template <> class BaseCLTypeConverter<std::byte, 1> { \
22372237
public: \
@@ -2330,7 +2330,7 @@ using select_apply_cl_t =
23302330
__SYCL_DECLARE_SCALAR_BOOL_CONVERTER \
23312331
} // namespace detail
23322332

2333-
#if __cplusplus >= 201703L
2333+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
23342334
#define __SYCL_DECLARE_BYTE_VECTOR_CONVERTER \
23352335
namespace detail { \
23362336
__SYCL_DECLARE_BYTE_CONVERTER(2) \
@@ -2344,7 +2344,7 @@ using select_apply_cl_t =
23442344
__SYCL_DECLARE_VECTOR_CONVERTERS(char)
23452345
__SYCL_DECLARE_SCHAR_VECTOR_CONVERTERS
23462346
__SYCL_DECLARE_BOOL_VECTOR_CONVERTERS
2347-
#if __cplusplus >= 201703L
2347+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
23482348
__SYCL_DECLARE_BYTE_VECTOR_CONVERTER
23492349
#endif
23502350
__SYCL_DECLARE_UNSIGNED_INTEGRAL_VECTOR_CONVERTERS(uchar)
@@ -2371,7 +2371,7 @@ __SYCL_DECLARE_FLOAT_VECTOR_CONVERTERS(double)
23712371
#undef __SYCL_DECLARE_SCALAR_SCHAR_CONVERTER
23722372
#undef __SYCL_DECLARE_BOOL_VECTOR_CONVERTERS
23732373
#undef __SYCL_DECLARE_BOOL_CONVERTER
2374-
#if __cplusplus >= 201703L
2374+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
23752375
#undef __SYCL_DECLARE_BYTE_VECTOR_CONVERTER
23762376
#undef __SYCL_DECLARE_BYTE_CONVERTER
23772377
#undef __SYCL_DECLARE_SCALAR_BYTE_CONVERTER

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#if __cplusplus >= 201703L
11+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
1212
#include <CL/sycl/detail/group_sort_impl.hpp>
1313

1414
__SYCL_INLINE_NAMESPACE(cl) {

sycl/include/sycl/ext/oneapi/group_sort.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#if __cplusplus >= 201703L
11+
#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
1212
#include <CL/sycl/detail/defines_elementary.hpp>
1313
#include <CL/sycl/detail/group_sort_impl.hpp>
1414
#include <CL/sycl/detail/type_traits.hpp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -D_HAS_STD_BYTE=0 %s -Xclang -verify-ignore-unexpected=note,warning
2+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
3+
// expected-no-diagnostics
4+
#include <CL/sycl.hpp>

0 commit comments

Comments
 (0)