Fixes for basic explicit_s2v and commonfns degrees for cl_half (#2024)

Basic explicit_s2v:

The verification step was always using round to even when converting a
float to half even for round to zero cores.

Commonfns degrees:

The verification step was only taking into account infinities and not
values that over/underflow. This resulted in an incorrect error
calculation. E.g:

double cpu_result = 175668.85998711039;
cl_half gpu_result = 31743; // this is 65504 when converting to float,
we overflowed.
float error = (cpu_result - gpu_result) * some_factor;

The fix adds the check if( (cl_half) reference == test ) before
calculating the error.
This commit is contained in:
Ahmed
2024-08-13 17:52:07 +01:00
committed by GitHub
parent aa49f3bb53
commit b4c3bf2af2
5 changed files with 90 additions and 61 deletions

View File

@@ -151,28 +151,6 @@ struct MixTest : BaseFunctionTest
cl_int Run() override;
};
template <typename T> float UlpFn(const T &val, const double &r)
{
if (std::is_same<T, half>::value)
{
return Ulp_Error_Half(val, r);
}
else if (std::is_same<T, float>::value)
{
return Ulp_Error(val, r);
}
else if (std::is_same<T, double>::value)
{
return Ulp_Error_Double(val, r);
}
else
{
log_error("UlpFn: unsupported data type\n");
}
return -1.f; // wrong val
}
template <typename T> inline double conv_to_dbl(const T &val)
{
if (std::is_same<T, half>::value)
@@ -217,6 +195,33 @@ template <typename T> bool isfinite_fp(const T &v)
}
}
template <typename T> float UlpFn(const T &val, const double &r)
{
if (std::is_same<T, half>::value)
{
if (conv_to_half(r) == val)
{
return 0.0f;
}
return Ulp_Error_Half(val, r);
}
else if (std::is_same<T, float>::value)
{
return Ulp_Error(val, r);
}
else if (std::is_same<T, double>::value)
{
return Ulp_Error_Double(val, r);
}
else
{
log_error("UlpFn: unsupported data type\n");
}
return -1.f; // wrong val
}
template <class T>
int MakeAndRunTest(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements,