Added support for cl_ext_float_atomics in c11_atomics exchange test along with atomic_half type (#2337)

Related to #2142, according to the work plan, extending
CBasicTestExchange with support for atomic_half.
This commit is contained in:
Marcin Hajder
2025-06-24 17:37:50 +02:00
committed by GitHub
parent 8701acfa90
commit 550b14cd25
2 changed files with 65 additions and 8 deletions

View File

@@ -883,7 +883,14 @@ CBasicTest<HostAtomicType, HostDataType>::ProgramHeader(cl_uint maxNumDestItems)
header += std::string("__global volatile ") + aTypeName + " destMemory["
+ ss.str() + "] = {\n";
ss.str("");
if (CBasicTest<HostAtomicType, HostDataType>::DataType()._type
!= TYPE_ATOMIC_HALF)
ss << _startValue;
else
ss << static_cast<HostDataType>(
cl_half_to_float(static_cast<cl_half>(_startValue)));
for (cl_uint i = 0; i < maxNumDestItems; i++)
{
if (aTypeName == "atomic_flag")

View File

@@ -545,12 +545,37 @@ public:
HostDataType>::MemoryOrderScopeStr;
using CBasicTestMemOrderScope<HostAtomicType, HostDataType>::Iterations;
using CBasicTestMemOrderScope<HostAtomicType, HostDataType>::IterationsStr;
using CBasicTestMemOrderScope<HostAtomicType, HostDataType>::LocalMemory;
CBasicTestExchange(TExplicitAtomicType dataType, bool useSVM)
: CBasicTestMemOrderScope<HostAtomicType, HostDataType>(dataType,
useSVM)
{
if constexpr (std::is_same_v<HostDataType, HOST_ATOMIC_HALF>)
StartValue(cl_half_from_float(static_cast<float>(1234),
gHalfRoundingMode));
else
StartValue(123456);
}
virtual int ExecuteSingleTest(cl_device_id deviceID, cl_context context,
cl_command_queue queue)
{
if constexpr (std::is_same_v<HostDataType, HOST_ATOMIC_HALF>)
{
if (LocalMemory()
&& (gHalfAtomicCaps & CL_DEVICE_LOCAL_FP_ATOMIC_LOAD_STORE_EXT)
== 0)
return 0; // skip test - not applicable
if (!LocalMemory()
&& (gHalfAtomicCaps & CL_DEVICE_GLOBAL_FP_ATOMIC_LOAD_STORE_EXT)
== 0)
return 0;
}
return CBasicTestMemOrderScope<
HostAtomicType, HostDataType>::ExecuteSingleTest(deviceID, context,
queue);
}
virtual std::string ProgramCore()
{
std::string memoryOrderScope = MemoryOrderScopeStr();
@@ -591,17 +616,35 @@ public:
/* Any repeated value is treated as an error */
std::vector<bool> tidFound(threadCount);
bool startValueFound = false;
cl_uint i;
cl_uint startVal = StartValue();
for (i = 0; i <= threadCount; i++)
if constexpr (std::is_same_v<HostDataType, HOST_ATOMIC_HALF>)
startVal = static_cast<cl_uint>(
cl_half_to_float(static_cast<cl_half>(StartValue())));
for (cl_uint i = 0; i <= threadCount; i++)
{
cl_uint value;
cl_uint value = 0;
if (i == threadCount)
value = (cl_uint)finalValues[0]; // additional value from atomic
{
if constexpr (!std::is_same_v<HostDataType, HOST_ATOMIC_HALF>)
value =
(cl_uint)finalValues[0]; // additional value from atomic
// variable (last written)
else
value =
cl_half_to_float(static_cast<cl_half>(finalValues[0]));
}
else
{
if constexpr (!std::is_same_v<HostDataType, HOST_ATOMIC_HALF>)
value = (cl_uint)refValues[i];
if (value == (cl_uint)StartValue())
else
value =
cl_half_to_float(static_cast<cl_half>(refValues[i]));
}
if (value == startVal)
{
// Special initial value
if (startValueFound)
@@ -666,6 +709,13 @@ static int test_atomic_exchange_generic(cl_device_id deviceID,
TYPE_ATOMIC_DOUBLE, useSVM);
EXECUTE_TEST(error,
test_double.Execute(deviceID, context, queue, num_elements));
if (gFloatAtomicsSupported)
{
CBasicTestExchange<HOST_ATOMIC_HALF, HOST_HALF> test_half(
TYPE_ATOMIC_HALF, useSVM);
EXECUTE_TEST(error,
test_half.Execute(deviceID, context, queue, num_elements));
}
if (AtomicTypeInfo(TYPE_ATOMIC_SIZE_T).Size(deviceID) == 4)
{
CBasicTestExchange<HOST_ATOMIC_INTPTR_T32, HOST_INTPTR_T32>