From 347b114579ed74f50afb3a3747db9955ba67f3c8 Mon Sep 17 00:00:00 2001 From: vladimirlaz Date: Mon, 1 Nov 2021 19:28:23 +0300 Subject: [PATCH] [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. --- sycl/include/CL/sycl/detail/generic_type_lists.hpp | 6 +++--- sycl/include/CL/sycl/detail/generic_type_traits.hpp | 2 +- sycl/include/CL/sycl/stream.hpp | 7 ++++--- sycl/include/CL/sycl/types.hpp | 12 ++++++------ .../oneapi/experimental/group_helpers_sorters.hpp | 2 +- sycl/include/sycl/ext/oneapi/group_sort.hpp | 2 +- sycl/test/regression/disabled_std_byte.cpp | 4 ++++ 7 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 sycl/test/regression/disabled_std_byte.cpp diff --git a/sycl/include/CL/sycl/detail/generic_type_lists.hpp b/sycl/include/CL/sycl/detail/generic_type_lists.hpp index a2d34d6fa61fa..a5866d0a391e5 100644 --- a/sycl/include/CL/sycl/detail/generic_type_lists.hpp +++ b/sycl/include/CL/sycl/detail/generic_type_lists.hpp @@ -287,7 +287,7 @@ using vector_long_integer_list = type_list; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) // std::byte using scalar_byte_list = type_list; @@ -321,7 +321,7 @@ using scalar_unsigned_integer_list = scalar_unsigned_char_list>, scalar_unsigned_short_list, scalar_unsigned_int_list, scalar_unsigned_long_list, scalar_unsigned_longlong_list -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) , scalar_byte_list #endif @@ -334,7 +334,7 @@ using vector_unsigned_integer_list = vector_unsigned_char_list>, vector_unsigned_short_list, vector_unsigned_int_list, vector_unsigned_long_list, vector_unsigned_longlong_list -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) , vector_byte_list #endif diff --git a/sycl/include/CL/sycl/detail/generic_type_traits.hpp b/sycl/include/CL/sycl/detail/generic_type_traits.hpp index cd78d9f106211..670fb49104a60 100644 --- a/sycl/include/CL/sycl/detail/generic_type_traits.hpp +++ b/sycl/include/CL/sycl/detail/generic_type_traits.hpp @@ -433,7 +433,7 @@ struct select_cl_mptr_or_vector_or_scalar; // which is not supported on device template struct TypeHelper { using RetType = T; }; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) template <> struct TypeHelper { using RetType = std::uint8_t; }; #endif diff --git a/sycl/include/CL/sycl/stream.hpp b/sycl/include/CL/sycl/stream.hpp index c63c30d0d1f72..52daa3e659fbe 100644 --- a/sycl/include/CL/sycl/stream.hpp +++ b/sycl/include/CL/sycl/stream.hpp @@ -326,11 +326,12 @@ EnableIfFP floatingPointToDecStr(T AbsVal, char *Digits, for (unsigned I = 0; I < FractionLength; ++I) Digits[Offset++] = digitToChar(FractionDigits[I]); + auto AbsExp = Exp < 0 ? -Exp : Exp; // Exponent part Digits[Offset++] = 'e'; Digits[Offset++] = Exp >= 0 ? '+' : '-'; - Digits[Offset++] = digitToChar(abs(Exp) / 10); - Digits[Offset++] = digitToChar(abs(Exp) % 10); + Digits[Offset++] = digitToChar(AbsExp / 10); + Digits[Offset++] = digitToChar(AbsExp % 10); } else { // normal mode if (Exp < 0) { Digits[Offset++] = '0'; @@ -958,7 +959,7 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS stream { const h_item &RHS); }; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) // Byte (has to be converted to a numeric value) template inline std::enable_if_t::value, const stream &> diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 4d7f0ebc19a03..5ec1c9325c79a 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -103,7 +103,7 @@ template struct vec_helper { static constexpr RetType get(T value) { return value; } }; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) template <> struct vec_helper { using RetType = std::uint8_t; static constexpr RetType get(std::byte value) { return (RetType)value; } @@ -2206,7 +2206,7 @@ using select_apply_cl_t = __SYCL_GET_CL_TYPE(int, num), __SYCL_GET_CL_TYPE(long, num)>; \ }; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #define __SYCL_DECLARE_BYTE_CONVERTER(num) \ template <> class BaseCLTypeConverter { \ public: \ @@ -2231,7 +2231,7 @@ using select_apply_cl_t = using DataType = bool; \ }; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #define __SYCL_DECLARE_SCALAR_BYTE_CONVERTER \ template <> class BaseCLTypeConverter { \ public: \ @@ -2330,7 +2330,7 @@ using select_apply_cl_t = __SYCL_DECLARE_SCALAR_BOOL_CONVERTER \ } // namespace detail -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #define __SYCL_DECLARE_BYTE_VECTOR_CONVERTER \ namespace detail { \ __SYCL_DECLARE_BYTE_CONVERTER(2) \ @@ -2344,7 +2344,7 @@ using select_apply_cl_t = __SYCL_DECLARE_VECTOR_CONVERTERS(char) __SYCL_DECLARE_SCHAR_VECTOR_CONVERTERS __SYCL_DECLARE_BOOL_VECTOR_CONVERTERS -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) __SYCL_DECLARE_BYTE_VECTOR_CONVERTER #endif __SYCL_DECLARE_UNSIGNED_INTEGRAL_VECTOR_CONVERTERS(uchar) @@ -2371,7 +2371,7 @@ __SYCL_DECLARE_FLOAT_VECTOR_CONVERTERS(double) #undef __SYCL_DECLARE_SCALAR_SCHAR_CONVERTER #undef __SYCL_DECLARE_BOOL_VECTOR_CONVERTERS #undef __SYCL_DECLARE_BOOL_CONVERTER -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #undef __SYCL_DECLARE_BYTE_VECTOR_CONVERTER #undef __SYCL_DECLARE_BYTE_CONVERTER #undef __SYCL_DECLARE_SCALAR_BYTE_CONVERTER diff --git a/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp b/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp index 932d0a29fb888..a47ee187855a5 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/group_helpers_sorters.hpp @@ -8,7 +8,7 @@ #pragma once -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #include __SYCL_INLINE_NAMESPACE(cl) { diff --git a/sycl/include/sycl/ext/oneapi/group_sort.hpp b/sycl/include/sycl/ext/oneapi/group_sort.hpp index 17a91755dcb99..775d988917aa0 100644 --- a/sycl/include/sycl/ext/oneapi/group_sort.hpp +++ b/sycl/include/sycl/ext/oneapi/group_sort.hpp @@ -8,7 +8,7 @@ #pragma once -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0) #include #include #include diff --git a/sycl/test/regression/disabled_std_byte.cpp b/sycl/test/regression/disabled_std_byte.cpp new file mode 100644 index 0000000000000..735c09e39e488 --- /dev/null +++ b/sycl/test/regression/disabled_std_byte.cpp @@ -0,0 +1,4 @@ +// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -D_HAS_STD_BYTE=0 %s -Xclang -verify-ignore-unexpected=note,warning +// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning +// expected-no-diagnostics +#include