18
18
#include < iostream>
19
19
#include < limits>
20
20
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
+
21
29
__SYCL_INLINE_NAMESPACE (cl) {
22
30
namespace sycl {
23
31
namespace detail {
@@ -130,7 +138,7 @@ class half {
130
138
half (const half &) = default ;
131
139
half (half &&) = default ;
132
140
133
- half (const float &rhs) : Data(rhs) {}
141
+ __SYCL_CONSTEXPR_ON_DEVICE half (const float &rhs) : Data(rhs) {}
134
142
135
143
half &operator =(const half &rhs) = default ;
136
144
@@ -216,15 +224,6 @@ using half = cl::sycl::detail::half_impl::half;
216
224
// Partial specialization of some functions in namespace `std`
217
225
namespace std {
218
226
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
228
227
229
228
// Partial specialization of `std::hash<cl::sycl::half>`
230
229
template <> struct hash <half> {
@@ -307,35 +306,43 @@ template <> struct numeric_limits<half> {
307
306
308
307
static constexpr const float_round_style round_style = round_to_nearest;
309
308
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
+ }
311
312
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
+ }
313
316
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
+ }
315
320
316
- static CONSTEXPR_QUALIFIER half epsilon () noexcept {
321
+ static __SYCL_CONSTEXPR_ON_DEVICE const half epsilon () noexcept {
317
322
return SYCL_HLF_EPSILON;
318
323
}
319
324
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
+ }
321
328
322
- static CONSTEXPR_QUALIFIER half infinity () noexcept {
329
+ static __SYCL_CONSTEXPR_ON_DEVICE const half infinity () noexcept {
323
330
return __builtin_huge_valf ();
324
331
}
325
332
326
- static CONSTEXPR_QUALIFIER half quiet_NaN () noexcept {
333
+ static __SYCL_CONSTEXPR_ON_DEVICE const half quiet_NaN () noexcept {
327
334
return __builtin_nanf (" " );
328
335
}
329
336
330
- static CONSTEXPR_QUALIFIER half signaling_NaN () noexcept {
337
+ static __SYCL_CONSTEXPR_ON_DEVICE const half signaling_NaN () noexcept {
331
338
return __builtin_nansf (" " );
332
339
}
333
340
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
+ }
335
344
};
336
345
337
- #undef CONSTEXPR_QUALIFIER
338
-
339
346
} // namespace std
340
347
341
348
inline std::ostream &operator <<(std::ostream &O, half const &rhs) {
@@ -349,3 +356,5 @@ inline std::istream &operator>>(std::istream &I, half &rhs) {
349
356
rhs = ValFloat;
350
357
return I;
351
358
}
359
+
360
+ #undef __SYCL_CONSTEXPR_ON_DEVICE
0 commit comments