Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c11_atomics] Add float/double type to atomic_compare_exchange test #2048

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test_conformance/c11_atomics/test_atomics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,68 @@
#include <sstream>
#include <vector>

template <>
bool host_atomic_compare_exchange<float, float>(
volatile float *a, float *expected, float desired,
TExplicitMemoryOrderType order_success,
TExplicitMemoryOrderType order_failure)
{
union FloatInt {
float f;
uint32_t i;
};
FloatInt a2{ *a };
FloatInt expected2{ *expected };
FloatInt desired2{ desired };
FloatInt tmp;
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
tmp.i = InterlockedCompareExchange(&a2.i, desired2.i, expected2.i);
#elif defined(__GNUC__)
tmp.i = __sync_val_compare_and_swap(&a2.i, expected2.i, desired2.i);
#else
log_info("Host function not implemented: atomic_compare_exchange\n");
tmp.i = 0;
#endif
if (tmp.i == expected2.i)
{
*a = a2.f;
return true;
}
*expected = tmp.f;
return false;
}

template <>
bool host_atomic_compare_exchange<double, double>(
volatile double *a, double *expected, double desired,
TExplicitMemoryOrderType order_success,
TExplicitMemoryOrderType order_failure)
{
union DoubleInt64 {
double d;
uint64_t i;
};
DoubleInt64 a2{ *a };
DoubleInt64 expected2{ *expected };
DoubleInt64 desired2{ desired };
DoubleInt64 tmp;
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
tmp.i = InterlockedCompareExchange(&a2.i, desired2.i, expected2.i);
#elif defined(__GNUC__)
tmp.i = __sync_val_compare_and_swap(&a2.i, expected2.i, desired2.i);
#else
log_info("Host function not implemented: atomic_compare_exchange\n");
tmp.i = 0;
#endif
if (tmp.i == expected2.i)
{
*a = a2.d;
return true;
}
*expected = tmp.d;
return false;
}

template <typename HostAtomicType, typename HostDataType>
class CBasicTestStore
: public CBasicTestMemOrderScope<HostAtomicType, HostDataType> {
Expand Down Expand Up @@ -852,6 +914,14 @@ int test_atomic_compare_exchange_strong_generic(cl_device_id deviceID,
TYPE_ATOMIC_ULONG, useSVM);
EXECUTE_TEST(error,
test_ulong.Execute(deviceID, context, queue, num_elements));
CBasicTestCompareStrong<HOST_ATOMIC_FLOAT, HOST_FLOAT> test_float(
TYPE_ATOMIC_FLOAT, useSVM);
EXECUTE_TEST(error,
test_float.Execute(deviceID, context, queue, num_elements));
CBasicTestCompareStrong<HOST_ATOMIC_DOUBLE, HOST_DOUBLE> test_double(
TYPE_ATOMIC_DOUBLE, useSVM);
EXECUTE_TEST(error,
test_double.Execute(deviceID, context, queue, num_elements));
if (AtomicTypeInfo(TYPE_ATOMIC_SIZE_T).Size(deviceID) == 4)
{
CBasicTestCompareStrong<HOST_ATOMIC_INTPTR_T32, HOST_INTPTR_T32>
Expand Down Expand Up @@ -988,6 +1058,14 @@ int test_atomic_compare_exchange_weak_generic(cl_device_id deviceID,
TYPE_ATOMIC_ULONG, useSVM);
EXECUTE_TEST(error,
test_ulong.Execute(deviceID, context, queue, num_elements));
CBasicTestCompareWeak<HOST_ATOMIC_FLOAT, HOST_FLOAT> test_float(
TYPE_ATOMIC_FLOAT, useSVM);
EXECUTE_TEST(error,
test_float.Execute(deviceID, context, queue, num_elements));
CBasicTestCompareWeak<HOST_ATOMIC_DOUBLE, HOST_DOUBLE> test_double(
TYPE_ATOMIC_DOUBLE, useSVM);
EXECUTE_TEST(error,
test_double.Execute(deviceID, context, queue, num_elements));
if (AtomicTypeInfo(TYPE_ATOMIC_SIZE_T).Size(deviceID) == 4)
{
CBasicTestCompareWeak<HOST_ATOMIC_INTPTR_T32, HOST_INTPTR_T32>
Expand Down
Loading