Added support for cl_ext_float_atomics in CBasicTestFetchAdd with atomic_float (#2345)

Related to #2142, according to the work plan, extending
CBasicTestFetchAdd with support for atomic_float.
This commit is contained in:
Marcin Hajder
2025-09-02 17:38:56 +02:00
committed by GitHub
parent d417d7670d
commit fbba22770d
4 changed files with 253 additions and 42 deletions

View File

@@ -17,6 +17,7 @@
#define HOST_ATOMICS_H_
#include "harness/testHarness.h"
#include <mutex>
#ifdef WIN32
#include "Windows.h"
@@ -94,14 +95,25 @@ template <typename AtomicType, typename CorrespondingType>
CorrespondingType host_atomic_fetch_add(volatile AtomicType *a, CorrespondingType c,
TExplicitMemoryOrderType order)
{
if constexpr (std::is_same_v<AtomicType, HOST_ATOMIC_FLOAT>)
{
static std::mutex mx;
std::lock_guard<std::mutex> lock(mx);
CorrespondingType old_value = *a;
*a += c;
return old_value;
}
else
{
#if defined( _MSC_VER ) || (defined( __INTEL_COMPILER ) && defined(WIN32))
return InterlockedExchangeAdd(a, c);
return InterlockedExchangeAdd(a, c);
#elif defined(__GNUC__)
return __sync_fetch_and_add(a, c);
return __sync_fetch_and_add(a, c);
#else
log_info("Host function not implemented: atomic_fetch_add\n");
return 0;
log_info("Host function not implemented: atomic_fetch_add\n");
return 0;
#endif
}
}
template <typename AtomicType, typename CorrespondingType>