c11_atomics: unify host half representation and conversion with wrapper class (#2503)

Introduce `HostHalf` wrapper class to eliminate explicit
`cl_half_from_float`
and `cl_half_to_float` conversions throughout the test code. The wrapper
provides semantic value constructors/operators and automatic
conversions,
simplifying half-precision arithmetic operations.

Key improvements:
- `HostHalf` class with operator overloading for arithmetic and
comparisons
- Type traits `is_host_atomic_fp_v` and `is_host_fp_v` for generic FP
handling
- Unified floating-point atomic operations (add/sub/min/max/exchange)
- Removed 300+ lines of half-specific conditional branches
- Consistent calculation for all FP types
This commit is contained in:
Yilong Guo
2025-12-17 00:37:33 +08:00
committed by GitHub
parent 67fbbe4ee2
commit 119af24d54
4 changed files with 248 additions and 494 deletions

View File

@@ -194,9 +194,9 @@ template<> cl_int AtomicTypeExtendedInfo<cl_int>::MinValue() {return CL_INT_MIN;
template<> cl_uint AtomicTypeExtendedInfo<cl_uint>::MinValue() {return 0;}
template<> cl_long AtomicTypeExtendedInfo<cl_long>::MinValue() {return CL_LONG_MIN;}
template <> cl_ulong AtomicTypeExtendedInfo<cl_ulong>::MinValue() { return 0; }
template <> cl_half AtomicTypeExtendedInfo<cl_half>::MinValue()
template <> HostHalf AtomicTypeExtendedInfo<HostHalf>::MinValue()
{
return cl_half_from_float(-CL_HALF_MAX, gHalfRoundingMode);
return -CL_HALF_MAX;
}
template <> cl_float AtomicTypeExtendedInfo<cl_float>::MinValue()
{
@@ -217,9 +217,9 @@ template <> cl_uint AtomicTypeExtendedInfo<cl_uint>::MaxValue()
}
template<> cl_long AtomicTypeExtendedInfo<cl_long>::MaxValue() {return CL_LONG_MAX;}
template<> cl_ulong AtomicTypeExtendedInfo<cl_ulong>::MaxValue() {return CL_ULONG_MAX;}
template <> cl_half AtomicTypeExtendedInfo<cl_half>::MaxValue()
template <> HostHalf AtomicTypeExtendedInfo<HostHalf>::MaxValue()
{
return cl_half_from_float(CL_HALF_MAX, gHalfRoundingMode);
return CL_HALF_MAX;
}
template <> cl_float AtomicTypeExtendedInfo<cl_float>::MaxValue()
{