Added support for cl_ext_float_atomics in CBasicTestFetchMin/Max with atomic_float (#2353)

Related to #2142, according to the work plan, extending
`CBasicTestFetchMin`/`CBasicTestFetchMax` with support for atomic_float.
This commit is contained in:
Marcin Hajder
2025-09-09 17:45:35 +02:00
committed by GitHub
parent a0bd81d574
commit df61cad39f
4 changed files with 348 additions and 64 deletions

View File

@@ -172,19 +172,34 @@ bool host_atomic_compare_exchange(volatile AtomicType *a, CorrespondingType *exp
TExplicitMemoryOrderType order_success,
TExplicitMemoryOrderType order_failure)
{
CorrespondingType tmp;
#if defined( _MSC_VER ) || (defined( __INTEL_COMPILER ) && defined(WIN32))
tmp = InterlockedCompareExchange(a, desired, *expected);
CorrespondingType tmp;
if constexpr (std::is_same_v<AtomicType, HOST_ATOMIC_FLOAT>)
{
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
tmp = *reinterpret_cast<volatile float *>(a);
if (tmp == *expected)
{
*reinterpret_cast<volatile float *>(a) = desired;
return true;
}
*expected = tmp;
}
else
{
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
tmp = InterlockedCompareExchange(a, desired, *expected);
#elif defined(__GNUC__)
tmp = __sync_val_compare_and_swap(a, *expected, desired);
tmp = __sync_val_compare_and_swap(a, *expected, desired);
#else
log_info("Host function not implemented: atomic_compare_exchange\n");
tmp = 0;
log_info("Host function not implemented: atomic_compare_exchange\n");
tmp = 0;
#endif
if(tmp == *expected)
return true;
*expected = tmp;
return false;
if (tmp == *expected) return true;
*expected = tmp;
}
return false;
}
template <typename AtomicType, typename CorrespondingType>