1818#include < iostream>
1919#include < limits>
2020
21+ #ifdef __SYCL_DEVICE_ONLY__
22+ // `constexpr` could work because the implicit conversion from `float` to
23+ // `_Float16` can be `constexpr`.
24+ #define __SYCL_CONSTEXPR_ON_DEVICE constexpr
25+ #else
26+ #define __SYCL_CONSTEXPR_ON_DEVICE
27+ #endif
28+
2129__SYCL_INLINE_NAMESPACE (cl) {
2230namespace sycl {
2331namespace detail {
@@ -130,7 +138,7 @@ class half {
130138 half (const half &) = default ;
131139 half (half &&) = default ;
132140
133- half (const float &rhs) : Data(rhs) {}
141+ __SYCL_CONSTEXPR_ON_DEVICE half (const float &rhs) : Data(rhs) {}
134142
135143 half &operator =(const half &rhs) = default ;
136144
@@ -216,15 +224,6 @@ using half = cl::sycl::detail::half_impl::half;
216224// Partial specialization of some functions in namespace `std`
217225namespace std {
218226
219- #ifdef __SYCL_DEVICE_ONLY__
220- // `constexpr` could work because the implicit conversion from `float` to
221- // `_Float16` can be `constexpr`.
222- #define CONSTEXPR_QUALIFIER constexpr
223- #else
224- // The qualifier is `const` instead of `constexpr` that is original to be
225- // because the constructor is not `constexpr` function.
226- #define CONSTEXPR_QUALIFIER const
227- #endif
228227
229228// Partial specialization of `std::hash<cl::sycl::half>`
230229template <> struct hash <half> {
@@ -307,35 +306,43 @@ template <> struct numeric_limits<half> {
307306
308307 static constexpr const float_round_style round_style = round_to_nearest;
309308
310- static CONSTEXPR_QUALIFIER half min () noexcept { return SYCL_HLF_MIN; }
309+ static __SYCL_CONSTEXPR_ON_DEVICE const half min () noexcept {
310+ return SYCL_HLF_MIN;
311+ }
311312
312- static CONSTEXPR_QUALIFIER half max () noexcept { return SYCL_HLF_MAX; }
313+ static __SYCL_CONSTEXPR_ON_DEVICE const half max () noexcept {
314+ return SYCL_HLF_MAX;
315+ }
313316
314- static CONSTEXPR_QUALIFIER half lowest () noexcept { return -SYCL_HLF_MAX; }
317+ static __SYCL_CONSTEXPR_ON_DEVICE const half lowest () noexcept {
318+ return -SYCL_HLF_MAX;
319+ }
315320
316- static CONSTEXPR_QUALIFIER half epsilon () noexcept {
321+ static __SYCL_CONSTEXPR_ON_DEVICE const half epsilon () noexcept {
317322 return SYCL_HLF_EPSILON;
318323 }
319324
320- static CONSTEXPR_QUALIFIER half round_error () noexcept { return 0 .5F ; }
325+ static __SYCL_CONSTEXPR_ON_DEVICE const half round_error () noexcept {
326+ return 0 .5F ;
327+ }
321328
322- static CONSTEXPR_QUALIFIER half infinity () noexcept {
329+ static __SYCL_CONSTEXPR_ON_DEVICE const half infinity () noexcept {
323330 return __builtin_huge_valf ();
324331 }
325332
326- static CONSTEXPR_QUALIFIER half quiet_NaN () noexcept {
333+ static __SYCL_CONSTEXPR_ON_DEVICE const half quiet_NaN () noexcept {
327334 return __builtin_nanf (" " );
328335 }
329336
330- static CONSTEXPR_QUALIFIER half signaling_NaN () noexcept {
337+ static __SYCL_CONSTEXPR_ON_DEVICE const half signaling_NaN () noexcept {
331338 return __builtin_nansf (" " );
332339 }
333340
334- static CONSTEXPR_QUALIFIER half denorm_min () noexcept { return 5 .96046e-08F ; }
341+ static __SYCL_CONSTEXPR_ON_DEVICE const half denorm_min () noexcept {
342+ return 5 .96046e-08F ;
343+ }
335344};
336345
337- #undef CONSTEXPR_QUALIFIER
338-
339346} // namespace std
340347
341348inline std::ostream &operator <<(std::ostream &O, half const &rhs) {
@@ -349,3 +356,5 @@ inline std::istream &operator>>(std::istream &I, half &rhs) {
349356 rhs = ValFloat;
350357 return I;
351358}
359+
360+ #undef __SYCL_CONSTEXPR_ON_DEVICE
0 commit comments