diff --git a/sycl/include/sycl/detail/vector_arith.hpp b/sycl/include/sycl/detail/vector_arith.hpp index 377605a391d67..e85e5e77cf97b 100644 --- a/sycl/include/sycl/detail/vector_arith.hpp +++ b/sycl/include/sycl/detail/vector_arith.hpp @@ -14,6 +14,8 @@ #include #include +#include + namespace sycl { inline namespace _V1 { namespace detail { diff --git a/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp b/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp index e7866303c11ed..7fa2fc820a5b3 100644 --- a/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp +++ b/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp @@ -115,19 +115,6 @@ struct is_esimd_arithmetic_type : std::true_type {}; template <> struct is_esimd_arithmetic_type : std::true_type {}; -// Misc -inline std::ostream &operator<<(std::ostream &O, sycl::half const &rhs) { - O << static_cast(rhs); - return O; -} - -inline std::istream &operator>>(std::istream &I, sycl::half &rhs) { - float ValFloat = 0.0f; - I >> ValFloat; - rhs = ValFloat; - return I; -} - } // namespace ext::intel::esimd::detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/ext/oneapi/bfloat16.hpp b/sycl/include/sycl/ext/oneapi/bfloat16.hpp index 5ba60801c8c77..bb47ac7667556 100644 --- a/sycl/include/sycl/ext/oneapi/bfloat16.hpp +++ b/sycl/include/sycl/ext/oneapi/bfloat16.hpp @@ -8,12 +8,12 @@ #pragma once -#include // for half -#include // for bit_cast -#include // for __DPCPP_SYCL_EXTERNAL -#include // for half +#include +#include +#include +#include -#include // for uint16_t, uint32_t +#include namespace sycl { inline namespace _V1 { @@ -126,6 +126,12 @@ class bfloat16 { // for floating-point types. // Stream Operator << and >> +#ifdef __SYCL_DEVICE_ONLY__ + // std::istream/std::ostream aren't usable on device, so don't provide a + // definition to save compile time by using lightweight ``. + inline friend std::ostream &operator<<(std::ostream &O, bfloat16 const &rhs); + inline friend std::istream &operator>>(std::istream &I, bfloat16 &rhs); +#else inline friend std::ostream &operator<<(std::ostream &O, bfloat16 const &rhs) { O << static_cast(rhs); return O; @@ -137,6 +143,7 @@ class bfloat16 { rhs = ValFloat; return I; } +#endif private: Bfloat16StorageT value; diff --git a/sycl/include/sycl/half_type.hpp b/sycl/include/sycl/half_type.hpp index 0e918df3aacb3..11e1fb388cb1b 100644 --- a/sycl/include/sycl/half_type.hpp +++ b/sycl/include/sycl/half_type.hpp @@ -10,18 +10,25 @@ #include // for bit_cast #include // for __SYCL_EXPORT -#include // for istream, ostream #ifdef __SYCL_DEVICE_ONLY__ #include #endif -#include // for size_t -#include // for uint16_t, uint32_t, uint8_t -#include // for hash +#include +#include #include // for float_denorm_style, float_r... -#include // for hash -#include // for enable_if_t +#include + +// For std::hash, seems to be the most lightweight header provide it under +// C++17: +#include + +#ifdef __SYCL_DEVICE_ONLY__ +#include +#else +#include +#endif #if !defined(__has_builtin) || !__has_builtin(__builtin_expect) #define __builtin_expect(a, b) (a) @@ -478,6 +485,13 @@ class [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] half { #endif // __SYCL_DEVICE_ONLY__ // Operator << and >> +#ifdef __SYCL_DEVICE_ONLY__ + // std::istream/std::ostream aren't usable on device, so don't provide a + // definition to save compile time by using lightweight ``. + inline friend std::ostream &operator<<(std::ostream &O, + sycl::half const &rhs); + inline friend std::istream &operator>>(std::istream &I, sycl::half &rhs); +#else inline friend std::ostream &operator<<(std::ostream &O, sycl::half const &rhs) { O << static_cast(rhs); @@ -490,6 +504,7 @@ class [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] half { rhs = ValFloat; return I; } +#endif template friend struct std::hash;